threads / patch / 22818

patchFix gitmkdtemp: correct test for mktemp() return value

Subject: [PATCH] Fix gitmkdtemp: correct test for mktemp() return value

## tl;dr

3 messages between Feb 25, 2010 and Feb 25, 2010. Diffs are folded; open one to read it.

replies: 2people: 3as markdown or json

Filippo Negroni· Feb 25, 2010, 10:01 UTC · lore
>From 5e3b362cdd86150de901312c01beac9596b7e2ba Mon Sep 17 00:00:00 2001
From: Filippo Negroni <fnegroni@flexerasoftware.com>
Date: Thu, 25 Feb 2010 09:39:56 +0000
Subject: [PATCH] Fix gitmkdtemp: correct test for mktemp() return value

In gitmkdtemp, the return value of mktemp is not tested correctly. mktemp() always returns its 'template' argument, even upon failre. Upon failure, mktemp sets template to be an empty string: its first character is '\0'. This patch ensures the return value of mktemp is correctly tested by dereferencing the pointer returned by it.

Signed-off-by: Filippo Negroni <fnegroni@flexerasoftware.com>
---
 compat/mkdtemp.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Show changes to compat/mkdtemp.c +1 −1
diff --git a/compat/mkdtemp.c b/compat/mkdtemp.c
index 34d4b49..1136119 100644
--- a/compat/mkdtemp.c
+++ b/compat/mkdtemp.c
@@ -2,7 +2,7 @@
 
 char *gitmkdtemp(char *template)
 {
-       if (!mktemp(template) || mkdir(template, 0700))
+       if (!*mktemp(template) || mkdir(template, 0700))
                return NULL;
        return template;
 }
-- 
1.6.4
Junio C Hamano· Feb 25, 2010, 17:33 UTC · re: Filippo Negroni · lore

Re: [PATCH] Fix gitmkdtemp: correct test for mktemp() return value

Filippo Negroni <fnegroni@flexerasoftware.com> writes:
Show 12 quoted lines
> From 5e3b362cdd86150de901312c01beac9596b7e2ba Mon Sep 17 00:00:00 2001
> From: Filippo Negroni <fnegroni@flexerasoftware.com>
> Date: Thu, 25 Feb 2010 09:39:56 +0000
> Subject: [PATCH] Fix gitmkdtemp: correct test for mktemp() return value
>
> In gitmkdtemp, the return value of mktemp is not tested correctly.
> mktemp() always returns its 'template' argument, even upon failre.
> Upon failure, mktemp sets template to be an empty string: its first character is '\0'.
> This patch ensures the return value of mktemp is correctly tested by dereferencing the pointer returned by it.
>
> Signed-off-by: Filippo Negroni <fnegroni@flexerasoftware.com>
> ---
Thanks.

Next time please do not quote the mbox header lines (i.e. start your body with "In gitmkdtemp, the return value ...".

Matthieu Moy· Feb 25, 2010, 18:05 UTC · re: Junio C Hamano · lore

Re: [PATCH] Fix gitmkdtemp: correct test for mktemp() return value

Junio C Hamano <gitster@pobox.com> writes:
> Next time please do not quote the mbox header lines (i.e. start your body
> with "In gitmkdtemp, the return value ...".
... or just use "git send-email", which does the trick for you.
-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

← back to recent threads