[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCHv2] qdev: Validate hex properties
From: |
Andreas Färber |
Subject: |
Re: [Qemu-devel] [PATCHv2] qdev: Validate hex properties |
Date: |
Wed, 27 Nov 2013 10:35:01 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.0 |
Am 27.11.2013 08:52, schrieb Hannes Reinecke:
> 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;
> }
Thanks, this seems to match the requested logic. But please run
checkpatch.pl and add the missing braces. I'll queue it then.
Please add Cc: address@hidden to the commit message while at it
since this seems a bug fix that spans multiple releases.
Regards,
Andreas
> @@ -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;
> }
>
--
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg