{"thread":{"id":"22817","subject":"compat/mkdtemp.c: patch for gitmkdtemp() compatibility implementation","startedAt":"2010-02-25T09:01:12Z","lastAt":"2010-02-25T09:31:19Z","messageCount":2,"participants":["Filippo Negroni","Matthieu Moy"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"135663","messageId":"4B863C58.7010105@flexerasoftware.com","threadId":"22817","inReplyTo":null,"subject":"compat/mkdtemp.c: patch for gitmkdtemp() compatibility implementation","fromName":"Filippo Negroni","fromEmail":"fnegroni@flexerasoftware.com","sentAt":"2010-02-25T09:01:12Z","receivedAt":"2010-02-25T09:01:12Z","isPatch":false,"sender":{"key":"fnegroni@flexerasoftware.com","avatar":null},"body":"Dear all,\n\nI noticed that the current implementation of mkdtemp() in the compat/ directory does not seem to be correct.\n\ngitmkdtemp() is needed for platforms such as Solaris 9 and 10 which do not implement mkdtemp().\n\nThe current implementation (compat/mkdtemp.c):\n\n----\nchar *gitmkdtemp(char *template)\n{\n        if (!mktemp(template) || mkdir(template, 0700))\n                return NULL;\n        return template;\n}\n----\n\nseems to be testing the return value of mktemp incorrectly.\n\nmktemp() always returns the argument 'template', even on failure.\n\nThis is an extract from Solaris's mktemp(2) manual page:\n\nRETURN VALUES\n     The mktemp() function will  assign  to  template  the  empty\n     string if it  cannot create a unique name.\n\nUpon failure, 'template' is set to an empty string, i.e., it's first character is '\\0'.\n\nThe fixed implementation should read:\n\n----\nchar *gitmkdtemp(char *template)\n{\n        if (!*mktemp(template) || mkdir(template, 0700))\n                return NULL;\n        return template;\n}\n----\n\nI.e., simply add the pointer dereference operator when calling mktemp().\n\nI have attached a patch against the most current git repo, branch master.\n\nPlease let me know if you need the patch in any other way.\n\n\n>From 00b2a96d93d801d06eb710bc03b3e4804d3583ec Mon Sep 17 00:00:00 2001\nFrom: Filippo Negroni <fnegroni@flexerasoftware.com>\nDate: Thu, 25 Feb 2010 08:39:35 +0000\nSubject: [PATCH] Fixed return value check for mkdtemp implementation.\n\nmktemp() returns an 'empty' string, not a NULL pointer.\n---\n compat/mkdtemp.c |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/compat/mkdtemp.c b/compat/mkdtemp.c\nindex 34d4b49..1136119 100644\n--- a/compat/mkdtemp.c\n+++ b/compat/mkdtemp.c\n@@ -2,7 +2,7 @@\n \n char *gitmkdtemp(char *template)\n {\n-\tif (!mktemp(template) || mkdir(template, 0700))\n+\tif (!*mktemp(template) || mkdir(template, 0700))\n \t\treturn NULL;\n \treturn template;\n }\n-- \n1.6.4\n\n"},{"id":"135665","messageId":"vpqy6ih4q6w.fsf@bauges.imag.fr","threadId":"22817","inReplyTo":"4B863C58.7010105@flexerasoftware.com","subject":"Re: compat/mkdtemp.c: patch for gitmkdtemp() compatibility implementation","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2010-02-25T09:31:19Z","receivedAt":"2010-02-25T09:31:19Z","isPatch":false,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Thanks for your contribution to git. However ...\n\nFilippo Negroni <fnegroni@flexerasoftware.com> writes:\n\n> Please let me know if you need the patch in any other way.\n\nPlease, read\n\nhttp://repo.or.cz/w/git.git?a=blob;f=Documentation/SubmittingPatches;hb=HEAD\n\nespecially about inlining the patch and Signed-off-by, to make it easy\nand legally possible for our maintainer to apply your patch.\n\nThanks,\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"}]}