]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fs-util: always go through the unlink cleanup paths in xopenat_full()
authorLennart Poettering <lennart@poettering.net>
Mon, 21 Oct 2024 19:56:05 +0000 (21:56 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 22 Oct 2024 15:45:41 +0000 (17:45 +0200)
We didn't go through it at all if label_ops_post() failed.

src/basic/fs-util.c

index 5994ebd4035ce6b9cd629a2822c02407b7ffa966..bbf2fea3e62753992c36ff48f39c6f28f838a5b4 100644 (file)
@@ -1186,7 +1186,7 @@ int xopenat_full(int dir_fd, const char *path, int open_flags, XOpenFlags xopen_
                 if (FLAGS_SET(xopen_flags, XO_LABEL)) {
                         r = label_ops_post(dir_fd, path);
                         if (r < 0)
-                                return r;
+                                goto error;
                 }
 
                 open_flags &= ~(O_EXCL|O_CREAT);
@@ -1206,10 +1206,8 @@ int xopenat_full(int dir_fd, const char *path, int open_flags, XOpenFlags xopen_
                            -ENOTDIR))
                         return fd;
 
-                if (made_dir)
-                        (void) unlinkat(dir_fd, path, AT_REMOVEDIR);
-
-                return fd;
+                r = fd;
+                goto error;
         }
 
         if (FLAGS_SET(open_flags, O_CREAT) && FLAGS_SET(xopen_flags, XO_LABEL)) {