tempnam and AF_UNIX sockets

Richard C Bilson rcbilson@plg.uwaterloo.ca
Fri Jan 14 21:37:00 GMT 2005


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



More information about the Libc-alpha mailing list