commit 6d82708

Santtu Lakkala  ·  2025-02-20 14:23:11 +0000 UTC
parent d40834e
Fix uninitialised memory access

Avoid calling xs_type() on uninitialised memory when xs_extend() is
called with NULL data.
1 files changed,  +4, -3
M xs.h
M xs.h
+4, -3
 1@@ -398,6 +398,7 @@ xs_val *xs_dup(const xs_val *data)
 2 xs_val *xs_expand(xs_val *data, int offset, int size)
 3 /* opens a hole in data */
 4 {
 5+    xstype type = xs_type(data);
 6     int sz = xs_size(data);
 7     int n;
 8 
 9@@ -410,9 +411,9 @@ xs_val *xs_expand(xs_val *data, int offset, int size)
10     for (n = sz - 1; n >= offset + size; n--)
11         data[n] = data[n - size];
12 
13-    if (xs_type(data) == XSTYPE_LIST ||
14-        xs_type(data) == XSTYPE_DICT ||
15-        xs_type(data) == XSTYPE_DATA)
16+    if (type == XSTYPE_LIST ||
17+        type == XSTYPE_DICT ||
18+        type == XSTYPE_DATA)
19         _xs_put_size(data, sz);
20 
21     return data;