Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NvVD6-0002uc-9J for qemu-devel@nongnu.org; Sat, 27 Mar 2010 08:33:52 -0400 Received: from [140.186.70.92] (port=48115 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NvVD4-0002tG-Pm for qemu-devel@nongnu.org; Sat, 27 Mar 2010 08:33:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NvVD3-0001Y4-E9 for qemu-devel@nongnu.org; Sat, 27 Mar 2010 08:33:50 -0400 Received: from hall.aurel32.net ([88.191.82.174]:49014) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NvVD3-0001Xx-73 for qemu-devel@nongnu.org; Sat, 27 Mar 2010 08:33:49 -0400 Date: Sat, 27 Mar 2010 13:33:46 +0100 From: Aurelien Jarno Subject: Re: [Qemu-devel] [PATCH] qemu-kvm: avoid strlen of NULL pointer Message-ID: <20100327123346.GA18866@volta.aurel32.net> References: <201003031532.43257.jens@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <201003031532.43257.jens@linux.vnet.ibm.com> List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jens Osterkamp Cc: qemu-devel@nongnu.org On Wed, Mar 03, 2010 at 03:32:43PM +0100, Jens Osterkamp wrote: > If the user wants to create a chardev of type socket but forgets to give a > host= option, qemu_opt_get returns NULL. This NULL pointer is then fed into > strlen a few lines below without a check which results in a segfault. > This fixes it. While this correctly fixes the segfault, it doesn't output any error message. The best would probably be to fold that with the test of "port", as the error message already mentions "host and/or port". > Signed-off-by: Jens Osterkamp > --- > qemu-sockets.c | 3 +++ > 1 files changed, 3 insertions(+), 0 deletions(-) > > diff --git a/qemu-sockets.c b/qemu-sockets.c > index 23c3def..a191304 100644 > --- a/qemu-sockets.c > +++ b/qemu-sockets.c > @@ -137,6 +137,9 @@ int inet_listen_opts(QemuOpts *opts, int port_offset) > pstrcpy(port, sizeof(port), qemu_opt_get(opts, "port")); > addr = qemu_opt_get(opts, "host"); > > + if (!addr) > + return -1; > + > to = qemu_opt_get_number(opts, "to", 0); > if (qemu_opt_get_bool(opts, "ipv4", 0)) > ai.ai_family = PF_INET; > -- > 1.5.6.3 > > > -- > Best regards, > > Jens Osterkamp > -------------------------------------------------------------------------------- > IBM Deutschland Research & Development GmbH > Vorsitzender des Aufsichtsrats: Martin Jetter > Geschäftsführung: Dirk Wittkopp > Sitz der Gesellschaft: Böblingen > Registergericht: Amtsgericht Stuttgart, HRB 243294 > > > > -- Aurelien Jarno GPG: 1024D/F1BCDB73 aurelien@aurel32.net http://www.aurel32.net