All of lore.kernel.org
 help / color / mirror / Atom feed
From: John Snow <jsnow@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, John Snow <jsnow@redhat.com>,
	qemu-devel@nongnu.org, mreitz@redhat.com
Subject: [Qemu-devel] [PATCH v4 2/3] qemu-io: Check for trailing chars
Date: Thu,  5 Nov 2015 18:53:03 -0500	[thread overview]
Message-ID: <1446767584-13132-3-git-send-email-jsnow@redhat.com> (raw)
In-Reply-To: <1446767584-13132-1-git-send-email-jsnow@redhat.com>

Make sure there's not trailing garbage, e.g.
"64k-whatever-i-want-here"

Reported-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
---
 qemu-io-cmds.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
index 20605f2..238b1da 100644
--- a/qemu-io-cmds.c
+++ b/qemu-io-cmds.c
@@ -136,7 +136,14 @@ static char **breakline(char *input, int *count)
 static int64_t cvtnum(const char *s)
 {
     char *end;
-    return qemu_strtosz_suffix(s, &end, QEMU_STRTOSZ_DEFSUFFIX_B);
+    int64_t ret;
+
+    ret = qemu_strtosz_suffix(s, &end, QEMU_STRTOSZ_DEFSUFFIX_B);
+    if (*end != '\0') {
+        /* Detritus at the end of the string */
+        return -EINVAL;
+    }
+    return ret;
 }
 
 #define EXABYTES(x)     ((long long)(x) << 60)
-- 
2.4.3

  parent reply	other threads:[~2015-11-05 23:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-05 23:53 [Qemu-devel] [PATCH v4 0/3] qemu-io: clean up cvtnum usage John Snow
2015-11-05 23:53 ` [Qemu-devel] [PATCH v4 1/3] qemu-io: fix cvtnum lval types John Snow
2015-11-05 23:53 ` John Snow [this message]
2015-11-05 23:53 ` [Qemu-devel] [PATCH v4 3/3] qemu-io: Correct error messages John Snow
2015-11-06  9:46 ` [Qemu-devel] [PATCH v4 0/3] qemu-io: clean up cvtnum usage Kevin Wolf
2015-11-06 19:01   ` John Snow

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=1446767584-13132-3-git-send-email-jsnow@redhat.com \
    --to=jsnow@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.