Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#15250 closed bug (fixed)

jam crashes when given empty input file

Reported by: simonsouth Owned by: bonefish
Priority: normal Milestone: R1/beta2
Component: Build System Version: R1/Development
Keywords: Cc:
Blocked By: Blocking:
Platform: All

Description

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.

Change History (3)

comment:1 by simonsouth, 5 years ago

I've uploaded the patch here for review: https://review.haiku-os.org/c/buildtools/+/1716

comment:2 by waddlesplash, 5 years ago

Resolution: fixed
Status: newclosed

Merged in btrev43152.

comment:3 by nielx, 5 years ago

Milestone: UnscheduledR1/beta2

Assign tickets with status=closed and resolution=fixed within the R1/beta2 development window to the R1/beta2 Milestone

Note: See TracTickets for help on using tickets.