Fix pcre2grep recursive file name length issue.

This commit is contained in:
Philip.Hazel 2017-10-20 16:51:59 +00:00
parent 71d0ee75d2
commit 3a55923da8
2 changed files with 14 additions and 3 deletions

View File

@ -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
----------------------------

View File

@ -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;