pcre2/pcre2-10.30-Fix-pcre2grep-recursive-file-name-length-issue.patch

53 lines
1.6 KiB
Diff

From 386fd5ed13bd694a9940365602be6fcefd52d295 Mon Sep 17 00:00:00 2001
From: ph10 <ph10@6239d852-aaf2-0410-a92c-79f79f948069>
Date: Fri, 20 Oct 2017 16:51:59 +0000
Subject: [PATCH 1/2] Fix pcre2grep recursive file name length issue.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
git-svn-id: svn://vcs.exim.org/pcre2/code/trunk@873 6239d852-aaf2-0410-a92c-79f79f948069
Petr Písař: Ported to 10.30.
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;
--
2.13.6