Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/stdio PR/47757: Eric Radman: mktemp(3) mangles the ...



details:   https://anonhg.NetBSD.org/src/rev/a657380f6ede
branches:  trunk
changeset: 786259:a657380f6ede
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Apr 22 20:57:36 2013 +0000

description:
PR/47757: Eric Radman: mktemp(3) mangles the pathname if not given an absolute
    path
1. on error, gettemp() did not restore the path string
2. when emulating mktemp() it is not an error for the pattern not to represent
   a real directory structure
XXX[1]: pullup-5, pullup-6
XXX[2]: the default pattern is the simplistic <pid><X> for mktemp.

diffstat:

 lib/libc/stdio/gettemp.c |  14 ++++++++------
 1 files changed, 8 insertions(+), 6 deletions(-)

diffs (39 lines):

diff -r 17cda43e5edd -r a657380f6ede lib/libc/stdio/gettemp.c
--- a/lib/libc/stdio/gettemp.c  Mon Apr 22 19:33:53 2013 +0000
+++ b/lib/libc/stdio/gettemp.c  Mon Apr 22 20:57:36 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: gettemp.c,v 1.15 2012/03/15 18:22:30 christos Exp $    */
+/*     $NetBSD: gettemp.c,v 1.16 2013/04/22 20:57:36 christos Exp $    */
 
 /*
  * Copyright (c) 1987, 1993
@@ -40,7 +40,7 @@
 #if 0
 static char sccsid[] = "@(#)mktemp.c   8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: gettemp.c,v 1.15 2012/03/15 18:22:30 christos Exp $");
+__RCSID("$NetBSD: gettemp.c,v 1.16 2013/04/22 20:57:36 christos Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -119,14 +119,16 @@
                if (trv <= path)
                        break;
                if (*trv == '/') {
+                       int e;
                        *trv = '\0';
-                       if (stat(path, &sbuf))
-                               return 0;
+                       e = stat(path, &sbuf);
+                       *trv = '/';
+                       if (e == -1)
+                               return doopen == NULL && !domkdir;
                        if (!S_ISDIR(sbuf.st_mode)) {
                                errno = ENOTDIR;
-                               return 0;
+                               return doopen == NULL && !domkdir;
                        }
-                       *trv = '/';
                        break;
                }
        }



Home | Main Index | Thread Index | Old Index