discover: Use mkstemp rather than tempnam
authorJeremy Kerr <jk@ozlabs.org>
Thu, 14 Nov 2013 03:54:34 +0000 (14:54 +1100)
committerJeremy Kerr <jk@ozlabs.org>
Thu, 14 Nov 2013 04:33:01 +0000 (15:33 +1100)
We're getting warnings from some compilers about tempnam being unsafe.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
discover/paths.c

index aa977fdba1f3d0bcbdbf84356a854877c202a17d..64b218e820d2f06ec508584a7b4a2fddea0fc5b6 100644 (file)
@@ -46,15 +46,17 @@ char *join_paths(void *alloc_ctx, const char *a, const char *b)
 
 static char *local_name(void *ctx)
 {
-       char *tmp, *ret;
+       char *ret, tmp[] = "/tmp/pb-XXXXXX";
+       int fd;
 
-       tmp = tempnam(NULL, "pb-");
+       fd = mkstemp(tmp);
 
-       if (!tmp)
+       if (fd < 0)
                return NULL;
 
+       close(fd);
+
        ret = talloc_strdup(ctx, tmp);
-       free(tmp);
 
        return ret;
 }