[Pcre-svn] [873] code/trunk: Fix pcre2grep recursive file na…

Top Page
Delete this message
Author: Subversion repository
Date:  
To: pcre-svn
Subject: [Pcre-svn] [873] code/trunk: Fix pcre2grep recursive file name length issue.
Revision: 873
          http://www.exim.org/viewvc/pcre2?view=rev&revision=873
Author:   ph10
Date:     2017-10-20 17:51:59 +0100 (Fri, 20 Oct 2017)
Log Message:
-----------
Fix pcre2grep recursive file name length issue.


Modified Paths:
--------------
    code/trunk/ChangeLog
    code/trunk/src/pcre2grep.c


Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog    2017-10-17 16:26:40 UTC (rev 872)
+++ code/trunk/ChangeLog    2017-10-20 16:51:59 UTC (rev 873)
@@ -34,7 +34,12 @@
 about a bad option only if the following argument item does not start with a 
 hyphen.


+11. pcre2grep was truncating components of file names to 128 characters when
+processing files with the -r option, and also (some very odd code) truncating
+path names to 512 characters. There is now a check on the absolute length of
+full path file names, which may be up to 2047 characters long.

+
Version 10.30 14-August-2017
----------------------------


Modified: code/trunk/src/pcre2grep.c
===================================================================
--- code/trunk/src/pcre2grep.c    2017-10-17 16:26:40 UTC (rev 872)
+++ code/trunk/src/pcre2grep.c    2017-10-20 16:51:59 UTC (rev 873)
@@ -109,7 +109,7 @@
 #define MAXPATLEN 8192
 #endif


-#define FNBUFSIZ 1024
+#define FNBUFSIZ 2048
#define ERRBUFSIZ 256

/* Values for the "filenames" variable, which specifies options for file name
@@ -3032,7 +3032,7 @@

   if (dee_action == dee_RECURSE)
     {
-    char buffer[1024];
+    char buffer[FNBUFSIZ];
     char *nextfile;
     directory_type *dir = opendirectory(pathname);


@@ -3047,7 +3047,13 @@
     while ((nextfile = readdirectory(dir)) != NULL)
       {
       int frc;
-      sprintf(buffer, "%.512s%c%.128s", pathname, FILESEP, nextfile);
+      int fnlength = strlen(pathname) + strlen(nextfile) + 2;
+      if (fnlength > FNBUFSIZ)
+        {
+        fprintf(stderr, "pcre2grep: recursive filename is too long\n");
+        return 2;
+        }
+      sprintf(buffer, "%s%c%s", pathname, FILESEP, nextfile);
       frc = grep_or_recurse(buffer, dir_recurse, FALSE);
       if (frc > 1) rc = frc;
        else if (frc == 0 && rc == 1) rc = 0;