[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 1/9] hw/core/qdev-properties: Use qemu_strtol() in set_mac() h
From: |
Philippe Mathieu-Daudé |
Subject: |
[PATCH v2 1/9] hw/core/qdev-properties: Use qemu_strtol() in set_mac() handler |
Date: |
Mon, 16 Mar 2020 01:11:03 +0100 |
The MACAddr structure contains an array of uint8_t. Previously
if a value was out of the [0..255] range, it was silently casted
and no input validation was done.
Replace strtol() by qemu_strtol() -- so checkpatch.pl won't
complain if we move this code later -- and return EINVAL if the
input is invalid.
Reviewed-by: Richard Henderson <address@hidden>
Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
---
v2: Comment we added input validation (rth)
---
hw/core/qdev-properties.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index 59380ed761..48e4c98cf0 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -1,4 +1,5 @@
#include "qemu/osdep.h"
+#include "qemu/cutils.h"
#include "net/net.h"
#include "hw/qdev-properties.h"
#include "qapi/error.h"
@@ -532,7 +533,8 @@ static void set_mac(Object *obj, Visitor *v, const char
*name, void *opaque,
MACAddr *mac = qdev_get_prop_ptr(dev, prop);
Error *local_err = NULL;
int i, pos;
- char *str, *p;
+ char *str;
+ const char *p;
if (dev->realized) {
qdev_prop_set_after_realize(dev, name, errp);
@@ -546,6 +548,8 @@ static void set_mac(Object *obj, Visitor *v, const char
*name, void *opaque,
}
for (i = 0, pos = 0; i < 6; i++, pos += 3) {
+ long val;
+
if (!qemu_isxdigit(str[pos])) {
goto inval;
}
@@ -561,7 +565,10 @@ static void set_mac(Object *obj, Visitor *v, const char
*name, void *opaque,
goto inval;
}
}
- mac->a[i] = strtol(str+pos, &p, 16);
+ if (qemu_strtol(str + pos, &p, 16, &val) < 0 || val > 0xff) {
+ goto inval;
+ }
+ mac->a[i] = val;
}
g_free(str);
return;
--
2.21.1
- [PATCH v2 0/9] user-mode: Prune build dependencies (part 3), Philippe Mathieu-Daudé, 2020/03/15
- [PATCH v2 1/9] hw/core/qdev-properties: Use qemu_strtol() in set_mac() handler,
Philippe Mathieu-Daudé <=
- [PATCH v2 2/9] hw/core/qdev-properties: Use qemu_strtoul() in set_pci_host_devaddr(), Philippe Mathieu-Daudé, 2020/03/15
- [PATCH v2 3/9] hw/core/qdev-properties: Fix code style, Philippe Mathieu-Daudé, 2020/03/15
- [PATCH v2 4/9] hw/core/qdev-properties: Export enum-related functions, Philippe Mathieu-Daudé, 2020/03/15
- [PATCH v2 5/9] hw/core/qdev-properties: Export qdev_prop_enum, Philippe Mathieu-Daudé, 2020/03/15
- [PATCH v2 6/9] hw/core/qdev-properties: Export some integer-related functions, Philippe Mathieu-Daudé, 2020/03/15
- [PATCH v2 8/9] hw/core: Add qdev stub for user-mode, Philippe Mathieu-Daudé, 2020/03/15
- [PATCH v2 9/9] qapi: Restrict code generated for user-mode, Philippe Mathieu-Daudé, 2020/03/15
- [PATCH v2 7/9] hw/core/qdev-properties: Extract system-mode specific properties, Philippe Mathieu-Daudé, 2020/03/15