NetBSD Problem Report #47757

From www@NetBSD.org  Sun Apr 21 19:25:02 2013
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [149.20.53.66])
	by www.NetBSD.org (Postfix) with ESMTP id 07E5A63F3AB
	for <gnats-bugs@gnats.NetBSD.org>; Sun, 21 Apr 2013 19:25:02 +0000 (UTC)
Message-Id: <20130421192500.BEA1963F3AB@www.NetBSD.org>
Date: Sun, 21 Apr 2013 19:25:00 +0000 (UTC)
From: ericshane@eradman.com
Reply-To: ericshane@eradman.com
To: gnats-bugs@NetBSD.org
Subject: mktemp(3) mangles the pathname if not given an absolute path
X-Send-Pr-Version: www-1.0

>Number:         47757
>Category:       bin
>Synopsis:       mktemp(3) mangles the pathname if not given an absolute path
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    bin-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Apr 21 19:30:00 +0000 2013
>Closed-Date:    Thu Apr 16 06:54:38 +0000 2015
>Last-Modified:  Thu Apr 16 06:54:38 +0000 2015
>Originator:     Eric Radman
>Release:        5.1
>Organization:
eradman.com
>Environment:
it's i386, GENERIC kernel. Don't have access to my test box right now
>Description:
In my tests, mktemp(3) only seems to return the first portion of the path if a relative pathname is given
>How-To-Repeat:
#include <stdio.h>
#include <sys/syslimits.h>

int main() {
        char fn[PATH_MAX];

        strlcpy(fn, "tmp/test.XXXXXX", PATH_MAX);
        mktemp(fn);
        printf("'%s'\n", fn);

        return 0;
}

This prints 'tmp' instead of 'tmp/test.XXXXXX'.

>Fix:

>Release-Note:

>Audit-Trail:
From: Martin Husemann <martin@duskware.de>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: bin/47757: mktemp(3) mangles the pathname if not given an absolute path
Date: Sun, 21 Apr 2013 21:44:31 +0200

 Did the relative ./tmp path exist?
 The function incorrectly does not return NULL on this type of failure.

 Note that you should use mkstemp(3) anyway.

 Martin

From: Eric Radman <ericshane@eradman.com>
To: gnats-bugs@NetBSD.org
Cc: gnats-admin@netbsd.org, netbsd-bugs@netbsd.org, ericshane@eradman.com
Subject: Re: bin/47757: mktemp(3) mangles the pathname if not given an
 absolute path
Date: Sun, 21 Apr 2013 20:03:13 -0400

 On Sun, Apr 21, 2013 at 07:45:05PM +0000, Martin Husemann wrote:
 > The following reply was made to PR bin/47757; it has been noted by GNATS.
 > 
 > From: Martin Husemann <martin@duskware.de>
 > 
 >  Did the relative ./tmp path exist?

 Hi Martin,

 No the path doesn't exist, but on other platforms that I've tried (MacOS,
 Linux, OpenBSD, FreeBSD) *template is modified correctly weather the
 path exists or not.

 >  The function incorrectly does not return NULL on this type of failure.
 >  
 >  Note that you should use mkstemp(3) anyway.

 Perhaps I should explain my use case a little more. I'm using this
 function as part of a unit test that generates pathnames for functions
 that would normally expect user input (argv[1]). Part of the syntax for
 the user supplies is an optional prefix, '+'

 +/path/to/fifo

 The utility strips off the '+' later on, but I need to generate random
 paths that include this pattern. I could invent a workaround that adds
 the prefix after running mktemp(3)/mkstemp(3), but the man page doesn't
 indicate that the paths must start with '/'.

 Eric

From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/47757 CVS commit: src/lib/libc/stdio
Date: Mon, 22 Apr 2013 16:57:37 -0400

 Module Name:	src
 Committed By:	christos
 Date:		Mon Apr 22 20:57:36 UTC 2013

 Modified Files:
 	src/lib/libc/stdio: gettemp.c

 Log Message:
 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.


 To generate a diff of this commit:
 cvs rdiff -u -r1.15 -r1.16 src/lib/libc/stdio/gettemp.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: Tobias Nygren <tnn@NetBSD.org>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: bin/47757
Date: Thu, 19 Mar 2015 15:50:29 +0100

 Please pull up this fix to netbsd-6.
 I just found out that pkgsrc/devel/ccache is broken due to a variant of this bug.

 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 #include <assert.h>

 int main(int argc, char **argv) {
         char *itemplate = "/tmp/test/test.XXX";
         char *otemplate = strdup(itemplate);
         system("rm -rf /tmp/test");
         mkstemp(otemplate);
         printf("%s\n", itemplate);
         printf("%s\n", otemplate);
 }

 /tmp/test/test.XXX
 /tmp/test

State-Changed-From-To: open->pending-pullups
State-Changed-By: msaitoh@NetBSD.org
State-Changed-When: Sun, 22 Mar 2015 12:14:17 +0000
State-Changed-Why:
pullup requests were sent to pullup-[56]@n.o


From: "Soren Jacobsen" <snj@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/47757 CVS commit: [netbsd-6] src/lib/libc/stdio
Date: Thu, 16 Apr 2015 06:24:16 +0000

 Module Name:	src
 Committed By:	snj
 Date:		Thu Apr 16 06:24:16 UTC 2015

 Modified Files:
 	src/lib/libc/stdio [netbsd-6]: gettemp.c

 Log Message:
 Pull up following revision(s) (requested by msaitoh in ticket #1282):
 	lib/libc/stdio/gettemp.c: revision 1.16
 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.


 To generate a diff of this commit:
 cvs rdiff -u -r1.14 -r1.14.22.1 src/lib/libc/stdio/gettemp.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Soren Jacobsen" <snj@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/47757 CVS commit: [netbsd-5] src/lib/libc/stdio
Date: Thu, 16 Apr 2015 06:33:59 +0000

 Module Name:	src
 Committed By:	snj
 Date:		Thu Apr 16 06:33:59 UTC 2015

 Modified Files:
 	src/lib/libc/stdio [netbsd-5]: gettemp.c

 Log Message:
 Pull up following revision(s) (requested by msaitoh in ticket #1955):
 	lib/libc/stdio/gettemp.c: revision 1.16 via patch
 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.


 To generate a diff of this commit:
 cvs rdiff -u -r1.14 -r1.14.2.1 src/lib/libc/stdio/gettemp.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: pending-pullups->closed
State-Changed-By: snj@NetBSD.org
State-Changed-When: Thu, 16 Apr 2015 06:54:38 +0000
State-Changed-Why:
Fixed and pulled up. Thanks!


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.