chiark / gitweb /
basic/cap-list: report empty capability set as ""
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 25 Sep 2017 09:09:57 +0000 (11:09 +0200)
committerSven Eden <yamakuzure@gmx.net>
Mon, 25 Sep 2017 09:09:57 +0000 (11:09 +0200)
$ 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.

src/basic/cap-list.c

index 124641f940bf25577f9c314bd0af0100e9c492c3..2e9b2d9a550c5be5a90c3230552a6003d504e1a3 100644 (file)
@@ -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;