]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
nspawn: use the return value from asprintf instead of checking the pointer 4510/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 23 Oct 2016 15:57:55 +0000 (11:57 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 23 Oct 2016 15:57:55 +0000 (11:57 -0400)
If allocation fails, the value of the point is "undefined". In practice
this matters very little, but for consistency with rest of the code,
let's check the return value.

src/nspawn/nspawn-mount.c

index 9a03f4b0bdbbef3999c453679618e4cf45e7c75e..2cad84b5a14302938071746a9809c411650cf7ea 100644 (file)
@@ -193,11 +193,9 @@ static int tmpfs_patch_options(
         if ((userns && uid_shift != 0) || patch_ids) {
                 assert(uid_shift != UID_INVALID);
 
-                if (options)
-                        (void) asprintf(&buf, "%s,uid=" UID_FMT ",gid=" UID_FMT, options, uid_shift, uid_shift);
-                else
-                        (void) asprintf(&buf, "uid=" UID_FMT ",gid=" UID_FMT, uid_shift, uid_shift);
-                if (!buf)
+                if (asprintf(&buf, "%s%suid=" UID_FMT ",gid=" UID_FMT,
+                             options ?: "", options ? "," : "",
+                             uid_shift, uid_shift) < 0)
                         return -ENOMEM;
 
                 options = buf;
@@ -207,16 +205,12 @@ static int tmpfs_patch_options(
         if (selinux_apifs_context) {
                 char *t;
 
-                if (options)
-                        t = strjoin(options, ",context=\"", selinux_apifs_context, "\"");
-                else
-                        t = strjoin("context=\"", selinux_apifs_context, "\"");
-                if (!t) {
-                        free(buf);
+                t = strjoin(options ?: "", options ? "," : "",
+                            "context=\"", selinux_apifs_context, "\"");
+                free(buf);
+                if (!t)
                         return -ENOMEM;
-                }
 
-                free(buf);
                 buf = t;
         }
 #endif