]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic/string-table: avoid crash when table is sparse
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 27 Feb 2020 20:28:54 +0000 (21:28 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 27 Feb 2020 20:36:58 +0000 (21:36 +0100)
Generated _from_string() would crash when invoked on a table with some
holes.

src/basic/string-table.h

index 2d3cf81435bd0e371abe6635e24b361437f49aeb..96924778f55c264e1b7a3c4f33333e1d0a7940fd 100644 (file)
@@ -44,7 +44,7 @@ ssize_t string_table_lookup(const char * const *table, size_t len, const char *k
                 char *s;                                                \
                 if (i < 0 || i > max)                                   \
                         return -ERANGE;                                 \
-                if (i < (type) ELEMENTSOF(name##_table)) {              \
+                if (i < (type) ELEMENTSOF(name##_table) && name##_table[i]) { \
                         s = strdup(name##_table[i]);                    \
                         if (!s)                                         \
                                 return -ENOMEM;                         \