Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 134783 - Parted segfaults: Evil coding habits - application code in asserts
Summary: Parted segfaults: Evil coding habits - application code in asserts
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: x86 Linux
: Normal normal (vote)
Assignee: John N. Laliberte (RETIRED)
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-05-29 06:44 UTC by Maarten Billemont
Modified: 2006-06-14 00:30 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
Take application code out of asserts! (parted.patch,424 bytes, patch)
2006-05-29 06:45 UTC, Maarten Billemont
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Maarten Billemont 2006-05-29 06:44:37 UTC
parted-1.7.0/libparted/fs/hfs/probe.c has application code in an assert statement. This causes the code not to be executed when asserts are disabled. Segmentation faults are the result of this, since a nullpointer occurs. The simple given patch resolves this issue.
Comment 1 Maarten Billemont 2006-05-29 06:45:24 UTC
Created attachment 87798 [details, diff]
Take application code out of asserts!
Comment 2 Maarten Billemont 2006-05-29 06:48:03 UTC
I'm thinking the asserts may need to be converted to simple if()'s to assure safe operation. Not sure about that one, though.
Comment 3 Benno Schulenberg 2006-05-31 15:33:09 UTC
Applying the attached patch fixes the segfault that occurs here when doing a simple print statement.  Thanks.  But please change the subject line of this bug to something more dramatic: 'parted-1.7.1 segfaults upon print', for example.  Shouldn't the bug be filed upstream?

# gdb parted
Using host libthread_db library "/lib/libthread_db.so.1".
(gdb) run
Starting program: /usr/sbin/parted
GNU Parted 1.7.1
Using /dev/hda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print

Program received signal SIGSEGV, Segmentation fault.
hfsc_can_use_geom (geom=0x8070f44) at probe.c:48
48      probe.c: No such file or directory.
        in probe.c
(gdb) back
#0  hfsc_can_use_geom (geom=0x8070f44) at probe.c:48
#1  0xb7f12a13 in hfsplus_probe (geom=0x8070f44) at probe.c:110
#2  0xb7ee4543 in ped_file_system_probe_specific (fs_type=0xb7f3645c, geom=0x8070f44)
    at filesys.c:132
#3  0xb7ee4618 in ped_file_system_probe (geom=0x8070f44) at filesys.c:262
#4  0xb7f1b6fd in read_table (disk=0x8070ed8, sector=0, is_extended_table=0) at dos.c:861
#5  0xb7f1b8d8 in msdos_read (disk=0x8070ed8) at dos.c:912
#6  0xb7ee9c3e in ped_disk_new (dev=0x80712c0) at disk.c:190
#7  0x0804d4b5 in do_print (dev=0xbfd5e10c) at parted.c:1203
#8  0x0804afba in command_run (cmd=0x0, dev=0xebe187db) at command.c:138
#9  0x08053d3b in interactive_mode (dev=0xbfd5e10c, cmd_list=0x8070ef8) at ui.c:1276
#10 0x0804f6aa in main (argc=0, argv=0xbfd5e1c8) at parted.c:2254
(gdb)
Comment 4 Benno Schulenberg 2006-06-13 13:53:51 UTC
Patch was included in parted-1.7.1-r1.  Bug can be closed.

Although... some other candidates seem to remain in libparted/fs/hfs/hfs.c:

PED_ASSERT ((hgee = hfs_get_empty_end(fs)) != 0, return 0);
PED_ASSERT ((hgee = hfs_get_empty_end(fs)) != 0, return 0);
PED_ASSERT ((hgms = hfsplus_get_min_size (fs)) != 0, return 0);
Comment 5 Maarten Billemont 2006-06-14 00:30:16 UTC
Those are inside '#ifdef DEBUG' statements, and followed by an '#else' which does things the way they should be done. I recon they should not cause problems.

I am however wary of the second
PED_ASSERT ((hgee = hfs_get_empty_end(fs)) != 0, return 0);
statement, closely following the first. It seems to serve no purpose. I recon it can be removed.

Also, if you look at all the ASSERT's done in the code, something tells me it's bound to blow up. The ASSERTS are used to do parameter validation, which is a big no-no.

ref.
http://java.sun.com/j2se/1.4.2/docs/guide/lang/assert.html#usage