From 49b9fc5a42ea59ca095413bdd4d11a952df5562d Mon Sep 17 00:00:00 2001 From: ph10 Date: Fri, 20 Oct 2017 16:57:48 +0000 Subject: Fix pcregrep recursive file name issue. git-svn-id: svn://vcs.exim.org/pcre/code/trunk@1712 2f5784b3-3f2a-0410-8824-cb99058d5e15 --- ChangeLog | 5 +++++ pcregrep.c | 10 ++++++++-- 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; -- cgit v1.2.1