[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCHv2] qdev: Validate hex properties
From: |
Hannes Reinecke |
Subject: |
[Qemu-devel] [PATCHv2] qdev: Validate hex properties |
Date: |
Wed, 27 Nov 2013 08:52:55 +0100 |
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.
Cc: Peter Maydell <address@hidden>
Cc: Eric Blake <address@hidden>
Signed-off-by: Hannes Reinecke <address@hidden>
---
hw/core/qdev-properties.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index dc8ae69..5a94c04 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -198,7 +198,10 @@ static int parse_hex8(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;
}
@@ -329,7 +332,10 @@ 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 +402,10 @@ 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
- [Qemu-devel] [PATCHv2] qdev: Validate hex properties,
Hannes Reinecke <=