]> granicus.if.org Git - gc/commitdiff
Fix potential null dereference in GC_CONS
authorIvan Maidanski <ivmai@mail.ru>
Mon, 7 May 2018 21:47:48 +0000 (00:47 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Tue, 17 Jul 2018 06:15:02 +0000 (09:15 +0300)
(a cherry-pick of commit e39899ac from 'release-7_6')

* include/gc_inline.h (GC_CONS): Store second element only if result
is non-null; store first element along with second one.

include/gc_inline.h

index d6e467cd16b518628b2333b49842063ddb74a450..9b8aef40e7981b883d862883f6acc81f6d8d6db5 100644 (file)
@@ -150,8 +150,11 @@ GC_API void GC_CALL GC_generic_malloc_many(size_t /* lb */, int /* k */,
     size_t grans = GC_WORDS_TO_WHOLE_GRANULES(2); \
     GC_FAST_MALLOC_GRANS(result, grans, tiny_fl, 0, GC_I_NORMAL, \
                          GC_malloc(grans * GC_GRANULE_BYTES), \
-                         *(void **)(result) = (void *)(first)); \
-    ((void **)(result))[1] = (void *)(second); \
+                         (void)0); \
+    if ((result) != NULL) { \
+      *(void **)(result) = (void *)(first); \
+      ((void **)(result))[1] = (void *)(second); \
+    } \
   } while (0)
 
 #endif /* !GC_INLINE_H */