mirror of
https://github.com/morgan9e/systemd
synced 2026-04-14 16:37:19 +09:00
basic/string-table: avoid crash when table is sparse
Generated _from_string() would crash when invoked on a table with some holes.
This commit is contained in:
@@ -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; \
|
||||
|
||||
Reference in New Issue
Block a user