ban mktemp(3)
Subsystems (2)
cover ban mktemp(3)
mktemp(3) is insecure and POSIX.1-2008 no longer specifies it. Stop using it.
wrapper: add git_mkdtemp()
compat: use git_mkdtemp()
compat: remove mingw_mktemp()
banned.h: ban mktemp(3)
banned.h | 3 +++ compat/mingw-posix.h | 3 --- compat/mingw.c | 12 ------------ compat/mkdtemp.c | 4 +--- wrapper.c | 17 +++++++++++++++-- wrapper.h | 2 ++ 6 files changed, 21 insertions(+), 20 deletions(-)
Signature · 1 line
2.52.0
PATCH 1/4 wrapper: add git_mkdtemp()
Extend git_mkstemps_mode() to optionally call mkdir(2) instead of open(2), then use that ability to create a mkdtemp(3) replacement, git_mkdtemp(). We'll start using it in the next commit.
--- wrapper.c | 17 +++++++++++++++-- wrapper.h | 2 ++ 2 files changed, 17 insertions(+), 2 deletions(-)
wrapper.c +15 -2
@@ -429,7 +429,7 @@ int xmkstemp(char *filename_template)#undef TMP_MAX#define TMP_MAX 16384 -int git_mkstemps_mode (char *pattern,int suffix_len,int mode) +static int git_mkdstemps_mode (char *pattern,int suffix_len,int mode,bool dir) {static const char letters[] ="abcdefghijklmnopqrstuvwxyz"
@@ -471,7 +471,10 @@ int git_mkstemps_mode(char *pattern, int suffix_len, int mode) v /= num_letters; } - fd =open (pattern,O_CREAT |O_EXCL |O_RDWR , mode); +if (dir) + fd =mkdir (pattern, mode); +else + fd =open (pattern,O_CREAT |O_EXCL |O_RDWR , mode);if (fd >=0 )return fd;/*
@@ -486,6 +489,16 @@ int git_mkstemps_mode(char *pattern, int suffix_len, int mode)return -1 ; } +char *git_mkdtemp (char *pattern) +{ +return git_mkdstemps_mode (pattern,0 ,0700 , true) ?NULL : pattern; +} + +int git_mkstemps_mode (char *pattern,int suffix_len,int mode) +{ +return git_mkdstemps_mode (pattern, suffix_len, mode, false); +} +int git_mkstemp_mode (char *pattern,int mode) {/* mkstemp is just mkstemps with no suffix */
wrapper.h +2 -0
@@ -37,6 +37,8 @@ int xsnprintf(char *dst, size_t max, const char *fmt, ...);int xgethostname (char *buf,size_t len); +char *git_mkdtemp (char *pattern); +/* set default permissions by passing mode arguments to open(2) */ int git_mkstemps_mode (char *pattern,int suffix_len,int mode);int git_mkstemp_mode (char *pattern,int mode);
Signature · 1 line
2.52.0
Re: [PATCH 1/4] wrapper: add git_mkdtemp()
fairly trivial, but:
Quoted 3 lines · René Scharfe
Extend
git_mkstemps_mode()to optionally call mkdir(2) instead of open(2), then use that ability to create a mkdtemp(3) replacement,git_mkdtemp(). We'll start using it in the next commit.
[snip]
wrapper.c int git_mkstemps_mode(char *pattern, int suffix_len, int mode) · line 477
Quoted 5 lines
wrapper.c +4
-1- fd =open (pattern,O_CREAT |O_EXCL |O_RDWR , mode); +if (dir) + fd =mkdir (pattern, mode); +else + fd =open (pattern,O_CREAT |O_EXCL |O_RDWR , mode);
mkdir() returns a success (0) / fail (-1) indication, rather than a file descriptor, so this is kind of misleading. I think a comment mentioning it would suffice (but also be a good idea, lest someone later think it needs a close() call).
Chris
Re: [PATCH 1/4] wrapper: add git_mkdtemp()
In reply to René Scharfewrapper.c int xmkstemp(char *filename_template) · line 432
Quoted 2 lines · René Scharfe
wrapper.c +1
-1-int git_mkstemps_mode (char *pattern,int suffix_len,int mode) +static int git_mkdstemps_mode (char *pattern,int suffix_len,int mode,bool dir)
This is a file-scope static, so as long as it is understood by those who futz with things in this file well, there is no need to go extra mile to avoid confusion, but the meaning of the returned value from this function is vastly different depending on the value of "dir". It used to be that you can subject it to write(2), but obviously that is not relevant when you called mkdir(2) here.
wrapper.c int git_mkstemps_mode(char *pattern, int suffix_len, int mode) · line 475
Quoted 10 lines
{
wrapper.c +2
-1static const char letters[] ="abcdefghijklmnopqrstuvwxyz" @@ -471,7 +471,10 @@ int git_mkstemps_mode(char *pattern, int suffix_len, int mode) v /= num_letters; } - fd =open (pattern,O_CREAT |O_EXCL |O_RDWR , mode); +if (dir) + fd =mkdir (pattern, mode);
OK. The caller calls this helper with 0700 (S_IRWXU), so that's probably OK. If we can make this into two helper functions with distinct function signatures that share the majority of logic, it would have been much nicer, but short of introducing a callback function I do not think of a good way, so I'll let it pass.
Quoted 4 lines
wrapper.c +2
-0+else + fd =open (pattern,O_CREAT |O_EXCL |O_RDWR , mode);if (fd >=0 )return fd;
PATCH 2/4 compat: use git_mkdtemp()
In reply to René ScharfeA file might appear at the path returned by mktemp(3) before we call mkdir(2). Use the more robust git_mkdtemp() instead, which retries a number of times and doesn't need to call lstat(2).
--- compat/mkdtemp.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
compat/mkdtemp.c +1 -3
@@ -2,7 +2,5 @@char *gitmkdtemp (char *template) { -if (!*mktemp (template) ||mkdir (template,0700 )) -return NULL ; -return template; +return git_mkdtemp (template); }
Signature · 1 line
2.52.0
Re: [PATCH 2/4] compat: use git_mkdtemp()
Quoted 3 lines · René Scharfe
A file might appear at the path returned by mktemp(3) before we call mkdir(2). Use the more robust
git_mkdtemp()instead, which retries a number of times and doesn't need to call lstat(2).
This seems like a good idea. At least one of the mkdtemp() callers was using $TMPDIR, so this was a potential security-sensitive race.
compat/mkdtemp.c line 6
Quoted 13 lines
compat/mkdtemp.c +1
-3@@ -2,7 +2,5 @@char *gitmkdtemp (char *template) { -if (!*mktemp (template) ||mkdir (template,0700 )) -return NULL ; -return template; +return git_mkdtemp (template); }
OK, so now we have gitmkdtemp() and git_mkdtemp(), which are also now the exact same thing. That seems overly complicated. ;)
This one is a conditionally-compiled wrapper for NO_MKDTEMP. But since we always have git_mkdtemp() available (as of your first patch), can't we just point at it directly with the macro?
Like this:
Makefile +0 -1
@@ -1919,7 +1919,6 @@ ifdef NO_SETENV endif ifdef NO_MKDTEMP COMPAT_CFLAGS += -DNO_MKDTEMP - COMPAT_OBJS += compat/mkdtemp.o endif ifdef MKDIR_WO_TRAILING_SLASH COMPAT_CFLAGS += -DMKDIR_WO_TRAILING_SLASH
compat/mkdtemp.c deleted +0 -6
@@ -1,6 +0,0 @@ -#include "../git-compat-util.h" - -char *gitmkdtemp (char *template) -{ -return git_mkdtemp (template); -}
compat/posix.h +1 -2
@@ -329,8 +329,7 @@ int gitsetenv(const char *, const char *, int);#endif #ifdef NO_MKDTEMP -#define mkdtemp gitmkdtemp -char *gitmkdtemp (char *); +#define mkdtemp git_mkdtemp#endif #ifdef NO_UNSETENV
meson.build +0 -1
@@ -1401,7 +1401,6 @@ checkfuncs = { 'strlcpy' : ['strlcpy.c'], 'strtoull' : [], 'setenv' : ['setenv.c'], - 'mkdtemp' : ['mkdtemp.c'], 'initgroups' : [], 'strtoumax' : ['strtoumax.c', 'strtoimax.c'], 'pread' : ['pread.c'],
We could even take it a step further and just always use git_mkdtemp(), like we were discussing elsewhere for mkstemp(). And then the makefile knobs can go away, too, like:
Makefile +0 -2
@@ -68,8 +68,6 @@ include shared.mak # # Define NO_UNSETENV if you don't have unsetenv in the C library. # -# Define NO_MKDTEMP if you don't have mkdtemp in the C library. -# # Define MKDIR_WO_TRAILING_SLASH if your mkdir() can't deal with trailing slash. # # Define NO_GECOS_IN_PWENT if you don't have pw_gecos in struct passwd
compat/posix.h +0 -2
@@ -328,9 +328,7 @@ ssize_t git_pread(int fd, void *buf, size_t count, off_t offset);int gitsetenv (const char *,const char *,int );#endif -#ifdef NO_MKDTEMP #define mkdtemp git_mkdtemp -#endif #ifdef NO_UNSETENV #define unsetenv gitunsetenv
configure.ac +0 -6
@@ -1140,12 +1140,6 @@ GIT_CHECK_FUNC(unsetenv, [NO_UNSETENV=YesPlease]) GIT_CONF_SUBST([NO_UNSETENV]) # -# Define NO_MKDTEMP if you don't have mkdtemp in the C library. -GIT_CHECK_FUNC(mkdtemp, -[NO_MKDTEMP=], -[NO_MKDTEMP=YesPlease]) -GIT_CONF_SUBST([NO_MKDTEMP]) -# # Define NO_INITGROUPS if you don't have initgroups in the C library. GIT_CHECK_FUNC(initgroups, [NO_INITGROUPS=],
contrib/buildsystems/CMakeLists.txt +1 -5
@@ -374,7 +374,7 @@ endif() #function checks set(function_checks strcasestr memmem strlcpy strtoimax strtoumax strtoull - setenv mkdtemp poll pread memmem) + setenv poll pread memmem) #unsetenv,hstrerror are incompatible with windows build if(NOT WIN32)
@@ -411,10 +411,6 @@ if(NOT HAVE_SETENV) list(APPEND compat_SOURCES compat/setenv.c) endif() -if(NOT HAVE_MKDTEMP) - list(APPEND compat_SOURCES compat/mkdtemp.c) -endif() - if(NOT HAVE_PREAD) list(APPEND compat_SOURCES compat/pread.c) endif()
-Peff
Re: [PATCH 2/4] compat: use git_mkdtemp()
Quoted 26 lines · Jeff King
Quoted 3 lines · René Scharfe
A file might appear at the path returned by mktemp(3) before we call mkdir(2). Use the more robust
git_mkdtemp()instead, which retries a number of times and doesn't need to call lstat(2).This seems like a good idea. At least one of the
mkdtemp()callers was using $TMPDIR, so this was a potential security-sensitive race.compat/mkdtemp.c line 6
Quoted 13 lines
compat/mkdtemp.c +1
-3@@ -2,7 +2,5 @@char *gitmkdtemp (char *template) { -if (!*mktemp (template) ||mkdir (template,0700 )) -return NULL ; -return template; +return git_mkdtemp (template); }OK, so now we have
gitmkdtemp()andgit_mkdtemp(), which are also now the exact same thing. That seems overly complicated. ;)
Quoted 3 lines
This one is a conditionally-compiled wrapper for
NO_MKDTEMP. But since we always havegit_mkdtemp()available (as of your first patch), can't we just point at it directly with the macro?
A worthwhile cleanup if we stop at this point, but complicated by targeting three build systems, the CMake build being broken on macOS and me only knowing how to fake NO_MKDEMP for make, leaving half the build space untestable for me.
Quoted 45 lines
Like this:
Makefile +0
-1@@ -1919,7 +1919,6 @@ ifdef NO_SETENV endif ifdef NO_MKDTEMP COMPAT_CFLAGS += -DNO_MKDTEMP - COMPAT_OBJS += compat/mkdtemp.o endif ifdef MKDIR_WO_TRAILING_SLASH COMPAT_CFLAGS += -DMKDIR_WO_TRAILING_SLASHcompat/mkdtemp.c deleted +0
-6@@ -1,6 +0,0 @@ -#include "../git-compat-util.h" - -char *gitmkdtemp (char *template) -{ -return git_mkdtemp (template); -}compat/posix.h +1
-2@@ -329,8 +329,7 @@ int gitsetenv(const char *, const char *, int);#endif #ifdef NO_MKDTEMP -#define mkdtemp gitmkdtemp -char *gitmkdtemp (char *); +#define mkdtemp git_mkdtemp#endif #ifdef NO_UNSETENV meson.build +0
-0
meson.build checkfuncs = { · line 1406
Quoted 7 lines
meson.build +0
-1@@ -1401,7 +1401,6 @@ checkfuncs = { 'strlcpy' : ['strlcpy.c'], 'strtoull' : [], 'setenv' : ['setenv.c'], - 'mkdtemp' : ['mkdtemp.c'], 'initgroups' : [], 'strtoumax' : ['strtoumax.c', 'strtoimax.c'], 'pread' : ['pread.c'],
We need to keep that dictionary entry to still define NO_MKDTEMP, and just empty the array of filenames.
contrib/buildsystems/CMakeLists.txt needs to be updated as well, like you do below (keep in function_checks, remove from compat_SOURCES).
At the very least this cleanup should be done in a separated patch, as it's harder than it looks.
Quoted 62 lines
We could even take it a step further and just always use
git_mkdtemp(), like we were discussing elsewhere formkstemp(). And then the makefile knobs can go away, too, like:Makefile +0
-2@@ -68,8 +68,6 @@ include shared.mak # # Define NO_UNSETENV if you don't have unsetenv in the C library. # -# Define NO_MKDTEMP if you don't have mkdtemp in the C library. -# # Define MKDIR_WO_TRAILING_SLASH if your mkdir() can't deal with trailing slash. # # Define NO_GECOS_IN_PWENT if you don't have pw_gecos in struct passwdcompat/posix.h +0
-2@@ -328,9 +328,7 @@ ssize_t git_pread(int fd, void *buf, size_t count, off_t offset);int gitsetenv (const char *,const char *,int );#endif -#ifdef NO_MKDTEMP #define mkdtemp git_mkdtemp -#endif #ifdef NO_UNSETENV #define unsetenv gitunsetenvconfigure.ac +0
-6@@ -1140,12 +1140,6 @@ GIT_CHECK_FUNC(unsetenv, [NO_UNSETENV=YesPlease]) GIT_CONF_SUBST([NO_UNSETENV]) # -# Define NO_MKDTEMP if you don't have mkdtemp in the C library. -GIT_CHECK_FUNC(mkdtemp, -[NO_MKDTEMP=], -[NO_MKDTEMP=YesPlease]) -GIT_CONF_SUBST([NO_MKDTEMP]) -# # Define NO_INITGROUPS if you don't have initgroups in the C library. GIT_CHECK_FUNC(initgroups, [NO_INITGROUPS=],contrib/buildsystems/CMakeLists.txt +1
-1@@ -374,7 +374,7 @@ endif() #function checks set(function_checks strcasestr memmem strlcpy strtoimax strtoumax strtoull - setenv mkdtemp poll pread memmem) + setenv poll pread memmem) #unsetenv,hstrerror are incompatible with windows build if(NOT WIN32)
contrib/buildsystems/CMakeLists.txt if(NOT HAVE_SETENV) · line 416
Quoted 10 lines
contrib/buildsystems/CMakeLists.txt +0
-4@@ -411,10 +411,6 @@ if(NOT HAVE_SETENV) list(APPEND compat_SOURCES compat/setenv.c) endif() -if(NOT HAVE_MKDTEMP) - list(APPEND compat_SOURCES compat/mkdtemp.c) -endif() - if(NOT HAVE_PREAD) list(APPEND compat_SOURCES compat/pread.c) endif()
Right. Dropping this dependency and then deep cleaning the compat code is attractive and mostly sidesteps the build system complications. That's for a later series.
Ultimately you'd prefer banning mkdtemp(3) instead of automatically redirecting to git_mkdtemp(), though, no?
René
Re: [PATCH 2/4] compat: use git_mkdtemp()
Quoted 11 lines · René Scharfe
Quoted 3 lines
This one is a conditionally-compiled wrapper for
NO_MKDTEMP. But since we always havegit_mkdtemp()available (as of your first patch), can't we just point at it directly with the macro?A worthwhile cleanup if we stop at this point, but complicated by targeting three build systems, the CMake build being broken on macOS and me only knowing how to fake
NO_MKDEMPfor make, leaving half the build space untestable for me.
[...]
At the very least this cleanup should be done in a separated patch, as it's harder than it looks.
OK, I am convinced that it is not entirely trivial and can go in a separate patch. :) Mostly I was surprised that you would not have followed through on an obvious cleanup opportunity. It just turned out harder than I expected.
Quoted 3 lines
Right. Dropping this dependency and then deep cleaning the compat code is attractive and mostly sidesteps the build system complications. That's for a later series.
Yup. Sounds reasonable.
Quoted 2 lines
Ultimately you'd prefer banning mkdtemp(3) instead of automatically redirecting to
git_mkdtemp(), though, no?
I'm OK either way. Whatever we end up doing for mkstemp(), I think we should match here.
I do like being explicit that we are using our own wrapper and not the system function. But I wonder if it might make complications in third-party code like clar, which calls mkdtemp(). If we don't have a compat macro we'll have to patch the sources that we import into t/unit-tests/clar.
So maybe that is an argument that we should leave the "#define mkdtemp" in place.
-Peff
Re: [PATCH 2/4] compat: use git_mkdtemp()
In reply to Jeff KingQuoted 3 lines · Jeff King
This one is a conditionally-compiled wrapper for
NO_MKDTEMP. But since we always havegit_mkdtemp()available (as of your first patch), can't we just point at it directly with the macro?
Yup, that is much nicer.
PATCH 3/4 compat: remove mingw_mktemp()
In reply to René ScharfeRemove the mktemp(3) compatibility function now that its last caller was removed by the previous commit.
--- compat/mingw-posix.h | 3 --- compat/mingw.c | 12 ------------ 2 files changed, 15 deletions(-)
compat/mingw-posix.h +0 -3
@@ -241,9 +241,6 @@ int mingw_chdir(const char *dirname);int mingw_chmod (const char *filename,int mode);#define chmod mingw_chmod -char *mingw_mktemp (char *template); -#define mktemp mingw_mktemp -char *mingw_getcwd (char *pointer,int len);#define getcwd mingw_getcwd
compat/mingw.c +0 -12
@@ -1164,18 +1164,6 @@ unsigned int sleep (unsigned int seconds)return 0 ; } -char *mingw_mktemp (char *template) -{ -wchar_t wtemplate[MAX_PATH ]; -if (xutftowcs_path (wtemplate, template) <0 ) -return NULL ; -if (!_wmktemp (wtemplate)) -return NULL ; -if (xwcstoutf (template, wtemplate,strlen (template) +1 ) <0 ) -return NULL ; -return template; -} -int mkstemp (char *template) {return git_mkstemp_mode (template,0600 );
Signature · 1 line
2.52.0
PATCH 4/4 banned.h: ban mktemp(3)
In reply to René ScharfeOlder versions of mktemp(3) generate easily guessable file names. The function checks if the generated name is used, which is unreliable, as a file with that name might then be created by some other process before we can do it ourselves. The function was dropped from POSIX due to its security problems. Forbid its use.
--- banned.h | 3 +++ 1 file changed, 3 insertions(+)
banned.h +3 -0
@@ -41,4 +41,7 @@#undef asctime_r#define asctime_r (t, buf) BANNED(asctime_r) +#undef mktemp +#define mktemp (x) BANNED(mktemp) +#endif /* BANNED_H */
Signature · 1 line
2.52.0
Re: [PATCH 4/4] banned.h: ban mktemp(3)
Quoted 5 lines · René Scharfe
Older versions of mktemp(3) generate easily guessable file names. The function checks if the generated name is used, which is unreliable, as a file with that name might then be created by some other process before we can do it ourselves. The function was dropped from POSIX due to its security problems. Forbid its use.
Great. I am happy to see this.
-Peff
v2 cover ban mktemp(3)
In reply to René Scharfemktemp(3) is insecure and POSIX.1-2008 no longer specifies it. Stop using it.
Changes since v1:
- add comment regarding return values of git_mkdstemps_mode()
- add patch to drop trivialized gitmkdtemp()
wrapper: add git_mkdtemp()
compat: use git_mkdtemp()
compat: remove mingw_mktemp()
banned.h: ban mktemp(3)
compat: remove gitmkdtemp()
Makefile | 1 - banned.h | 3 +++ compat/mingw-posix.h | 3 --- compat/mingw.c | 12 ------------ compat/mkdtemp.c | 8 -------- compat/posix.h | 3 +-- contrib/buildsystems/CMakeLists.txt | 4 ---- meson.build | 2 +- wrapper.c | 21 +++++++++++++++++++-- wrapper.h | 2 ++ 10 files changed, 26 insertions(+), 33 deletions(-) delete mode 100644 compat/mkdtemp.c
Range-diff against v1:
1: 830e6375aa ! 1: 413131caf6 wrapper: add git_mkdtemp()
@@ wrapper.c: int xmkstemp(char *filename_template)
#define TMP_MAX 16384
-int git_mkstemps_mode(char *pattern, int suffix_len, int mode)
++/*
++ * Returns -1 on error, 0 if it created a directory, or an open file ++ * descriptor to the created regular file.
++ */
+static int git_mkdstemps_mode(char *pattern, int suffix_len, int mode, bool dir)
{
static const char letters[] =
2: 889903eaa2 = 2: f8850b2a92 compat: use git_mkdtemp() 3: 255b97254f = 3: 6986b4b6bf compat: remove mingw_mktemp() 4: 8300d2e224 = 4: f34252f411 banned.h: ban mktemp(3) -: ---------- > 5: d106855a23 compat: remove gitmkdtemp()
Signature · 1 line
2.52.0
PATCH v2 1/5 wrapper: add git_mkdtemp()
Extend git_mkstemps_mode() to optionally call mkdir(2) instead of open(2), then use that ability to create a mkdtemp(3) replacement, git_mkdtemp(). We'll start using it in the next commit.
--- wrapper.c | 21 +++++++++++++++++++-- wrapper.h | 2 ++ 2 files changed, 21 insertions(+), 2 deletions(-)
wrapper.c +19 -2
@@ -429,7 +429,11 @@ int xmkstemp(char *filename_template)#undef TMP_MAX#define TMP_MAX 16384 -int git_mkstemps_mode (char *pattern,int suffix_len,int mode) +/* +* Returns -1 on error, 0 if it created a directory, or an open file +* descriptor to the created regular file. +*/ +static int git_mkdstemps_mode (char *pattern,int suffix_len,int mode,bool dir) {static const char letters[] ="abcdefghijklmnopqrstuvwxyz"
@@ -471,7 +475,10 @@ int git_mkstemps_mode(char *pattern, int suffix_len, int mode) v /= num_letters; } - fd =open (pattern,O_CREAT |O_EXCL |O_RDWR , mode); +if (dir) + fd =mkdir (pattern, mode); +else + fd =open (pattern,O_CREAT |O_EXCL |O_RDWR , mode);if (fd >=0 )return fd;/*
@@ -486,6 +493,16 @@ int git_mkstemps_mode(char *pattern, int suffix_len, int mode)return -1 ; } +char *git_mkdtemp (char *pattern) +{ +return git_mkdstemps_mode (pattern,0 ,0700 , true) ?NULL : pattern; +} + +int git_mkstemps_mode (char *pattern,int suffix_len,int mode) +{ +return git_mkdstemps_mode (pattern, suffix_len, mode, false); +} +int git_mkstemp_mode (char *pattern,int mode) {/* mkstemp is just mkstemps with no suffix */
wrapper.h +2 -0
@@ -37,6 +37,8 @@ int xsnprintf(char *dst, size_t max, const char *fmt, ...);int xgethostname (char *buf,size_t len); +char *git_mkdtemp (char *pattern); +/* set default permissions by passing mode arguments to open(2) */ int git_mkstemps_mode (char *pattern,int suffix_len,int mode);int git_mkstemp_mode (char *pattern,int mode);
Signature · 1 line
2.52.0
PATCH v2 2/5 compat: use git_mkdtemp()
In reply to René ScharfeA file might appear at the path returned by mktemp(3) before we call mkdir(2). Use the more robust git_mkdtemp() instead, which retries a number of times and doesn't need to call lstat(2).
--- compat/mkdtemp.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
compat/mkdtemp.c +1 -3
@@ -2,7 +2,5 @@char *gitmkdtemp (char *template) { -if (!*mktemp (template) ||mkdir (template,0700 )) -return NULL ; -return template; +return git_mkdtemp (template); }
Signature · 1 line
2.52.0
PATCH v2 3/5 compat: remove mingw_mktemp()
In reply to René ScharfeRemove the mktemp(3) compatibility function now that its last caller was removed by the previous commit.
--- compat/mingw-posix.h | 3 --- compat/mingw.c | 12 ------------ 2 files changed, 15 deletions(-)
compat/mingw-posix.h +0 -3
@@ -241,9 +241,6 @@ int mingw_chdir(const char *dirname);int mingw_chmod (const char *filename,int mode);#define chmod mingw_chmod -char *mingw_mktemp (char *template); -#define mktemp mingw_mktemp -char *mingw_getcwd (char *pointer,int len);#define getcwd mingw_getcwd
compat/mingw.c +0 -12
@@ -1164,18 +1164,6 @@ unsigned int sleep (unsigned int seconds)return 0 ; } -char *mingw_mktemp (char *template) -{ -wchar_t wtemplate[MAX_PATH ]; -if (xutftowcs_path (wtemplate, template) <0 ) -return NULL ; -if (!_wmktemp (wtemplate)) -return NULL ; -if (xwcstoutf (template, wtemplate,strlen (template) +1 ) <0 ) -return NULL ; -return template; -} -int mkstemp (char *template) {return git_mkstemp_mode (template,0600 );
Signature · 1 line
2.52.0
PATCH v2 4/5 banned.h: ban mktemp(3)
In reply to René ScharfeOlder versions of mktemp(3) generate easily guessable file names. The function checks if the generated name is used, which is unreliable, as a file with that name might then be created by some other process before we can do it ourselves. The function was dropped from POSIX due to its security problems. Forbid its use.
--- banned.h | 3 +++ 1 file changed, 3 insertions(+)
banned.h +3 -0
@@ -41,4 +41,7 @@#undef asctime_r#define asctime_r (t, buf) BANNED(asctime_r) +#undef mktemp +#define mktemp (x) BANNED(mktemp) +#endif /* BANNED_H */
Signature · 1 line
2.52.0
PATCH v2 5/5 compat: remove gitmkdtemp()
In reply to René Scharfegitmkdtemp() has become a trivial wrapper around git_mkdtemp(). Remove this now unnecessary layer of indirection.
---
Only tested with make.
Makefile | 1 - compat/mkdtemp.c | 6 ------ compat/posix.h | 3 +-- contrib/buildsystems/CMakeLists.txt | 4 ---- meson.build | 2 +- 5 files changed, 2 insertions(+), 14 deletions(-) delete mode 100644 compat/mkdtemp.c
Makefile +0 -1
@@ -1919,7 +1919,6 @@ ifdef NO_SETENV endif ifdef NO_MKDTEMP COMPAT_CFLAGS += -DNO_MKDTEMP - COMPAT_OBJS += compat/mkdtemp.o endif ifdef MKDIR_WO_TRAILING_SLASH COMPAT_CFLAGS += -DMKDIR_WO_TRAILING_SLASH
compat/mkdtemp.c deleted +0 -6
@@ -1,6 +0,0 @@ -#include "../git-compat-util.h" - -char *gitmkdtemp (char *template) -{ -return git_mkdtemp (template); -}
compat/posix.h +1 -2
@@ -329,8 +329,7 @@ int gitsetenv(const char *, const char *, int);#endif #ifdef NO_MKDTEMP -#define mkdtemp gitmkdtemp -char *gitmkdtemp (char *); +#define mkdtemp git_mkdtemp#endif #ifdef NO_UNSETENV
contrib/buildsystems/CMakeLists.txt +0 -4
@@ -411,10 +411,6 @@ if(NOT HAVE_SETENV) list(APPEND compat_SOURCES compat/setenv.c) endif() -if(NOT HAVE_MKDTEMP) - list(APPEND compat_SOURCES compat/mkdtemp.c) -endif() - if(NOT HAVE_PREAD) list(APPEND compat_SOURCES compat/pread.c) endif()
meson.build +1 -1
@@ -1401,7 +1401,7 @@ checkfuncs = { 'strlcpy' : ['strlcpy.c'], 'strtoull' : [], 'setenv' : ['setenv.c'], - 'mkdtemp' : ['mkdtemp.c'], + 'mkdtemp' : [], 'initgroups' : [], 'strtoumax' : ['strtoumax.c', 'strtoimax.c'], 'pread' : ['pread.c'],
Signature · 1 line
2.52.0
Quoted 6 lines · René Scharfe
mktemp(3) is insecure and POSIX.1-2008 no longer specifies it. Stop using it.
Changes since v1:
- add comment regarding return values ofgit_mkdstemps_mode()
- add patch to drop trivializedgitmkdtemp()
Thanks, this all looks reasonable to me. I don't have a system without mkdtemp() to test the meson change on, but I can confirm it builds on Linux for me using meson. ;)
-Peff