]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
dissect-image: fix fd leak in dissected_image_acquire_metadata()
authorLennart Poettering <lennart@poettering.net>
Mon, 4 Dec 2023 17:21:23 +0000 (18:21 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 12 Dec 2023 15:19:50 +0000 (16:19 +0100)
We have to go through the "finish" label to properly close all pipes in
the error path, so that we don't leak them.

src/shared/dissect-image.c

index 65f5e786b5693dcfea0eac778b84a9ad6ce4fd42..62aca296f617fdebb61aa8d3c26a3955986e0a51 100644 (file)
@@ -3629,18 +3629,25 @@ int dissected_image_acquire_metadata(DissectedImage *m, DissectImageFlags extra_
         r = wait_for_terminate_and_check("(sd-dissect)", child, 0);
         child = 0;
         if (r < 0)
-                return r;
+                goto finish;
 
         n = read(error_pipe[0], &v, sizeof(v));
-        if (n < 0)
-                return -errno;
-        if (n == sizeof(v))
-                return v; /* propagate error sent to us from child */
-        if (n != 0)
-                return -EIO;
-
-        if (r != EXIT_SUCCESS)
-                return -EPROTO;
+        if (n < 0) {
+                r = -errno;
+                goto finish;
+        }
+        if (n == sizeof(v)) {
+                r = v; /* propagate error sent to us from child */
+                goto finish;
+        }
+        if (n != 0) {
+                r = -EIO;
+                goto finish;
+        }
+        if (r != EXIT_SUCCESS) {
+                r = -EPROTO;
+                goto finish;
+        }
 
         free_and_replace(m->hostname, hostname);
         m->machine_id = machine_id;