From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51869) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VlZvm-0007ex-Te for qemu-devel@nongnu.org; Wed, 27 Nov 2013 02:53:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VlZvh-0006hk-NK for qemu-devel@nongnu.org; Wed, 27 Nov 2013 02:53:06 -0500 Received: from cantor2.suse.de ([195.135.220.15]:60670 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VlZvh-0006ha-Ga for qemu-devel@nongnu.org; Wed, 27 Nov 2013 02:53:01 -0500 From: Hannes Reinecke Date: Wed, 27 Nov 2013 08:52:55 +0100 Message-Id: <1385538775-4208-1-git-send-email-hare@suse.de> Subject: [Qemu-devel] [PATCHv2] qdev: Validate hex properties List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Andreas Faerber Cc: Peter Maydell , Hannes Reinecke , qemu-devel@nongnu.org, Alexander Graf 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 Cc: Eric Blake Signed-off-by: Hannes Reinecke --- 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