This is an automated email from the git hooks/post-receive script.

guillem pushed a commit to branch main
in repository dpkg.

View the commit online:
https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=53e4c9bf2cd57dc2232090bae0062fc39e5ade30

commit 53e4c9bf2cd57dc2232090bae0062fc39e5ade30
Author: Guillem Jover <[email protected]>
AuthorDate: Thu Mar 17 23:05:45 2022 +0100

    libdpkg: Check that executables are regular files
    
    Otherwise we might try to execute other kinds of files, such as
    directories.
---
 lib/dpkg/file.c     | 3 +++
 lib/dpkg/t/t-file.c | 5 +++--
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/lib/dpkg/file.c b/lib/dpkg/file.c
index 85687dbb5..4f7c3aaa2 100644
--- a/lib/dpkg/file.c
+++ b/lib/dpkg/file.c
@@ -49,6 +49,9 @@ file_is_exec(const char *filename)
        if (stat(filename, &st) < 0)
                return false;
 
+       if (!S_ISREG(st.st_mode))
+               return false;
+
        return st.st_mode & 0111;
 }
 
diff --git a/lib/dpkg/t/t-file.c b/lib/dpkg/t/t-file.c
index ae089b25e..ebba306bb 100644
--- a/lib/dpkg/t/t-file.c
+++ b/lib/dpkg/t/t-file.c
@@ -64,7 +64,6 @@ test_file_slurp(void)
        test_error(err);
        varbuf_destroy(&vb);
        test_pass(rmdir(test_dir) == 0);
-       free(test_dir);
 
        test_file = test_alloc(strdup("test.XXXXXX"));
        fd = mkstemp(test_file);
@@ -87,6 +86,7 @@ test_file_slurp(void)
        test_pass(err.type == DPKG_MSG_NONE);
        varbuf_destroy(&vb);
 
+       test_fail(file_is_exec(test_dir));
        test_fail(file_is_exec(test_file));
        test_pass(chmod(test_file, 755) == 0);
        test_pass(file_is_exec(test_file));
@@ -95,11 +95,12 @@ test_file_slurp(void)
 
        test_pass(unlink(test_file) == 0);
        free(test_file);
+       free(test_dir);
 }
 
 TEST_ENTRY(test)
 {
-       test_plan(31);
+       test_plan(32);
 
        test_file_slurp();
 }

-- 
Dpkg.Org's dpkg

Reply via email to