qemu/slirp
Jim Meyering 6265eb26a3 don't dereference NULL after failed strdup
Most of these are obvious NULL-deref bug fixes, for example,
the ones in these files:

  block/curl.c
  net.c
  slirp/misc.c

and the first one in block/vvfat.c.
The others in block/vvfat.c may not lead to an immediate segfault, but I
traced the two schedule_rename(..., strdup(path)) uses, and a failed
strdup would appear to trigger this assertion in handle_renames_and_mkdirs:

	    assert(commit->path);

The conversion to use qemu_strdup in envlist_to_environ is not technically
needed, but does avoid a theoretical leak in the caller when strdup fails
for one value, but later succeeds in allocating another buffer(plausible,
if one string length is much larger than the others).  The caller does
not know the length of the returned list, and as such can only free
pointers until it hits the first NULL.  If there are non-NULL pointers
beyond the first, their buffers would be leaked.  This one is admittedly
far-fetched.

The two in linux-user/main.c are worth fixing to ensure that an
OOM error is diagnosed up front, rather than letting it provoke some
harder-to-diagnose secondary error, in case of exec failure, or worse, in
case the exec succeeds but with an invalid list of command line options.
However, considering how unlikely it is to encounter a failed strdup early
in main, this isn't a big deal.  Note that adding the required uses of
qemu_strdup here and in envlist.c induce link failures because qemu_strdup
is not currently in any library they're linked with.  So for now, I've
omitted those changes, as well as the fixes in target-i386/helper.c
and target-sparc/helper.c.

If you'd like to see the above discussion (or anything else)
in the commit log, just let me know and I'll be happy to adjust.

>From 9af42864fd1ea666bd25e2cecfdfae74c20aa8c7 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering@redhat.com>
Date: Mon, 8 Feb 2010 18:29:29 +0100
Subject: [PATCH] don't dereference NULL after failed strdup

Handle failing strdup by replacing each use with qemu_strdup,
so as not to dereference NULL or trigger a failing assertion.
* block/curl.c (curl_open): s/\bstrdup\b/qemu_strdup/
* block/vvfat.c (init_directories): Likewise.
(get_cluster_count_for_direntry, check_directory_consistency): Likewise.
* net.c (parse_host_src_port): Likewise.
* slirp/misc.c (fork_exec): Likewise.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-02-10 14:00:53 -06:00
..
COPYRIGHT Remove the advertising clause from the slirp license 2009-01-26 19:37:41 +00:00
bootp.c Do not use dprintf 2010-02-07 02:03:50 +03:00
bootp.h slirp: Factor out internal state structure 2009-06-29 08:52:49 -05:00
cksum.c Remove the advertising clause from the slirp license 2009-01-26 19:37:41 +00:00
debug.h slirp: Cleanup and basic reanimation of debug code 2009-06-29 08:52:46 -05:00
if.c slirp: Use internal state in interface 2009-06-29 08:52:49 -05:00
if.h slirp: Factor out internal state structure 2009-06-29 08:52:49 -05:00
ip.h fix networking on win32 host 2009-12-18 23:23:56 +01:00
ip_icmp.c slirp: Read host DNS config on demand 2009-08-27 20:46:58 -05:00
ip_icmp.h Fix breakage by obsolete _P() for good 2009-07-01 19:11:17 +00:00
ip_input.c slirp: fix unmatched bracket in if 0 2009-09-30 18:56:44 +00:00
ip_output.c slirp: Factor out internal state structure 2009-06-29 08:52:49 -05:00
libslirp.h slirp: Read host DNS config on demand 2009-08-27 20:46:58 -05:00
main.h slirp: Read host DNS config on demand 2009-08-27 20:46:58 -05:00
mbuf.c slirp: fix use-after-free 2009-11-21 00:34:04 +01:00
mbuf.h Fix breakage by obsolete _P() for good 2009-07-01 19:11:17 +00:00
misc.c don't dereference NULL after failed strdup 2010-02-10 14:00:53 -06:00
misc.h slirp: Remove UDP protocol emulation (talk, cuseeme) 2009-07-27 14:09:15 -05:00
sbuf.c slirp: Drop dead code 2009-06-29 08:52:46 -05:00
sbuf.h Fix breakage by obsolete _P() for good 2009-07-01 19:11:17 +00:00
slirp.c Fix sys-queue.h conflict for good 2009-09-12 07:36:22 +00:00
slirp.h Don't leak file descriptors 2009-12-03 11:45:50 -06:00
slirp_config.h rename WORDS_BIGENDIAN to HOST_WORDS_BIGENDIAN 2009-07-27 14:09:21 -05:00
socket.c Don't leak file descriptors 2009-12-03 11:45:50 -06:00
socket.h Fix breakage by obsolete _P() for good 2009-07-01 19:11:17 +00:00
tcp.h rename WORDS_BIGENDIAN to HOST_WORDS_BIGENDIAN 2009-07-27 14:09:21 -05:00
tcp_input.c slirp: Factor out internal state structure 2009-06-29 08:52:49 -05:00
tcp_output.c slirp: Factor out internal state structure 2009-06-29 08:52:49 -05:00
tcp_subr.c Don't leak file descriptors 2009-12-03 11:45:50 -06:00
tcp_timer.c More NULL pointer fixes 2009-08-01 10:13:20 +00:00
tcp_timer.h Fix breakage by obsolete _P() for good 2009-07-01 19:11:17 +00:00
tcp_var.h slirp: Factor out internal state structure 2009-06-29 08:52:49 -05:00
tcpip.h Remove the advertising clause from the slirp license 2009-01-26 19:37:41 +00:00
tftp.c Qemu's internal TFTP server breaks lock-step-iness of TFTP 2010-01-13 17:14:16 -06:00
tftp.h slirp: Factor out internal state structure 2009-06-29 08:52:49 -05:00
udp.c Don't leak file descriptors 2009-12-03 11:45:50 -06:00
udp.h Fix breakage by obsolete _P() for good 2009-07-01 19:11:17 +00:00