[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 02/21] hw/core/qdev-properties: Use qemu_strtol() in set_mac() han
From: |
Eduardo Habkost |
Subject: |
[PULL 02/21] hw/core/qdev-properties: Use qemu_strtol() in set_mac() handler |
Date: |
Mon, 5 Oct 2020 17:09:41 -0400 |
From: Philippe Mathieu-Daudé <philmd@redhat.com>
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.
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20200930164949.1425294-3-philmd@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
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 343c824da04..080ba319a1f 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"
@@ -524,7 +525,8 @@ static void set_mac(Object *obj, Visitor *v, const char
*name, void *opaque,
Property *prop = opaque;
MACAddr *mac = qdev_get_prop_ptr(dev, prop);
int i, pos;
- char *str, *p;
+ char *str;
+ const char *p;
if (dev->realized) {
qdev_prop_set_after_realize(dev, name, errp);
@@ -536,6 +538,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;
}
@@ -551,7 +555,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.26.2
- [PULL 00/21] machine + QOM queue, 2020-10-05, Eduardo Habkost, 2020/10/05
- [PULL 01/21] numa: hmat: require parent cache description before the next level one, Eduardo Habkost, 2020/10/05
- [PULL 03/21] hw/core/qdev-properties: Use qemu_strtoul() in set_pci_host_devaddr(), Eduardo Habkost, 2020/10/05
- [PULL 02/21] hw/core/qdev-properties: Use qemu_strtol() in set_mac() handler,
Eduardo Habkost <=
- [PULL 04/21] hw/core/qdev-properties: Fix code style, Eduardo Habkost, 2020/10/05
- [PULL 05/21] hw/core/qdev-properties: Export enum-related functions, Eduardo Habkost, 2020/10/05
- [PULL 06/21] hw/core/qdev-properties: Export qdev_prop_enum, Eduardo Habkost, 2020/10/05
- [PULL 07/21] hw/core/qdev-properties: Export some integer-related functions, Eduardo Habkost, 2020/10/05
- [PULL 09/21] hw/core/cpu: Add missing 'exec/cpu-common.h' include, Eduardo Habkost, 2020/10/05
- [PULL 11/21] qom: Fix DECLARE_*CHECKER documentation, Eduardo Habkost, 2020/10/05
- [PULL 08/21] hw/core/qdev-properties: Extract system-mode specific properties, Eduardo Habkost, 2020/10/05
- [PULL 13/21] docs/devel/qom: Fix indentation of code blocks, Eduardo Habkost, 2020/10/05
- [PULL 10/21] qom: Improve error message displayed with missing object properties, Eduardo Habkost, 2020/10/05
- [PULL 12/21] docs/devel/qom: Fix indentation of bulleted list, Eduardo Habkost, 2020/10/05