This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
tempnam and AF_UNIX sockets
- From: Richard C Bilson <rcbilson at plg dot uwaterloo dot ca>
- To: libc-alpha at sources dot redhat dot com
- Date: Fri, 14 Jan 2005 16:37:31 -0500 (EST)
- Subject: tempnam and AF_UNIX sockets
In a library I'm working on, there is code as follows:
((sockaddr_un *)saddr)->sun_family = AF_UNIX;
tmpnm = tempnam( NULL, "uC++" );
strncpy( ((sockaddr_un *)saddr)->sun_path, tmpnm, sizeof(((sockaddr_un *)saddr)->sun_path) );
saddrlen = SUN_LEN( (sockaddr_un *)saddr );
code = bind( socket.access.fd, saddr, saddrlen );
I have three questions:
1) Many uses of tempnam are unsafe. Is this one such use? (I think
not, but I may lack imagination.)
2) If it is unsafe, how can it be done safely?
3) If it is safe, how do I suppress the "tempnam is dangerous" linker
warning?
The last has been a constant irritation for our users, who don't
understand why their program becomes "dangerous" simply because they've
linked with our library.
Many thanks.
--
Richard C. Bilson, Research Assistant | School of Computer Science
rcbilson@plg.uwaterloo.ca | University of Waterloo
http://plg.uwaterloo.ca/~rcbilson | 200 University Avenue West
Office: DC 3548F Ph: (519)888-4567x4822 | Waterloo, Ontario, CANADA N2L 3G1