qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: riku.voipio@linaro.org
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org
Subject: [Qemu-devel] [PULL 2/5] linux-user: Fix memchr() argument in open_self_cmdline()
Date: Thu,  4 Aug 2016 17:15:02 +0300	[thread overview]
Message-ID: <ba4b3f668abf1fcde204c8f3185ea6edeec6eaa3.1470319929.git.riku.voipio@linaro.org> (raw)
In-Reply-To: <cover.1470319929.git.riku.voipio@linaro.org>

From: Peter Maydell <peter.maydell@linaro.org>

In open_self_cmdline() we look for a 0 in the buffer we read
from /prc/self/cmdline. We were incorrectly passing the length
of our buf[] array to memchr() as the length to search, rather
than the number of bytes we actually read into it, which could
be shorter. This was spotted by Coverity (because it could
result in our trying to pass a negative length argument to
write()).

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
---
 linux-user/syscall.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index ca6a2b4..092ff4e 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -6856,7 +6856,7 @@ static int open_self_cmdline(void *cpu_env, int fd)
         if (!word_skipped) {
             /* Skip the first string, which is the path to qemu-*-static
                instead of the actual command. */
-            cp_buf = memchr(buf, 0, sizeof(buf));
+            cp_buf = memchr(buf, 0, nb_read);
             if (cp_buf) {
                 /* Null byte found, skip one string */
                 cp_buf++;
-- 
2.1.4

  parent reply	other threads:[~2016-08-04 14:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-04 14:15 [Qemu-devel] [PULL 0/5] linux-user fixes for 2.7 riku.voipio
2016-08-04 14:15 ` [Qemu-devel] [PULL 1/5] linux-user: Use correct alignment for long long on i386 guests riku.voipio
2016-08-04 14:15 ` riku.voipio [this message]
2016-08-04 14:15 ` [Qemu-devel] [PULL 3/5] linux-user: Don't write off end of new_utsname buffer riku.voipio
2016-08-04 14:15 ` [Qemu-devel] [PULL 4/5] linux-user: Fix target_semid_ds structure definition riku.voipio
2016-08-04 14:15 ` [Qemu-devel] [PULL 5/5] linux-user: Handle brk() attempts with very large sizes riku.voipio
2016-08-05  9:21 ` [Qemu-devel] [PULL 0/5] linux-user fixes for 2.7 Peter Maydell

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=ba4b3f668abf1fcde204c8f3185ea6edeec6eaa3.1470319929.git.riku.voipio@linaro.org \
    --to=riku.voipio@linaro.org \
    --cc=peter.maydell@linaro.org \
    --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).