All of lore.kernel.org
 help / color / mirror / Atom feed
From: Filippo Negroni <fnegroni@flexerasoftware.com>
To: git@vger.kernel.org
Subject: compat/mkdtemp.c: patch for gitmkdtemp() compatibility implementation
Date: Thu, 25 Feb 2010 09:01:12 +0000	[thread overview]
Message-ID: <4B863C58.7010105@flexerasoftware.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1234 bytes --]

Dear all,

I noticed that the current implementation of mkdtemp() in the compat/ directory does not seem to be correct.

gitmkdtemp() is needed for platforms such as Solaris 9 and 10 which do not implement mkdtemp().

The current implementation (compat/mkdtemp.c):

----
char *gitmkdtemp(char *template)
{
        if (!mktemp(template) || mkdir(template, 0700))
                return NULL;
        return template;
}
----

seems to be testing the return value of mktemp incorrectly.

mktemp() always returns the argument 'template', even on failure.

This is an extract from Solaris's mktemp(2) manual page:

RETURN VALUES
     The mktemp() function will  assign  to  template  the  empty
     string if it  cannot create a unique name.

Upon failure, 'template' is set to an empty string, i.e., it's first character is '\0'.

The fixed implementation should read:

----
char *gitmkdtemp(char *template)
{
        if (!*mktemp(template) || mkdir(template, 0700))
                return NULL;
        return template;
}
----

I.e., simply add the pointer dereference operator when calling mktemp().

I have attached a patch against the most current git repo, branch master.

Please let me know if you need the patch in any other way.

[-- Attachment #2: 0001-Fixed-return-value-check-for-mkdtemp-implementation.patch --]
[-- Type: text/plain, Size: 703 bytes --]

>From 00b2a96d93d801d06eb710bc03b3e4804d3583ec Mon Sep 17 00:00:00 2001
From: Filippo Negroni <fnegroni@flexerasoftware.com>
Date: Thu, 25 Feb 2010 08:39:35 +0000
Subject: [PATCH] Fixed return value check for mkdtemp implementation.

mktemp() returns an 'empty' string, not a NULL pointer.
---
 compat/mkdtemp.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

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


             reply	other threads:[~2010-02-25  9:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-25  9:01 Filippo Negroni [this message]
2010-02-25  9:31 ` compat/mkdtemp.c: patch for gitmkdtemp() compatibility implementation Matthieu Moy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4B863C58.7010105@flexerasoftware.com \
    --to=fnegroni@flexerasoftware.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.