changeset 15314:517a0b73b86b

stat: be robust to PATH_MAX definition Make this stack-allocation of PATH_MAX bytes more robust. * lib/stat.c (rpl_stat): Require reasonable PATH_MAX. * modules/stat (Depends-on): Add verify. Signed-off-by: Eric Blake <eblake@redhat.com>
author Eric Blake <eblake@redhat.com>
date Mon, 20 Jun 2011 16:55:24 -0600
parents 8dfa469e2ba8
children 94b3a0b47189
files ChangeLog lib/stat.c modules/stat
diffstat 3 files changed, 13 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2011-06-22  Eric Blake  <eblake@redhat.com>
 
+	stat: be robust to PATH_MAX definition
+	* lib/stat.c (rpl_stat): Require reasonable PATH_MAX.
+	* modules/stat (Depends-on): Add verify.
+
 	link: work around IRIX bug
 	* m4/link.m4 (gl_FUNC_LINK): Expose the bug.
 	* lib/link.c (rpl_link): Work around it.
--- a/lib/stat.c
+++ b/lib/stat.c
@@ -38,6 +38,7 @@
 #include <stdbool.h>
 #include <string.h>
 #include "dosname.h"
+#include "verify.h"
 
 /* Store information about NAME into ST.  Work around bugs with
    trailing slashes.  Mingw has other bugs (such as st_ino always
@@ -63,6 +64,12 @@
     }
 #endif /* REPLACE_FUNC_STAT_FILE */
 #if REPLACE_FUNC_STAT_DIR
+  /* The only known systems where REPLACE_FUNC_STAT_DIR is needed also
+     have a constant PATH_MAX.  */
+# ifndef PATH_MAX
+#  error "Please port this replacement to your platform"
+# endif
+
   if (result == -1 && errno == ENOENT)
     {
       /* Due to mingw's oddities, there are some directories (like
@@ -77,6 +84,7 @@
       char fixed_name[PATH_MAX + 1] = {0};
       size_t len = strlen (name);
       bool check_dir = false;
+      verify (PATH_MAX <= 4096);
       if (PATH_MAX <= len)
         errno = ENAMETOOLONG;
       else if (len)
--- a/modules/stat
+++ b/modules/stat
@@ -9,6 +9,7 @@
 sys_stat
 dosname         [test $REPLACE_STAT = 1]
 stdbool         [test $REPLACE_STAT = 1]
+verify          [test $REPLACE_STAT = 1]
 
 configure.ac:
 gl_FUNC_STAT