summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15>2017-10-20 16:57:48 +0000
committerph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15>2017-10-20 16:57:48 +0000
commit49b9fc5a42ea59ca095413bdd4d11a952df5562d (patch)
tree5b28e2087561218c7763ae6b3c6916e4b0972c7e
parent3f00c9292a6432c1b2f66f217fe2886eb480f187 (diff)
downloadpcre-49b9fc5a42ea59ca095413bdd4d11a952df5562d.tar.gz
Fix pcregrep recursive file name issue.
git-svn-id: svn://vcs.exim.org/pcre/code/trunk@1712 2f5784b3-3f2a-0410-8824-cb99058d5e15
-rw-r--r--ChangeLog5
-rw-r--r--pcregrep.c10
2 files changed, 13 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 151b055..6598469 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -11,6 +11,11 @@ Version 8.42 xx-xxx-2017
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
-------------------------
diff --git a/pcregrep.c b/pcregrep.c
index 317f745..d4a5fb5 100644
--- a/pcregrep.c
+++ b/pcregrep.c
@@ -2234,7 +2234,7 @@ if (isdirectory(pathname))
if (dee_action == dee_RECURSE)
{
- char buffer[1024];
+ char buffer[2048];
char *nextfile;
directory_type *dir = opendirectory(pathname);
@@ -2249,7 +2249,13 @@ if (isdirectory(pathname))
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;