qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] include/hw: field 'offset' in struct Property should be ptrdiff_t as int causes overflow
@ 2015-03-04 14:09 Ildar Isaev
  2015-08-25 14:17 ` Markus Armbruster
  0 siblings, 1 reply; 8+ messages in thread
From: Ildar Isaev @ 2015-03-04 14:09 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell, Ildar Isaev, aliguori

'offset' field in struct Property is calculated as a diff between two pointers (hw/core/qdev-properties.c:802)

arrayprop->prop.offset = eltptr - (void *)dev;

If offset is declared as int, this subtraction can cause type overflow
thus leading to the fall of the subsequent assert (hw/core/qdev-properties.c:803)

assert(qdev_get_prop_ptr(dev, &arrayprop->prop) == eltptr);

So ptrdiff_t should be used instead

Signed-off-by: Ildar Isaev <ild@inbox.ru>
---
 include/hw/qdev-core.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index 4e673f9..f0e2a73 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -224,7 +224,7 @@ struct BusState {
 struct Property {
     const char   *name;
     PropertyInfo *info;
-    int          offset;
+    ptrdiff_t    offset;
     uint8_t      bitnr;
     uint8_t      qtype;
     int64_t      defval;
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-11-13 19:36 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-04 14:09 [Qemu-devel] [PATCH] include/hw: field 'offset' in struct Property should be ptrdiff_t as int causes overflow Ildar Isaev
2015-08-25 14:17 ` Markus Armbruster
2015-08-25 14:32   ` Peter Maydell
2015-11-11  8:54     ` Markus Armbruster
2015-11-12 17:41       ` Andreas Färber
2015-11-13 18:32         ` John Snow
2015-11-13 18:36           ` Andreas Färber
2015-11-13 19:36             ` John Snow

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).