Author: blueswirl Date: Sun Apr 25 14:53:39 2010 New Revision: 752 URL: http://tracker.coreboot.org/trac/openbios/changeset/752
Log: Fix NULL pointer dereferences, spotted by clang analyzer
Fix clang warnings: ../packages/disk-label.c:83:6: warning: Dereference of null pointer if( *s == '-' || isdigit(*s) || ../libopenbios/elf_load.c:267:5: warning: Null pointer passed as an argument to a 'nonnull' parameter memcpy(addr, name, nhdr.n_namesz);
Signed-off-by: Blue Swirl blauwirbel@gmail.com
Modified: trunk/openbios-devel/libopenbios/elf_load.c trunk/openbios-devel/packages/disk-label.c
Modified: trunk/openbios-devel/libopenbios/elf_load.c ============================================================================== --- trunk/openbios-devel/libopenbios/elf_load.c Sun Apr 25 14:53:37 2010 (r751) +++ trunk/openbios-devel/libopenbios/elf_load.c Sun Apr 25 14:53:39 2010 (r752) @@ -264,11 +264,13 @@ memcpy(addr, &nhdr, sizeof(nhdr)); addr += sizeof(nhdr);
- memcpy(addr, name, nhdr.n_namesz); - addr += nhdr.n_namesz; - pad = padded(nhdr.n_namesz) - nhdr.n_namesz; - memset(addr, 0, pad); - addr += pad; + if (name && nhdr.n_namesz) { + memcpy(addr, name, nhdr.n_namesz); + addr += nhdr.n_namesz; + pad = padded(nhdr.n_namesz) - nhdr.n_namesz; + memset(addr, 0, pad); + addr += pad; + }
memcpy(addr, desc, nhdr.n_descsz); addr += nhdr.n_descsz;
Modified: trunk/openbios-devel/packages/disk-label.c ============================================================================== --- trunk/openbios-devel/packages/disk-label.c Sun Apr 25 14:53:37 2010 (r751) +++ trunk/openbios-devel/packages/disk-label.c Sun Apr 25 14:53:39 2010 (r752) @@ -68,6 +68,9 @@ if (!path) { path = strdup(""); } + if (!path) { + goto out; + } DPRINTF("dlabel-open '%s'\n", path );
/* open disk interface */