From: Zbigniew Jędrzejewski-Szmek Date: Thu, 27 Feb 2020 20:28:54 +0000 (+0100) Subject: basic/string-table: avoid crash when table is sparse X-Git-Tag: v245-rc2~20^2~1 X-Git-Url: http://git-history.diyao.me/?a=commitdiff_plain;h=aa73f181e92ce991cff4e6890822764698befc90;p=systemd%2F.git basic/string-table: avoid crash when table is sparse Generated _from_string() would crash when invoked on a table with some holes. --- diff --git a/src/basic/string-table.h b/src/basic/string-table.h index 2d3cf81435..96924778f5 100644 --- a/src/basic/string-table.h +++ b/src/basic/string-table.h @@ -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; \