From: Hannes Reinecke <hare@suse.de>
To: Andreas Faerber <afaerber@suse.de>
Cc: Hannes Reinecke <hare@suse.de>,
qemu-devel@nongnu.org, Alexander Graf <agraf@suse.de>
Subject: [Qemu-devel] [PATCHv3] qdev: Validate hex properties
Date: Thu, 28 Nov 2013 09:39:07 +0100 [thread overview]
Message-ID: <1385627947-23147-1-git-send-email-hare@suse.de> (raw)
strtoul(l) might overflow, in which case it'll return '-1' and set
the appropriate error code. So update the calls to strtoul(l) when
parsing hex properties to avoid silent overflows.
Signed-off-by: Hannes Reinecke <hare@suse.de>
---
hw/core/qdev-properties.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index dc8ae69..4891a01 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -191,6 +191,7 @@ PropertyInfo qdev_prop_uint8 = {
static int parse_hex8(DeviceState *dev, Property *prop, const char *str)
{
+ unsigned long val;
uint8_t *ptr = qdev_get_prop_ptr(dev, prop);
char *end;
@@ -198,11 +199,18 @@ static int parse_hex8(DeviceState *dev, Property *prop, const char *str)
return -EINVAL;
}
- *ptr = strtoul(str, &end, 16);
+ errno = 0;
+ val = strtoul(str, &end, 16);
+ if (errno) {
+ return -errno;
+ }
+ if (val > 255) {
+ return -ERANGE;
+ }
if ((*end != '\0') || (end == str)) {
return -EINVAL;
}
-
+ *ptr = val;
return 0;
}
@@ -329,7 +337,11 @@ static int parse_hex32(DeviceState *dev, Property *prop, const char *str)
return -EINVAL;
}
+ errno = 0;
*ptr = strtoul(str, &end, 16);
+ if (errno) {
+ return -errno;
+ }
if ((*end != '\0') || (end == str)) {
return -EINVAL;
}
@@ -396,7 +408,11 @@ static int parse_hex64(DeviceState *dev, Property *prop, const char *str)
return -EINVAL;
}
+ errno = 0;
*ptr = strtoull(str, &end, 16);
+ if (errno) {
+ return -errno;
+ }
if ((*end != '\0') || (end == str)) {
return -EINVAL;
}
--
1.8.1.4
next reply other threads:[~2013-11-28 8:39 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-28 8:39 Hannes Reinecke [this message]
2013-11-28 14:09 ` [Qemu-devel] [PATCHv3] qdev: Validate hex properties Andreas Färber
2013-11-28 17:46 ` Eric Blake
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=1385627947-23147-1-git-send-email-hare@suse.de \
--to=hare@suse.de \
--cc=afaerber@suse.de \
--cc=agraf@suse.de \
--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).