summaryrefslogtreecommitdiff
path: root/src/libelogind/sd-bus/bus-error.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2016-01-13 14:23:54 -0500
committerSven Eden <yamakuzure@gmx.net>2017-05-17 15:22:15 +0200
commit26d2a60ca60f4f6cd7d5b5a907841c5e8e7d6365 (patch)
tree68f1d6cda7eef7cba0f76dc8bd430d649cd718ae /src/libelogind/sd-bus/bus-error.c
parent3b22b89bce6c5185e1db0a28390a0e6df138a27b (diff)
bus-error: verify additional error maps during installation
Go over the entries in the map and check that they make sense. Tests are added. In the future we might want to do additional checks, e.g. verifying that the error names are in the expected format.
Diffstat (limited to 'src/libelogind/sd-bus/bus-error.c')
-rw-r--r--src/libelogind/sd-bus/bus-error.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/libelogind/sd-bus/bus-error.c b/src/libelogind/sd-bus/bus-error.c
index a99d55c47..c77eb5fd0 100644
--- a/src/libelogind/sd-bus/bus-error.c
+++ b/src/libelogind/sd-bus/bus-error.c
@@ -579,27 +579,29 @@ const char *bus_error_message(const sd_bus_error *e, int error) {
return strerror(error);
}
+static bool map_ok(const sd_bus_error_map *map) {
+ for (; map->code != BUS_ERROR_MAP_END_MARKER; map++)
+ if (!map->name || map->code <=0)
+ return false;
+ return true;
+}
+
_public_ int sd_bus_error_add_map(const sd_bus_error_map *map) {
const sd_bus_error_map **maps = NULL;
unsigned n = 0;
assert_return(map, -EINVAL);
+ assert_return(map_ok(map), -EINVAL);
- if (additional_error_maps) {
- for (;; n++) {
- if (additional_error_maps[n] == NULL)
- break;
-
+ if (additional_error_maps)
+ for (; additional_error_maps[n] != NULL; n++)
if (additional_error_maps[n] == map)
return 0;
- }
- }
maps = realloc_multiply(additional_error_maps, sizeof(struct sd_bus_error_map*), n + 2);
if (!maps)
return -ENOMEM;
-
maps[n] = map;
maps[n+1] = NULL;