about summary refs log tree commit diff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2004-09-30 23:13:17 +0000
committerUlrich Drepper <drepper@redhat.com>2004-09-30 23:13:17 +0000
commit0da4ee554369b536c554cbc2d50f1abf5e42bdf5 (patch)
tree27845d0eb9ce3bd8a4e618692a8b0207b69bcc21
parentc4f4ef871927b78f3c9a65cb34c95ced96e346e8 (diff)
downloadglibc-0da4ee554369b536c554cbc2d50f1abf5e42bdf5.tar.gz
glibc-0da4ee554369b536c554cbc2d50f1abf5e42bdf5.tar.xz
glibc-0da4ee554369b536c554cbc2d50f1abf5e42bdf5.zip
Update.
	* posix/Makefile: Add rules to build and run bug-glob1.
	* posix/bug-glob1.c: New file.
-rw-r--r--ChangeLog3
-rw-r--r--posix/Makefile3
-rw-r--r--posix/bug-glob1.c82
3 files changed, 87 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 918cd9daaa..39662680d9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2004-09-30  Ulrich Drepper  <drepper@redhat.com>
 
+	* posix/Makefile: Add rules to build and run bug-glob1.
+	* posix/bug-glob1.c: New file.
+
 	* iconv/iconv_prog.c (main): Print progress information to stderr.
 
 	* nscd/nscd.c (termination_handler): Reset timestamp so that
diff --git a/posix/Makefile b/posix/Makefile
index 82d35378d1..9bf415fdbf 100644
--- a/posix/Makefile
+++ b/posix/Makefile
@@ -82,7 +82,7 @@ tests		:= tstgetopt testfnm runtests runptests	     \
 		   bug-regex21 bug-regex22 bug-regex23 tst-nice tst-nanosleep \
 		   transbug tst-rxspencer tst-pcre tst-boost \
 		   bug-ga1 tst-vfork1 tst-vfork2 tst-waitid \
-		   tst-getaddrinfo2
+		   tst-getaddrinfo2 bug-glob1
 xtests		:= bug-ga2
 ifeq (yes,$(build-shared))
 test-srcs	:= globtest
@@ -172,6 +172,7 @@ tst-rxspencer-ARGS = --utf8 rxspencer/tests
 tst-rxspencer-ENV = LOCPATH=$(common-objpfx)localedata
 tst-pcre-ARGS = PCRE.tests
 tst-boost-ARGS = BOOST.tests
+bug-glob1-ARGS = "$(objpfx)"
 
 testcases.h: TESTS TESTS2C.sed
 	sed -f TESTS2C.sed < $< > $@T
diff --git a/posix/bug-glob1.c b/posix/bug-glob1.c
new file mode 100644
index 0000000000..4f7e981c75
--- /dev/null
+++ b/posix/bug-glob1.c
@@ -0,0 +1,82 @@
+/* Test case for globbing dangling symlink.  By Ulrich Drepper.  */
+#include <errno.h>
+#include <error.h>
+#include <glob.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+
+static void prepare (int argc, char *argv[]);
+#define PREPARE prepare
+static int do_test (void);
+#define TEST_FUNCTION do_test ()
+
+#include "../test-skeleton.c"
+
+
+static char *fname;
+
+static void
+prepare (int argc, char *argv[])
+{
+  if (argc < 2)
+    error (EXIT_FAILURE, 0, "missing argument");
+
+  size_t len = strlen (argv[1]);
+  static const char ext[] = "globXXXXXX";
+  fname = malloc (len + 1 + sizeof (ext));
+  if (fname == NULL)
+    error (EXIT_FAILURE, errno, "cannot create temp file");
+  strcpy (stpcpy (stpcpy (fname, argv[1]), "/"), ext);
+  fname = mktemp (fname);
+  if (fname == NULL || *fname == '\0')
+    error (EXIT_FAILURE, errno, "cannot create temp file name");
+  if (symlink ("bug-glob1-does-not-exist", fname) != 0)
+    error (EXIT_FAILURE, errno, "cannot create symlink");
+  add_temp_file (fname);
+}
+
+
+static int
+do_test (void)
+{
+  glob_t gl;
+  int retval = 0;
+  int e;
+
+  e = glob (fname, 0, NULL, &gl);
+  if (e == 0)
+    {
+      printf ("glob(\"%s\") succeeded\n", fname);
+      retval = 1;
+    }
+  globfree (&gl);
+
+  size_t fnamelen = strlen (fname);
+  char buf[fnamelen + 2];
+
+  strcpy (buf, fname);
+  buf[fnamelen - 1] = '?';
+  e = glob (buf, 0, NULL, &gl);
+  if (e == 0)
+    {
+      printf ("glob(\"%s\") succeeded\n", buf);
+      retval = 1;
+    }
+  globfree (&gl);
+
+  strcpy (buf, fname);
+  buf[fnamelen] = '*';
+  buf[fnamelen + 1] = '\0';
+  e = glob (buf, 0, NULL, &gl);
+  if (e == 0)
+    {
+      printf ("glob(\"%s\") succeeded\n", buf);
+      retval = 1;
+    }
+  globfree (&gl);
+
+  return retval;
+}