Skip to contentSkip to conversation

json-parser: Fix potential NULL pointer segfault

PATCH Applied Stefan Weil 2 participants 2 messages Sep 3, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 json-parser: Fix potential NULL pointer segfault

Report from smatch:
json-parser.c:474 parse_object(62) error: potential null derefence 'dict'. json-parser.c:553 parse_array(75) error: potential null derefence 'list'.

Label 'out' in json-parser.c can be called with list == NULL which is passed to QDECREF.

Modify QDECREF to handle a NULL argument (inline function qobject_decref already handles them, too).

---

I did not change QINCREF because there are currently no errors caused by that rarely used macro.

This patch can be used instead of the previous patch which fixed the problem directly in json-parser.c
(see http://patchwork.ozlabs.org/patch/181129/).

Regards,
Stefan Weil

 qobject.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
qobject.h +1 -1
index d42386d..9124649 100644
@@ -71,7 +71,7 @@ typedef struct QObject {
 
 /* High-level interface for qobject_decref() */
 #define QDECREF(obj)              \
-    qobject_decref(QOBJECT(obj))
+    qobject_decref(obj ? QOBJECT(obj) : NULL)
 
 /* Initialize an object to default values */
 #define QOBJECT_INIT(obj, qtype_type)   \
Signature · 1 line
1.7.10
#1 lore raw
Quoted 11 lines · On Mon, 3 Sep 2012 21:19:11 +0200 Stefan Weil <[email protected]> wrote:

Report from smatch:
json-parser.c:474 parse_object(62) error: potential null derefence 'dict'. json-parser.c:553 parse_array(75) error: potential null derefence 'list'.

Label 'out' in json-parser.c can be called with list == NULL which is passed to QDECREF.

Modify QDECREF to handle a NULL argument (inline function qobject_decref already handles them, too).

Applied to qmp-next branch, thanks!

Quoted 28 lines

---

I did not change QINCREF because there are currently no errors caused by that rarely used macro.

This patch can be used instead of the previous patch which fixed the problem directly in json-parser.c
(see http://patchwork.ozlabs.org/patch/181129/).

Regards,
Stefan Weil

 qobject.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
qobject.h +1 -1
index d42386d..9124649 100644
@@ -71,7 +71,7 @@ typedef struct QObject {
 
 /* High-level interface for qobject_decref() */
 #define QDECREF(obj)              \
-    qobject_decref(QOBJECT(obj))
+    qobject_decref(obj ? QOBJECT(obj) : NULL)
 
 /* Initialize an object to default values */
 #define QOBJECT_INIT(obj, qtype_type)   \