Revision: 1712
http://vcs.pcre.org/viewvc?view=rev&revision=1712
Author: ph10
Date: 2017-10-20 17:57:48 +0100 (Fri, 20 Oct 2017)
Log Message:
-----------
Fix pcregrep recursive file name issue.
Modified Paths:
--------------
code/trunk/ChangeLog
code/trunk/pcregrep.c
Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog 2017-09-13 16:20:43 UTC (rev 1711)
+++ code/trunk/ChangeLog 2017-10-20 16:57:48 UTC (rev 1712)
@@ -11,7 +11,12 @@
2. Fixed outdated real_pcre definitions in pcre.h.in (patch by Evgeny Kotkov).
+3. pcregrep 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 8.41 05-July-2017
-------------------------
Modified: code/trunk/pcregrep.c
===================================================================
--- code/trunk/pcregrep.c 2017-09-13 16:20:43 UTC (rev 1711)
+++ code/trunk/pcregrep.c 2017-10-20 16:57:48 UTC (rev 1712)
@@ -2234,7 +2234,7 @@
if (dee_action == dee_RECURSE)
{
- char buffer[1024];
+ char buffer[2048];
char *nextfile;
directory_type *dir = opendirectory(pathname);
@@ -2249,7 +2249,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 > 2048)
+ {
+ 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;