about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--stdio-common/tmpnam.c8
-rw-r--r--sysdeps/posix/getaddrinfo.c10
3 files changed, 19 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index c90bf533a3..0f4efab5b9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2000-09-28  Ulrich Drepper  <drepper@redhat.com>
 
+	* stdio-common/tmpnam.c (tmpnam): Optimize a bit.
+
+	* sysdeps/posix/getaddrinfo.c (gaih_local): Don't use tmpnam, use
+	underlying functions directly.
+
 	* sysdeps/unix/sysv/linux/bits/resource.h: Add RLIMIT_LOCKS.
 	* sysdeps/unix/sysv/linux/arm/bits/resource.h: Likewise.
 	* sysdeps/unix/sysv/linux/i386/bits/resource.h: Likewise.
diff --git a/stdio-common/tmpnam.c b/stdio-common/tmpnam.c
index c202760af2..fc30026648 100644
--- a/stdio-common/tmpnam.c
+++ b/stdio-common/tmpnam.c
@@ -29,15 +29,17 @@ tmpnam (char *s)
 {
   /* By using two buffers we manage to be thread safe in the case
      where S != NULL.  */
-  char tmpbuf[L_tmpnam];
+  char tmpbufmem[L_tmpnam];
+  char tmpbuf = s ?: tmpbufmem;
 
   /* In the following call we use the buffer pointed to by S if
      non-NULL although we don't know the size.  But we limit the size
      to L_tmpnam characters in any case.  */
-  if (__path_search (s ? : tmpbuf, L_tmpnam, NULL, NULL, 0))
+  if (__builtin_expect (__path_search (tmpbuf, L_tmpnam, NULL, NULL, 0),
+			0))
     return NULL;
 
-  if (__gen_tempname (s ? : tmpbuf, __GT_NOCREATE))
+  if (__builtin_expect (__gen_tempname (tmpbuf, __GT_NOCREATE), 0))
     return NULL;
 
   if (s == NULL)
diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c
index fdd8729657..7a84cd3030 100644
--- a/sysdeps/posix/getaddrinfo.c
+++ b/sysdeps/posix/getaddrinfo.c
@@ -206,7 +206,15 @@ gaih_local (const char *name, const struct gaih_service *service,
     }
   else
     {
-      if (tmpnam (((struct sockaddr_un *) (*pai)->ai_addr)->sun_path) == NULL)
+      /* This is a dangerous use of the interface since there is a time
+	 window between the test for the file and the actual creation
+	 (done by the caller) in which a file with the same name could
+	 be created.  */
+      char *buf = ((struct sockaddr_un *) (*pai)->ai_addr)->sun_path;
+
+      if (__builtin_expect (__path_search (buf, L_tmpnam, NULL, NULL, 0),
+			    0) != 0
+	  || __builtin_expect (__gen_tempname (buf, __GT_NOCREATE), 0) != 0)
 	return -EAI_SYSTEM;
     }