]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
misc: use everywhere mkstemp_cloexec() as fallback to mkostemp()
authorKarel Zak <kzak@redhat.com>
Mon, 7 Feb 2022 10:10:03 +0000 (11:10 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 7 Feb 2022 10:10:03 +0000 (11:10 +0100)
The function mkostemp() does not have to be available everywhere,
and for this reason, we have mkstemp_cloexec() as a fallback solution.
Unfortunately, some codes (usually fuzzy tests) do not use the
fallback. Let's fix it.

Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/script.c
libmount/src/utils.c
login-utils/last.c

index 1dfc2c9a8e29f181efe76e7cc81a64f4d73c84aa..d93b98171d4a38dc5cbfc60d6bb4672c386adf9a 100644 (file)
@@ -4,6 +4,7 @@
 #include "carefulputc.h"
 #include "mangle.h"
 #include "jsonwrt.h"
+#include "fileutils.h"
 
 #ifdef FUZZ_TARGET
 #include "fuzz.h"
@@ -1574,9 +1575,9 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
        struct fdisk_context *cxt;
        FILE *f;
 
-       fd = mkostemp(name, O_RDWR|O_CREAT|O_EXCL|O_CLOEXEC);
+       fd = mkstemp_cloexec(name);
        if (fd < 0)
-               err(EXIT_FAILURE, "mkostemp() failed");
+               err(EXIT_FAILURE, "mkstemp() failed");
        if (write_all(fd, data, size) != 0)
                err(EXIT_FAILURE, "write() failed");
        f = fopen(name, "r");
index 2a12f1128a29f693180f4e87700f6e053c968754..74815055b02b6b77da50d3a9702dfef15a0bdf4d 100644 (file)
@@ -890,7 +890,8 @@ int mnt_open_uniq_filename(const char *filename, char **name)
         */
        oldmode = umask(S_IRGRP|S_IWGRP|S_IXGRP|
                        S_IROTH|S_IWOTH|S_IXOTH);
-       fd = mkostemp(n, O_RDWR|O_CREAT|O_EXCL|O_CLOEXEC);
+
+       fd = mkstemp_cloexec(n);
        if (fd < 0)
                fd = -errno;
        umask(oldmode);
index 845cbdb618e9bbe306fbd71710c42d3ff33c8378..c7aec4c116f19c9e6ef8c98b4c82a6620300a80a 100644 (file)
@@ -52,6 +52,7 @@
 #include "strutils.h"
 #include "timeutils.h"
 #include "monotonic.h"
+#include "fileutils.h"
 
 #ifdef FUZZ_TARGET
 #include "fuzz.h"
@@ -939,9 +940,9 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
        char name[] = "/tmp/test-last-fuzz.XXXXXX";
        int fd;
 
-       fd = mkostemp(name, O_RDWR|O_CREAT|O_EXCL|O_CLOEXEC);
+       fd = mkstemp_cloexec(name);
        if (fd < 0)
-               err(EXIT_FAILURE, "mkostemp() failed");
+               err(EXIT_FAILURE, "mkstemp() failed");
        if (write_all(fd, data, size) != 0)
                err(EXIT_FAILURE, "write() failed");