[systemd-devel] [PATCH] journal: avoid NULL pointer dereference in chain_cache_put

philippedeswert at gmail.com philippedeswert at gmail.com
Mon Oct 27 14:36:26 PDT 2014


From: Philippe De Swert <philippedeswert at gmail.com>

ordered_hashmap_steal_first() can return NULL (and this is usually checked
except here), so there is a potential NULL pointer reference.
Thus moving the NULL check to cover both possible allocations of the
ChainCacheItem.

Found with coverity. Fixes: CID#1249723
---
 src/journal/journal-file.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
index d06dbc2..1add0c7 100644
--- a/src/journal/journal-file.c
+++ b/src/journal/journal-file.c
@@ -1384,10 +1384,11 @@ static void chain_cache_put(
                         ci = ordered_hashmap_steal_first(h);
                 else {
                         ci = new(ChainCacheItem, 1);
-                        if (!ci)
-                                return;
                 }
 
+                if (!ci)
+                       return;
+
                 ci->first = first;
 
                 if (ordered_hashmap_put(h, &ci->first, ci) < 0) {
-- 
1.8.3.2



More information about the systemd-devel mailing list