2017-12-14 17:54:42 +00:00
|
|
|
From 9aca3b6a087a396a81d7e26f4557eb97fecc1386 Mon Sep 17 00:00:00 2001
|
2017-12-13 19:36:53 +00:00
|
|
|
From: =?UTF-8?q?Bj=C3=B6rn=20Esser?= <besser82@fedoraproject.org>
|
|
|
|
Date: Wed, 13 Dec 2017 19:22:52 +0100
|
2017-12-14 17:54:42 +00:00
|
|
|
Subject: [PATCH] json_object: Avoid invalid free (and thus a segfault) when
|
2017-12-13 19:36:53 +00:00
|
|
|
ref_count gets < 0
|
|
|
|
|
|
|
|
---
|
2017-12-14 17:54:42 +00:00
|
|
|
json_object.c | 5 +++++
|
|
|
|
1 file changed, 5 insertions(+)
|
2017-12-13 19:36:53 +00:00
|
|
|
|
|
|
|
diff --git a/json_object.c b/json_object.c
|
2017-12-14 17:54:42 +00:00
|
|
|
index 042477a71b..7c7438d8ea 100644
|
2017-12-13 19:36:53 +00:00
|
|
|
--- a/json_object.c
|
|
|
|
+++ b/json_object.c
|
2017-12-14 17:54:42 +00:00
|
|
|
@@ -182,6 +182,11 @@ int json_object_put(struct json_object *jso)
|
|
|
|
{
|
|
|
|
if(!jso) return 0;
|
2017-12-13 19:36:53 +00:00
|
|
|
|
2017-12-14 17:54:42 +00:00
|
|
|
+ /* Avoid invalid free and crash explicitly instead of (silently)
|
|
|
|
+ * segfaulting.
|
|
|
|
+ */
|
|
|
|
+ assert(jso->_ref_count > 0);
|
|
|
|
+
|
|
|
|
#if defined(HAVE_ATOMIC_BUILTINS) && defined(ENABLE_THREADING)
|
|
|
|
/* Note: this only allow the refcount to remain correct
|
|
|
|
* when multiple threads are adjusting it. It is still an error
|