Bug 2249 - mktemp fails (it does nothing)
Summary: mktemp fails (it does nothing)
Keywords:
Status: CLOSED WONTFIX
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: glibc
Version: 6.0
Hardware: i386
OS: Linux
high
high
Target Milestone: ---
Assignee: Cristian Gafton
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 1999-04-18 14:33 UTC by jay
Modified: 2008-05-01 15:37 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 1999-07-02 20:59:10 UTC
Embargoed:


Attachments (Terms of Use)

Description jay 1999-04-18 14:33:19 UTC
mktemp returns an empty string.  Here is a GDB session
showing this:-

(gdb) b main
Breakpoint 1 at 0x804913c: file ../../gnu/CSSC/bsd/sccs.c,
line 576.
(gdb) r unedit foo
Starting program: /home/james/source/CSSC/compile/bsd/sccs
unedit foo

Breakpoint 1, main (argc=3, argv=0xbffffad4) at
../../gnu/CSSC/bsd/sccs.c:576
(gdb) n
(gdb)
(gdb)
(gdb)
(gdb)
[...]
(gdb)
(gdb)
(gdb) s
command (argv=0xbffffad8, forkflag=0 '\000', arg0=0x804b17e
"")
    at ../../gnu/CSSC/bsd/sccs.c:943
(gdb) n
(gdb)
(gdb)
(gdb)
(gdb)
(gdb)
(gdb)
(gdb)
(gdb)
(gdb)
(gdb)
(gdb)
(gdb)
(gdb)
(gdb)
(gdb)
(gdb)
(gdb)
(gdb)
(gdb)
(gdb) s
unedit (fn=0xbffffc42 "foo") at
../../gnu/CSSC/bsd/sccs.c:1862
(gdb) n
(gdb)
(gdb) print tfn
$1 = "/tmp/sccsXXXXX"
(gdb) n
(gdb)
(gdb)
(gdb)
(gdb)
(gdb)
(gdb)
(gdb)
(gdb)
(gdb) print tfn
$2 = "\000tmp/sccsXXXXX"
(gdb) list
1890	      return (FALSE);
1891	    }
1892
1893	  /* create temp file for editing p-file */
1894	  mktemp (tfn);
1895	  tfp = fopen (tfn, "w");
1896	  if (tfp == NULL)
1897	    {
1898	      usrerr ("cannot create \"%s\"", tfn);
1899	      fclose(pfp);
(gdb) where
#0  unedit (fn=0xbffffc42 "foo") at
../../gnu/CSSC/bsd/sccs.c:1895
#1  0x8049a57 in command (argv=0xbffffad8, forkflag=0
'\000',
    arg0=0x804b17e "") at ../../gnu/CSSC/bsd/sccs.c:1103
#2  0x80494d0 in main (argc=3, argv=0xbffffad8)
    at ../../gnu/CSSC/bsd/sccs.c:779
#3  0x40033ca7 in __libc_start_main (main=0x8049130 <main>,
argc=3,
    argv=0xbffffad4, init=0x8048b24 <_init>, fini=0x804ad7c
<_fini>,
    rtld_fini=0x40009c30 <_dl_fini>, stack_end=0xbffffacc)
    at ../sysdeps/generic/libc-start.c:78
(gdb) quit



Here is the strace output of the same event (which includes
the complete program execution):-

execve("../../bsd/sccs", ["../../bsd/sccs", "unedit",
"foo"], [/* 36 vars */]) =
 0
brk(0)                                  = 0x804ce19
open("/etc/ld.so.preload", O_RDONLY)    = -1 ENOENT (No such
file or directory)
open("/etc/ld.so.cache", O_RDONLY)      = 4
fstat(4, {st_mode=0, st_size=0, ...})   = 0
mmap(0, 34588, PROT_READ, MAP_PRIVATE, 4, 0) = 0x40013000
close(4)                                = 0
open("/lib/libc.so.6", O_RDONLY)        = 4
fstat(4, {st_mode=0, st_size=0, ...})   = 0
read(4, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3"..., 4096) = 4096
mmap(0, 944824, PROT_READ|PROT_EXEC, MAP_PRIVATE, 4, 0) =
0x4001c000
mprotect(0x400fb000, 31416, PROT_NONE)  = 0
mmap(0x400fb000, 20480, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED, 4, 0xde000)
 = 0x400fb000
mmap(0x40100000, 10936, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOU
S, -1, 0) = 0x40100000
close(4)                                = 0
mmap(0, 4096, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x401030
00
munmap(0x40013000, 34588)               = 0
personality(PER_LINUX)                  = 0
getpid()                                = 1363
getuid()                                = 101
geteuid()                               = 101
getgid()                           = 100
getegid()                               = 100
brk(0)                                  = 0x804ce19
brk(0x804ce51)                          = 0x804ce51
brk(0x804d000)                          = 0x804d000
open("/usr/share/locale/locale.alias", O_RDONLY) = 4
fstat(4, {st_mode=S_ISGID|S_ISVTX|0615, st_size=0, ...}) = 0
mmap(0, 4096, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x400130
00
read(4, "# Locale name alias data base.\n"..., 4096) = 2096
brk(0x804e000)                          = 0x804e000
read(4, "", 4096)                       = 0
close(4)                                = 0
munmap(0x40013000, 4096)                = 0
open("/usr/share/i18n/locale.alias", O_RDONLY) = -1 ENOENT
(No such file or dire
ctory)
open("/usr/share/locale/en_GB/LC_MESSAGES", O_RDONLY) = 4
fstat(4, {st_mode=0, st_size=0, ...})   = 0
close(4)                                = 0
open("/usr/share/locale/en_GB/LC_MESSAGES/SYS_LC_MESSAGES",
O_RDONLY) = 4
fstat(4, {st_mode=0, st_size=0, ...})   = 0
mmap(0, 42, PROT_READ, MAP_PRIVATE, 4, 0) = 0x40013000
close(4)                                = 0
open("/usr/share/locale/en_GB/LC_MONETARY", O_RDONLY) = 4
fstat(4, {st_mode=0, st_size=0, ...})   = 0
mmap(0, 93, PROT_READ, MAP_PRIVATE, 4, 0) = 0x40014000
close(4)                                = 0
open("/usr/share/locale/en_GB/LC_COLLATE", O_RDONLY) = 4
fstat(4, {st_mode=S_IFCHR|S_ISUID|S_ISGID|0535,
st_rdev=makedev(232, 171), ...})
 = 0
mmap(0, 29970, PROT_READ, MAP_PRIVATE, 4, 0) = 0x40104000
close(4)                                = 0
open("/usr/share/locale/en_GB/LC_TIME", O_RDONLY) = 4
fstat(4, {st_mode=S_ISVTX|0406, st_size=0, ...}) = 0
mmap(0, 492, PROT_READ, MAP_PRIVATE, 4, 0) = 0x40015000
close(4)                                = 0
open("/usr/share/locale/en_GB/LC_NUMERIC", O_RDONLY) = 4
fstat(4, {st_mode=S_IFCHR|S_ISUID|S_ISGID|067,
st_rdev=makedev(232, 171), ...})
= 0
mmap(0, 27, PROT_READ, MAP_PRIVATE, 4, 0) = 0x40016000
close(4)                                = 0
brk(0x804f000)                          = 0x804f000
open("/usr/share/locale/en_GB/LC_CTYPE", O_RDONLY) = 4
fstat(4, {st_mode=0, st_size=0, ...})   = 0
mmap(0, 10428, PROT_READ, MAP_PRIVATE, 4, 0) = 0x40017000
close(4)                                = 0
stat("foo", {st_mode=0, st_size=0, ...}) = 0
open("SCCS/p.foo", O_RDONLY)            = 4
open("", O_WRONLY|O_CREAT|O_TRUNC, 0666) = -1 ENOENT (No
such file or directory)
write(2, "\nsccs: ", 7)                 = 7
write(2, "cannot create \"\"", 16)      = 16
write(2, "\n", 1)                       = 1
close(4)                                = 0
_exit(71)                               = ?



Obviously, it's the open("",...) which is the symptom.
Unsetting $LANG doesn't help.

Comment 1 Jay Turner 1999-06-04 14:53:59 UTC
This issue has been forwarded to a developer for further action.

Comment 2 Alan Cox 1999-06-12 13:55:59 UTC
You are using mktemp incorrectly. It expects 6 X's to be passed.
It may also fail so you should check the return code

Comment 3 Cristian Gafton 1999-06-16 15:11:59 UTC
mktemp /tmp/foo.XXXXXX works for me

------- Email Received From  James Youngman <jay> 06/17/99 00:37 -------

Comment 4 Alan Cox 1999-06-17 13:44:59 UTC
Confirmed. Looks like a tiny glibc bug wants fixing.

Comment 5 Cristian Gafton 1999-07-02 20:57:59 UTC
Contents of the mail message:

Oops. The original bug report was for mktemp(3), not mktemp(1).

Well, as Alan pointed out, I had miscounted the Xs in the
function argument.  However, there is still a bug.  Where the argument
does not end in SIX 'X' characters, the function fails to return NULL.
Here is a much simpler example:-

[james@periwinkle james]$ make mktemp-test
cc     mktemp-test.c   -o mktemp-test
[james@periwinkle james]$ ./mktemp-test
mktemp returns '' (0xbffff798)
[james@periwinkle james]$ cat mktemp-test.c
#include <stdio.h>
#include <stdlib.h>

int main()
{
  char tmp[] = "/tmp/test.XXXXX"; /* Note! only 5 Xs! */
  char * p = mktemp(tmp);
  printf("mktemp returns '%s' (%p)\n", p ? p : "NULL", (void*)p);
  return 0;
}
[james@periwinkle james]$ cat /etc/redhat-release
Red Hat Linux release 6.0 (Hedwig)
[james@periwinkle james]$


From the manpage:-
RETURN VALUE
       The mktemp() function returns NULL on error (template  did
       not  end  in  XXXXXX) and template otherwise.
[...]

Comment 6 Cristian Gafton 1999-07-02 20:59:59 UTC
Well, POSIX says:

RETURN VALUE

     The mktemp() function returns the pointer template. If a unique
name cannot be created, template points to a null string.
[...]

So the current operation is correct. The man page will be fixed to
reflect that.


Note You need to log in before you can comment on or make changes to this bug.