After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 633083 - SEGFAULT if File is Empty
SEGFAULT if File is Empty
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Genie
unspecified
Other All
: Normal normal
: ---
Assigned To: Jamie McCracken
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2010-10-25 08:48 UTC by Sam H
Modified: 2016-10-12 11:07 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch to fix the bug (1.39 KB, patch)
2010-10-25 09:39 UTC, Sam H
rejected Details | Review
Return TokenType.EOF from read_token () if file is empty (1.06 KB, patch)
2016-10-11 17:46 UTC, Al Thomas
committed Details | Review

Description Sam H 2010-10-25 08:48:50 UTC
A check if whether current is null needs to be added to "bool comment (bool file_comment = false)" in vala/valageniescanner.vala and a check needs to be added to member "public TokenType read_token (out SourceLocation token_begin, out SourceLocation token_end)" of class "Vala.Genie.Scanner". I will try create a patch later once I work out how to use git. I was able to reproduce this with 0.10.x and the current development snapshot from git.
Comment 1 Sam H 2010-10-25 09:39:05 UTC
Created attachment 173158 [details] [review]
Patch to fix the bug

This fixes the bug. If someone more experienced than me can create a better patch then please do.
Comment 2 Al Thomas 2016-10-11 17:42:06 UTC
Review of attachment 173158 [details] [review]:

A simpler solution is possible by checking the mapped file contents are null
Comment 3 Al Thomas 2016-10-11 17:46:55 UTC
Created attachment 337451 [details] [review]
Return TokenType.EOF from read_token () if file is empty

Vala.SourceFile uses GLib.MappedFile.get_contents () to read the contents of a source file. If that file is empty (zero bytes) then get_contents () returns null. See https://developer.gnome.org/glib/stable/glib-File-Utilities.html#g-mapped-file-get-contents

This patch adds a check that the pointer to the current position is null and if it is then return an end of file token. The token_begin and token_end are only needed to stop compiler warnings.
Comment 4 Jamie McCracken 2016-10-12 00:02:26 UTC
Patch looks good. Please apply with help from someone with commit rights on IRC

thanks

Jamie
Comment 5 Rico Tzschichholz 2016-10-12 11:07:25 UTC
commit a4ab6177c9a659b4b76f4fd22aedbb4b22920c55
Author: Alistair Thomas <astavale@yahoo.co.uk>
Date:   Tue Oct 11 18:28:35 2016 +0100

    genie: Add empty file check to read_token ()
    
    Vala.SourceFile uses GLib.MappedFile.get_contents () to read a source
    file. This can return null if the file is empty.