bus: do not segfault on zeros in errno mapping table

Depending on the link order, holes might appear in the body of
the sd_bus_errnomap section. Ignore them.

Adds a simple test to print the table to help with debugging such
issues in the future.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2014-10-31 11:32:00 -04:00
parent 919699ec30
commit 5e071f200c
2 changed files with 14 additions and 1 deletions
+1 -1
View File
@@ -80,7 +80,7 @@ static int bus_error_mapping_lookup(const char *name, size_t len) {
const sd_bus_name_error_mapping *m;
for (m = __start_sd_bus_errnomap; m < __stop_sd_bus_errnomap; m++)
if (strneq(m->name, name, len))
if (m->name && strneq(m->name, name, len))
return m->code;
return EIO;
+13
View File
@@ -111,6 +111,18 @@ static void test_error(void) {
assert_se(sd_bus_error_is_set(&error));
}
extern const sd_bus_name_error_mapping __start_sd_bus_errnomap[];
extern const sd_bus_name_error_mapping __stop_sd_bus_errnomap[];
static void dump_mapping_table(void) {
const sd_bus_name_error_mapping *m;
printf("----- errno mappings ------\n");
for (m = __start_sd_bus_errnomap; m < __stop_sd_bus_errnomap; m++)
printf("%s -> %d\n", m->name, m->code);
printf("---------------------------\n");
}
static void test_errno_mapping_standard(void) {
assert_se(sd_bus_error_set(NULL, "System.Error.EUCLEAN", NULL) == -EUCLEAN);
assert_se(sd_bus_error_set(NULL, "System.Error.EBUSY", NULL) == -EBUSY);
@@ -130,6 +142,7 @@ static void test_errno_mapping_custom(void) {
}
int main(int argc, char *argv[]) {
dump_mapping_table();
test_error();
test_errno_mapping_standard();