qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Thayne Harbaugh <thayne@c2.net>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [BUG][PATCH] execve processesing NULL args
Date: Tue, 11 Dec 2007 09:34:03 -0700	[thread overview]
Message-ID: <1197390843.2947.41.camel@phantasm.home.enterpriseandprosperity.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 98 bytes --]

Here's a patch to avoid processing NULL args in execve.  It prevents
trying to dereference NULL.


[-- Attachment #2: 50_execve_null_args.patch --]
[-- Type: text/x-patch, Size: 2178 bytes --]

Index: qemu/linux-user/syscall.c
===================================================================
--- qemu.orig/linux-user/syscall.c	2007-11-19 20:45:20.000000000 -0700
+++ qemu/linux-user/syscall.c	2007-11-19 20:48:54.000000000 -0700
@@ -3515,7 +3515,7 @@
 
             argc = 0;
             guest_argp = arg2;
-            for (gp = guest_argp; ; gp += sizeof(abi_ulong)) {
+            for (gp = guest_argp; gp; gp += sizeof(abi_ulong)) {
                 if (get_user_ual(addr, gp))
                     goto efault;
                 if (!addr)
@@ -3524,7 +3524,7 @@
             }
             envc = 0;
             guest_envp = arg3;
-            for (gp = guest_envp; ; gp += sizeof(abi_ulong)) {
+            for (gp = guest_envp; gp; gp += sizeof(abi_ulong)) {
                 if (get_user_ual(addr, gp))
                     goto efault;
                 if (!addr)
@@ -3535,7 +3535,7 @@
             argp = alloca((argc + 1) * sizeof(void *));
             envp = alloca((envc + 1) * sizeof(void *));
 
-            for (gp = guest_argp, q = argp; ;
+            for (gp = guest_argp, q = argp; gp;
                   gp += sizeof(abi_ulong), q++) {
                 if (get_user_ual(addr, gp))
                     goto execve_efault;
@@ -3546,7 +3546,7 @@
             }
             *q = NULL;
 
-            for (gp = guest_envp, q = envp; ;
+            for (gp = guest_envp, q = envp; gp;
                   gp += sizeof(abi_ulong), q++) {
                 if (get_user_ual(addr, gp))
                     goto execve_efault;
@@ -3568,14 +3568,14 @@
             ret = -TARGET_EFAULT;
 
         execve_end:
-            for (gp = guest_argp, q = argp; *q;
+            for (gp = guest_argp, q = argp; gp && *q;
                   gp += sizeof(abi_ulong), q++) {
                 if (get_user_ual(addr, gp)
                     || !addr)
                     break;
                 unlock_user(*q, addr, 0);
             }
-            for (gp = guest_envp, q = envp; *q;
+            for (gp = guest_envp, q = envp; gp && *q;
                   gp += sizeof(abi_ulong), q++) {
                 if (get_user_ual(addr, gp)
                     || !addr)

                 reply	other threads:[~2007-12-11 16:43 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1197390843.2947.41.camel@phantasm.home.enterpriseandprosperity.com \
    --to=thayne@c2.net \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).