]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
portable: do not extract empty unit files
authorLuca Boccassi <bluca@debian.org>
Mon, 12 Jun 2023 22:47:03 +0000 (23:47 +0100)
committerLuca Boccassi <bluca@debian.org>
Mon, 12 Jun 2023 23:33:21 +0000 (00:33 +0100)
Bare minimum sanity check, an empty unit is an invalid unit so
skip it early.

src/portable/portable.c

index 1c31377567812812fb1026938fe306653ad64b2b..6b3fd004407fba71de7fd0215854ba9fb7d27658 100644 (file)
@@ -255,6 +255,7 @@ static int extract_now(
                         _cleanup_(portable_metadata_unrefp) PortableMetadata *m = NULL;
                         _cleanup_(mac_selinux_freep) char *con = NULL;
                         _cleanup_close_ int fd = -EBADF;
+                        struct stat st;
 
                         if (!unit_name_is_valid(de->d_name, UNIT_NAME_ANY))
                                 continue;
@@ -275,6 +276,17 @@ static int extract_now(
                                 continue;
                         }
 
+                        /* Reject empty files, just in case */
+                        if (fstat(fd, &st) < 0) {
+                                log_debug_errno(errno, "Failed to stat unit file '%s', ignoring: %m", de->d_name);
+                                continue;
+                        }
+
+                        if (st.st_size <= 0) {
+                                log_debug("Unit file '%s' is empty, ignoring.", de->d_name);
+                                continue;
+                        }
+
 #if HAVE_SELINUX
                         /* The units will be copied on the host's filesystem, so if they had a SELinux label
                          * we have to preserve it. Copy it out so that it can be applied later. */