Date: Mon, 22 Sep 1997 00:10:53 +0300 (EEST) From: Heikki Suonsivu <hsu@mail.clinet.fi> To: FreeBSD-gnats-submit@FreeBSD.ORG Subject: bin/4599: mktemp is too smart, accesses the path given Message-ID: <199709212110.AAA14120@katiska.clinet.fi> Resent-Message-ID: <199709212120.OAA17393@hub.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 4599 >Category: bin >Synopsis: mktemp is too smart, accesses the path given >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-bugs >State: open >Class: change-request >Submitter-Id: current-users >Arrival-Date: Sun Sep 21 14:20:01 PDT 1997 >Last-Modified: >Originator: Heikki Suonsivu >Organization: Clinet, Espoo, Finland >Release: FreeBSD 2.2-STABLE i386 >Environment: FreeBSD, I think in all versions from at least 2.2. >Description: mktemp is supposed to randomize a given pathname by replacing X's in the given string with process-specific numbers/data. However, if the given string does not point to a valid path, it returns NULL and botches the argument string. As it is supposed just to create a path name, this should not happen ? This breaks rdist6, which wants to create a temporary path and patch up missing directories on the path afterwards. >How-To-Repeat: #include <stdio.h> #include <string.h> main() { char foo[1024]; strcpy(foo, "/some/unexistent/directoryXXXXXX"); if (!mktemp(foo)) { perror(foo); } printf("foo become %s\n", foo); } hsu#katiska.clinet.fi Sun 10: ./hello /some/unexistent: No such file or directory foo become /some/unexistent hsu#katiska.clinet.fi Sun 11: >Fix: Dirty workaround for rdist6 (server.c): #if 0 if (!mktemp(new)) { error("Cannot create temporary name, errno %d.", errno); } #else { char *p; p = strstr(new, "XXXXXX"); if (p) sprintf(p, "%6d", getpid() % 1000000); else error("Cannot create temporary name"); } #endif -- Heikki Suonsivu, T{ysikuu 10 C 83/02210 Espoo/FINLAND, hsu@clinet.fi mobile +358-40-5519679 work +358-9-43542270 fax -4555276 >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199709212110.AAA14120>