From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:55829) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RvV35-0002ml-6V for qemu-devel@nongnu.org; Thu, 09 Feb 2012 09:32:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RvV2z-0004Lq-D8 for qemu-devel@nongnu.org; Thu, 09 Feb 2012 09:32:35 -0500 Received: from mail-pw0-f45.google.com ([209.85.160.45]:55650) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RvV2z-0004Go-49 for qemu-devel@nongnu.org; Thu, 09 Feb 2012 09:32:29 -0500 Received: by mail-pw0-f45.google.com with SMTP id ro12so1788490pbb.4 for ; Thu, 09 Feb 2012 06:32:28 -0800 (PST) Sender: Paolo Bonzini From: Paolo Bonzini Date: Thu, 9 Feb 2012 15:31:56 +0100 Message-Id: <1328797918-1316-8-git-send-email-pbonzini@redhat.com> In-Reply-To: <1328797918-1316-1-git-send-email-pbonzini@redhat.com> References: <1328797918-1316-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 7/9] qdev: accept hex properties only if prefixed by 0x List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: aliguori@us.ibm.com Hex properties are an obstacle to removal of old qdev string parsing, but even here we can lay down the foundations for future simplification. In general, they are rarely used and their printed form is more interesting than the parsing. For example you'd usually set isa-serial.index instead of isa-serial.iobase. And luckily our main client, libvirt only cares about few of these, and always sets them with a 0x prefix. So the series stops accepting bare hexadecimal numbers, preparing for making legacy properties read-only in 1.3 or so. The read side will stay as long as "info qtree" is with us. Signed-off-by: Paolo Bonzini --- hw/qdev-properties.c | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-) diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c index 9a838b0..d47122a 100644 --- a/hw/qdev-properties.c +++ b/hw/qdev-properties.c @@ -164,6 +164,10 @@ static int parse_hex8(DeviceState *dev, Property *prop, const char *str) uint8_t *ptr = qdev_get_prop_ptr(dev, prop); char *end; + if (str[0] != '0' || str[1] != 'x') { + return -EINVAL; + } + *ptr = strtoul(str, &end, 16); if ((*end != '\0') || (end == str)) { return -EINVAL; @@ -369,6 +373,10 @@ static int parse_hex32(DeviceState *dev, Property *prop, const char *str) uint32_t *ptr = qdev_get_prop_ptr(dev, prop); char *end; + if (str[0] != '0' || str[1] != 'x') { + return -EINVAL; + } + *ptr = strtoul(str, &end, 16); if ((*end != '\0') || (end == str)) { return -EINVAL; @@ -456,6 +464,10 @@ static int parse_hex64(DeviceState *dev, Property *prop, const char *str) uint64_t *ptr = qdev_get_prop_ptr(dev, prop); char *end; + if (str[0] != '0' || str[1] != 'x') { + return -EINVAL; + } + *ptr = strtoull(str, &end, 16); if ((*end != '\0') || (end == str)) { return -EINVAL; -- 1.7.7.6