Wireshark-bugs: [Wireshark-bugs] [Bug 7770] New: Failure to check for return values after calls
Date: Sat, 29 Sep 2012 12:06:51 -0700 (PDT)
https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=7770

           Summary: Failure to check for return values after calls to
                    calloc() in tools/lemon/lemon.c
           Product: Wireshark
           Version: 1.8.2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Normal
          Priority: Low
         Component: Extras
        AssignedTo: bugzilla-admin@xxxxxxxxxxxxx
        ReportedBy: wp02855@xxxxxxxxx


Created attachment 9249
  --> https://bugs.wireshark.org/bugzilla/attachment.cgi?id=9249
patch file (diff -u) for /wireshark-1.8.2/tools/lemon/lemon.c

Build Information:
Operating system is OpenSuSE 12.1 (64-bit).

GCC version is:

melmac:/usr/local/src/wireshark-1.8.2/tools/lemon # gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i586-suse-linux/4.6/lto-wrapper
Target: i586-suse-linux
Configured with: ../configure --prefix=/usr --infodir=/usr/share/info
--mandir=/usr/share/man --libdir=/usr/lib --libexecdir=/usr/lib
--enable-languages=c,c++,objc,fortran,obj-c++,java,ada
--enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.6
--enable-ssp --disable-libssp --disable-plugin
--with-bugurl=http://bugs.opensuse.org/ --with-pkgversion='SUSE Linux'
--disable-libgcj --disable-libmudflap --with-slibdir=/lib --with-system-zlib
--enable-__cxa_atexit --enable-libstdcxx-allocator=new --disable-libstdcxx-pch
--enable-version-specific-runtime-libs --program-suffix=-4.6
--enable-linux-futex --without-system-libunwind --with-arch-32=i586
--with-tune=generic --build=i586-suse-linux
Thread model: posix
gcc version 4.6.2 (SUSE Linux)
--
In reviewing file lemon.c, I noticed several calls to calloc() which did not
properly check the return value to see if the memory requested was actually
successfully allocated.  In addition, from the man page of calloc() <3>:

RETURN VALUE
The malloc() and calloc() functions return a pointer to the allocated memory
that is suitably aligned for any kind of variable. On error, these functions
return NULL. NULL may also be returned by a successful call to malloc() with a
size of zero, or by a successful call to calloc()with nmemb or size equal to
zero.

Several of the checks also test the return value against 0, but this is not
quite correct (compiler/OS compatibility), so I changed the return value to
NULL in those cases, which is what the actual check should be made against.

I'm attaching a file, lemon.c.patch which is a 'diff -u'

-- 
Configure bugmail: https://bugs.wireshark.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are watching all bug changes.