]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - posix/bug-getopt5.c
regex: fix read overrun [BZ #24114]
[thirdparty/glibc.git] / posix / bug-getopt5.c
index ed2639d35bdb91318698c78eb50a1c6c3ec603cf..4f67d9b2ece68573298d4898f0f5cd9f662bdb0b 100644 (file)
@@ -2,6 +2,7 @@
 #include <getopt.h>
 #include <unistd.h>
 #include <stdio.h>
+#include <stdlib.h>
 
 static const struct option opts[] =
   {
@@ -47,12 +48,14 @@ one_test (const char *fmt, int argc, char *argv[], int n, int expected[n])
 static int
 do_test (void)
 {
-  char *fname = tmpnam (NULL);
-  if (fname == NULL)
+  char fname[] = "/tmp/bug-getopt5.XXXXXX";
+  int fd = mkstemp (fname);
+  if (fd == -1)
     {
-      puts ("cannot generate name for temporary file");
+      printf ("mkstemp failed: %m\n");
       return 1;
     }
+  close (fd);
 
   if (freopen (fname, "w+", stderr) == NULL)
     {