diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2017-09-25 11:09:57 +0200 |
---|---|---|
committer | Sven Eden <yamakuzure@gmx.net> | 2017-09-25 11:09:57 +0200 |
commit | b32efd4b179b958d57653f4cc074413307e7dab1 (patch) | |
tree | bb241aa50746d6d242effedef792b9fe8f2c6d4b /src/basic/cap-list.c | |
parent | 68bb1246bf0dc56f61b6d655694ddd4df647167c (diff) |
basic/cap-list: report empty capability set as ""
$ systemctl show elogind-journald -p CapabilityBoundingSet,AmbientCapabilities
CapabilityBoundingSet=cap_chown cap_dac_override cap_dac_read_search cap_fowner cap_setgid ...
AmbientCapabilities=(null)
↓
$ systemctl show elogind-journald -p CapabilityBoundingSet,AmbientCapabilities
CapabilityBoundingSet=cap_chown cap_dac_override cap_dac_read_search cap_fowner cap_setgid ...
AmbientCapabilities=
Partially fixes #6511. Add some basic tests for the printing function.
Diffstat (limited to 'src/basic/cap-list.c')
-rw-r--r-- | src/basic/cap-list.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/basic/cap-list.c b/src/basic/cap-list.c index 124641f94..2e9b2d9a5 100644 --- a/src/basic/cap-list.c +++ b/src/basic/cap-list.c @@ -86,15 +86,17 @@ int capability_set_to_string_alloc(uint64_t set, char **s) { add = strlen(p); - if (!GREEDY_REALLOC0(str, allocated, n + add + 2)) + if (!GREEDY_REALLOC(str, allocated, n + add + 2)) return -ENOMEM; strcpy(mempcpy(str + n, p, add), " "); n += add + 1; } - if (n != 0) - str[n - 1] = '\0'; + if (!GREEDY_REALLOC(str, allocated, n + 1)) + return -ENOMEM; + + str[n > 0 ? n - 1 : 0] = '\0'; /* truncate the last space, if it's there */ *s = str; str = NULL; |