From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50235) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ztllw-0006Ao-KR for qemu-devel@nongnu.org; Tue, 03 Nov 2015 19:17:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ztllv-0007Fi-LL for qemu-devel@nongnu.org; Tue, 03 Nov 2015 19:17:52 -0500 From: John Snow Date: Tue, 3 Nov 2015 19:17:41 -0500 Message-Id: <1446596262-15328-3-git-send-email-jsnow@redhat.com> In-Reply-To: <1446596262-15328-1-git-send-email-jsnow@redhat.com> References: <1446596262-15328-1-git-send-email-jsnow@redhat.com> Subject: [Qemu-devel] [PATCH v3 2/3] qemu-io: Check for trailing chars List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-block@nongnu.org Cc: kwolf@redhat.com, John Snow , qemu-devel@nongnu.org, mreitz@redhat.com Make sure there's not trailing garbage, e.g. "64k-whatever-i-want-here" Reported-by: Max Reitz Signed-off-by: John Snow Reviewed-by: Eric Blake Reviewed-by: Kevin Wolf --- 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 f04c1db..2c38ae7 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