From: Alex Williamson <alex.williamson@redhat.com>
To: qemu-devel@nongnu.org, kvm@vger.kernel.org
Cc: pbonzini@redhat.com, imammedo@redhat.com
Subject: [Qemu-devel] [PATCH v3 1/2] qapi: Create DEFINE_PROP_STRING_LEN
Date: Fri, 16 Oct 2015 12:54:05 -0600 [thread overview]
Message-ID: <20151016185405.1248.70564.stgit@gimli.home> (raw)
In-Reply-To: <20151016184627.1248.63936.stgit@gimli.home>
A slight addition to set_string(), which optionally tests that the
string length is within the bounds specified.
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---
hw/core/qdev-properties.c | 7 +++++++
include/hw/qdev-core.h | 1 +
include/hw/qdev-properties.h | 16 ++++++++++++++--
3 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index 33e245e..51a05c7 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -422,6 +422,13 @@ static void set_string(Object *obj, Visitor *v, void *opaque,
error_propagate(errp, local_err);
return;
}
+
+ if (prop->strlen >= 0 && strlen(str) > prop->strlen) {
+ error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str);
+ g_free(str);
+ return;
+ }
+
g_free(*ptr);
*ptr = str;
}
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index 8057aed..12e3031 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -244,6 +244,7 @@ struct Property {
int arrayoffset;
PropertyInfo *arrayinfo;
int arrayfieldsize;
+ int strlen;
};
struct PropertyInfo {
diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h
index 77538a8..2a46640 100644
--- a/include/hw/qdev-properties.h
+++ b/include/hw/qdev-properties.h
@@ -69,6 +69,20 @@ extern PropertyInfo qdev_prop_arraylen;
.qtype = QTYPE_QBOOL, \
.defval = (bool)_defval, \
}
+#define DEFINE_PROP_STRING(_name, _state, _field) { \
+ .name = (_name), \
+ .info = &(qdev_prop_string), \
+ .strlen = -1, \
+ .offset = offsetof(_state, _field) \
+ + type_check(char*, typeof_field(_state, _field)), \
+ }
+#define DEFINE_PROP_STRING_LEN(_name, _state, _field, _strlen) { \
+ .name = (_name), \
+ .info = &(qdev_prop_string), \
+ .strlen = (_strlen), \
+ .offset = offsetof(_state, _field) \
+ + type_check(char*, typeof_field(_state, _field)), \
+ }
#define PROP_ARRAY_LEN_PREFIX "len-"
@@ -144,8 +158,6 @@ extern PropertyInfo qdev_prop_arraylen;
#define DEFINE_PROP_CHR(_n, _s, _f) \
DEFINE_PROP(_n, _s, _f, qdev_prop_chr, CharDriverState*)
-#define DEFINE_PROP_STRING(_n, _s, _f) \
- DEFINE_PROP(_n, _s, _f, qdev_prop_string, char*)
#define DEFINE_PROP_NETDEV(_n, _s, _f) \
DEFINE_PROP(_n, _s, _f, qdev_prop_netdev, NICPeers)
#define DEFINE_PROP_VLAN(_n, _s, _f) \
next prev parent reply other threads:[~2015-10-16 18:54 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-16 18:53 [Qemu-devel] [PATCH v3 0/2] Enable specifying a non-default Hyper-V vendor ID Alex Williamson
2015-10-16 18:54 ` Alex Williamson [this message]
2015-10-16 18:54 ` [Qemu-devel] [PATCH v3 2/2] kvm: Allow the Hyper-V vendor ID to be specified Alex Williamson
2015-10-16 23:06 ` [Qemu-devel] [PATCH v3 0/2] Enable specifying a non-default Hyper-V vendor ID Amos Jianjun Kong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20151016185405.1248.70564.stgit@gimli.home \
--to=alex.williamson@redhat.com \
--cc=imammedo@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).