bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] test-getcwd: don't stack-allocate PATH_MAX bytes


From: Eric Blake
Subject: [PATCH] test-getcwd: don't stack-allocate PATH_MAX bytes
Date: Mon, 20 Jun 2011 15:57:05 -0600

This reverts commit 1e33f8d86f, which guarantees that PATH_MAX
is always defined (but not necessarily constant).  Rather, the
test-getcwd code should be robust to POSIX rules for unlimited
or varying length maximums; as well as still passing in spite
of the HP-UX bug that doesn't define PATH_MAX as a proper
constant.

* modules/getcwd-tests (Depends-on): Revert prior change.
* tests/test-getcwd.c (test_long_name): Malloc the buffer instead.
(test_abort_bug): Fix compilation when PATH_MAX is variable.
* m4/getcwd-path-max.m4 (gl_FUNC_GETCWD_PATH_MAX): Keep in sync.
* m4/getcwd-abort-bug.m4 (gl_FUNC_GETCWD_ABORT_BUG): Likewise.
---

This should work whether or not Bruno's independent patch to
fix pathmax.h for HP-UX is checked in as well, but I'll hold
off committing until I have a review or until a couple days
have elapsed.

 ChangeLog              |    7 +++++++
 m4/getcwd-abort-bug.m4 |    4 +++-
 m4/getcwd-path-max.m4  |   12 ++++++++----
 modules/getcwd-tests   |    1 -
 tests/test-getcwd.c    |   14 ++++++++++----
 5 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 1758d67..1db2fc7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2011-06-20  Eric Blake  <address@hidden>

+       test-getcwd: don't stack-allocate PATH_MAX bytes
+       * modules/getcwd-tests (Depends-on): Revert prior change.
+       * tests/test-getcwd.c (test_long_name): Malloc the buffer instead.
+       (test_abort_bug): Fix compilation when PATH_MAX is variable.
+       * m4/getcwd-path-max.m4 (gl_FUNC_GETCWD_PATH_MAX): Keep in sync.
+       * m4/getcwd-abort-bug.m4 (gl_FUNC_GETCWD_ABORT_BUG): Likewise.
+
        test-stat: don't allocate PATH_MAX bytes
        * tests/test-stat.h (test_stat_func): Don't stack-allocate a
        PATH_MAX-sized buffer.
diff --git a/m4/getcwd-abort-bug.m4 b/m4/getcwd-abort-bug.m4
index fd6820d..f44ffef 100644
--- a/m4/getcwd-abort-bug.m4
+++ b/m4/getcwd-abort-bug.m4
@@ -1,4 +1,4 @@
-# serial 4
+# serial 5
 # Determine whether getcwd aborts when the length of the working directory
 # name is unusually large.  Any length between 4k and 16k trigger the bug
 # when using glibc-2.4.90-9 or older.
@@ -58,10 +58,12 @@ main ()
   size_t desired_depth;
   size_t d;

+#ifdef PATH_MAX
   /* The bug is triggered when PATH_MAX < getpagesize (), so skip
      this relatively expensive and invasive test if that's not true.  */
   if (getpagesize () <= PATH_MAX)
     return 0;
+#endif

   cwd = getcwd (NULL, 0);
   if (cwd == NULL)
diff --git a/m4/getcwd-path-max.m4 b/m4/getcwd-path-max.m4
index 475ae96..b5be446 100644
--- a/m4/getcwd-path-max.m4
+++ b/m4/getcwd-path-max.m4
@@ -1,4 +1,4 @@
-# serial 16
+# serial 17
 # Check for several getcwd bugs with long file names.
 # If so, arrange to compile the wrapper function.

@@ -77,14 +77,18 @@ main ()
      this should be done in a compile test.  */
   exit (0);
 #else
-  char buf[PATH_MAX * (DIR_NAME_SIZE / DOTDOTSLASH_LEN + 1)
-           + DIR_NAME_SIZE + BUF_SLOP];
-  char *cwd = getcwd (buf, PATH_MAX);
+  char *buf;
+  char *cwd;
   size_t initial_cwd_len;
   size_t cwd_len;
   int fail = 0;
   size_t n_chdirs = 0;

+  buf = malloc (PATH_MAX * (DIR_NAME_SIZE / DOTDOTSLASH_LEN + 1)
+                + DIR_NAME_SIZE + BUF_SLOP);
+  if (buf == NULL)
+    exit (10);
+  cwd = getcwd (buf, PATH_MAX);
   if (cwd == NULL)
     exit (10);

diff --git a/modules/getcwd-tests b/modules/getcwd-tests
index 34cc5ac..2187acc 100644
--- a/modules/getcwd-tests
+++ b/modules/getcwd-tests
@@ -5,7 +5,6 @@ Depends-on:
 errno
 fcntl-h
 getcwd-lgpl
-pathmax
 sys_stat

 configure.ac:
diff --git a/tests/test-getcwd.c b/tests/test-getcwd.c
index 3381077..b7c2ffe 100644
--- a/tests/test-getcwd.c
+++ b/tests/test-getcwd.c
@@ -26,7 +26,6 @@
 #include <string.h>
 #include <sys/stat.h>

-#include "pathmax.h"
 #include "macros.h"

 #if ! HAVE_GETPAGESIZE
@@ -49,10 +48,12 @@ test_abort_bug (void)
   size_t desired_depth;
   size_t d;

+#ifdef PATH_MAX
   /* The bug is triggered when PATH_MAX < getpagesize (), so skip
      this relatively expensive and invasive test if that's not true.  */
   if (getpagesize () <= PATH_MAX)
     return 0;
+#endif

   cwd = getcwd (NULL, 0);
   if (cwd == NULL)
@@ -121,14 +122,19 @@ test_long_name (void)
      this should be done in a compile test.  */
   return 0;
 #else
-  char buf[PATH_MAX * (DIR_NAME_SIZE / DOTDOTSLASH_LEN + 1)
-           + DIR_NAME_SIZE + BUF_SLOP];
-  char *cwd = getcwd (buf, PATH_MAX);
+  char *buf;
+  char *cwd;
   size_t initial_cwd_len;
   size_t cwd_len;
   int fail = 0;
   size_t n_chdirs = 0;

+  buf = malloc (PATH_MAX * (DIR_NAME_SIZE / DOTDOTSLASH_LEN + 1)
+                + DIR_NAME_SIZE + BUF_SLOP);
+  if (buf == NULL)
+    return 10;
+
+  cwd = getcwd (buf, PATH_MAX);
   if (cwd == NULL)
     return 10;

-- 
1.7.4.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]