From: Karel Zak Date: Mon, 7 Feb 2022 10:10:03 +0000 (+0100) Subject: misc: use everywhere mkstemp_cloexec() as fallback to mkostemp() X-Git-Tag: v2.38-rc2~44 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=adcd2c322ce4b66f90cf423aad369643d49edd5d;p=thirdparty%2Futil-linux.git misc: use everywhere mkstemp_cloexec() as fallback to mkostemp() 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 --- diff --git a/libfdisk/src/script.c b/libfdisk/src/script.c index 1dfc2c9a8e..d93b98171d 100644 --- a/libfdisk/src/script.c +++ b/libfdisk/src/script.c @@ -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"); diff --git a/libmount/src/utils.c b/libmount/src/utils.c index 2a12f1128a..74815055b0 100644 --- a/libmount/src/utils.c +++ b/libmount/src/utils.c @@ -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); diff --git a/login-utils/last.c b/login-utils/last.c index 845cbdb618..c7aec4c116 100644 --- a/login-utils/last.c +++ b/login-utils/last.c @@ -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");