]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
datatype: Initialize rt_symbol_tables' base field
authorPhil Sutter <phil@nwl.cc>
Fri, 22 Dec 2023 15:53:14 +0000 (16:53 +0100)
committerPhil Sutter <phil@nwl.cc>
Tue, 2 Jan 2024 17:29:51 +0000 (18:29 +0100)
It is unconditionally accessed in symbol_table_print() so make sure it
is initialized to either BASE_DECIMAL (arbitrary) for empty or
non-existent source files or a proper value depending on entry number
format.

Signed-off-by: Phil Sutter <phil@nwl.cc>
src/datatype.c

index 9ca0516700f81d9aa7d5528992cea3276bbb608b..4d867798222be1b74834b0a2774c5d052ea7d226 100644 (file)
@@ -893,6 +893,7 @@ struct symbol_table *rt_symbol_table_init(const char *filename)
 
        size = RT_SYM_TAB_INITIAL_SIZE;
        tbl = xmalloc(sizeof(*tbl) + size * sizeof(s));
+       tbl->base = BASE_DECIMAL;
        nelems = 0;
 
        f = open_iproute2_db(filename, &path);
@@ -905,10 +906,13 @@ struct symbol_table *rt_symbol_table_init(const char *filename)
                        p++;
                if (*p == '#' || *p == '\n' || *p == '\0')
                        continue;
-               if (sscanf(p, "0x%x %511s\n", &val, namebuf) != 2 &&
-                   sscanf(p, "0x%x %511s #", &val, namebuf) != 2 &&
-                   sscanf(p, "%u %511s\n", &val, namebuf) != 2 &&
-                   sscanf(p, "%u %511s #", &val, namebuf) != 2) {
+               if (sscanf(p, "0x%x %511s\n", &val, namebuf) == 2 ||
+                   sscanf(p, "0x%x %511s #", &val, namebuf) == 2) {
+                       tbl->base = BASE_HEXADECIMAL;
+               } else if (sscanf(p, "%u %511s\n", &val, namebuf) == 2 ||
+                          sscanf(p, "%u %511s #", &val, namebuf) == 2) {
+                       tbl->base = BASE_DECIMAL;
+               } else {
                        fprintf(stderr, "iproute database '%s' corrupted\n",
                                path ?: filename);
                        break;