diff --git a/ChangeLog b/ChangeLog index f0a4ad9..35c7ec0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -34,6 +34,11 @@ exit(0) and exit(1). 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 ---------------------------- diff --git a/src/pcre2grep.c b/src/pcre2grep.c index bd86998..d7410b4 100644 --- a/src/pcre2grep.c +++ b/src/pcre2grep.c @@ -109,7 +109,7 @@ typedef int BOOL; #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 (isdirectory(pathname)) if (dee_action == dee_RECURSE) { - char buffer[1024]; + char buffer[FNBUFSIZ]; char *nextfile; directory_type *dir = opendirectory(pathname); @@ -3047,7 +3047,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 > 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;