[haiku-bugs] [Haiku] #15250: jam crashes when given empty input file

  • From: "Haiku" <trac@xxxxxxxxxxxx>
  • To: undisclosed-recipients: ;
  • Date: Tue, 13 Aug 2019 19:55:56 -0000

#15250: jam crashes when given empty input file
--------------------------+------------------------------
 Reporter:  simonsouth    |        Owner:  bonefish
     Type:  bug           |       Status:  new
 Priority:  normal        |    Milestone:  Unscheduled
Component:  Build System  |      Version:  R1/Development
 Keywords:                |   Blocked By:
 Blocking:                |  Has a Patch:  0
 Platform:  All           |
--------------------------+------------------------------
 jam will crash with a segmentation fault if given an empty input file to
 parse. This can happen if a user deletes every line from his
 UserBuildConfig, for instance, without deleting the file itself.

 To demonstrate on Haiku, from within a "generated" subfolder beneath the
 Haiku source tree:

 {{{
 mv ../build/jam/UserBuildConfig{,.orig}
 touch ../build/jam/UserBuildConfig
 jam -q  # This will segfault
 mv ../build/jam/UserBuildConfig{.orig,}
 }}}

 This happens because as part of its file-caching mechanism, jam will
 allocate ''but not initialize'' an array of string pointers to hold lines
 read from the file. If no lines are read (because the file is empty) the
 first element of the array is never replaced with a valid pointer, causing
 a segfault later when the program tries to parse the file's contents.

 Changing jam so it initializes the first element of the array to zero
 solves the problem.

 I'll upload a patch for review.

-- 
Ticket URL: <https://dev.haiku-os.org/ticket/15250>
Haiku <https://dev.haiku-os.org>
The Haiku operating system.

Other related posts: