summary refs log tree commit diff stats
path: root/tools
diff options
context:
space:
mode:
authorAndrey Makarov <ph.makarov@gmail.com>2021-06-17 09:19:52 +0300
committerGitHub <noreply@github.com>2021-06-17 08:19:52 +0200
commit969cb97c0a9f045a2fb31866fc804cdf1b2698dd (patch)
tree44cc838dbf79986aa694948d3bac742cc35705ff /tools
parent49e945ed082bacd5cd5ecff305ec47ff3a00f1c5 (diff)
downloadNim-969cb97c0a9f045a2fb31866fc804cdf1b2698dd.tar.gz
PCRE, nimgrep: add limit for buffer size (#18280)
Diffstat (limited to 'tools')
-rw-r--r--tools/nimgrep.nim5
1 files changed, 4 insertions, 1 deletions
diff --git a/tools/nimgrep.nim b/tools/nimgrep.nim
index a368c40ef..a589cfb14 100644
--- a/tools/nimgrep.nim
+++ b/tools/nimgrep.nim
@@ -649,7 +649,7 @@ template updateCounters(output: Output) =
 proc printInfo(filename:string, output: Output) =
   case output.kind
   of openError:
-    printError("can not open path " & filename & " " & output.msg)
+    printError("cannot open path '" & filename & "': " & output.msg)
   of rejected:
     if optVerbose in options:
       echo "(rejected: ", output.reason, ")"
@@ -719,6 +719,9 @@ iterator searchFile(pattern: Pattern; buffer: string): Output =
                      pre: pre,
                      match: move(curMi))
     i = t.last+1
+  when typeof(pattern) is Regex:
+    if buffer.len > MaxReBufSize:
+      yield Output(kind: openError, msg: "PCRE size limit is " & $MaxReBufSize)
 
 func detectBin(buffer: string): bool =
   for i in 0 ..< min(1024, buffer.len):