From e31096d7ed72659a89c08705c5ebe073bf99ae89 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 21 Mar 2021 16:51:09 -0700 Subject: [PATCH] Skip long arguments in syntax highlighting path detection When fish performs syntax highlighting, it attempts to determine which arguments are valid paths and underline them. Skip paths whose length exceeds PATH_MAX. This is an optimization: such strings are almost certainly not valid paths and checking them may be expensive. Relevant is #7837 (cherry picked from commit 8d54d2b60eae39ef7b5f5bc1a7ae83bc91703d95) --- src/highlight.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/highlight.cpp b/src/highlight.cpp index db07f3111..a1e432979 100644 --- a/src/highlight.cpp +++ b/src/highlight.cpp @@ -918,6 +918,11 @@ void highlighter_t::color_as_argument(const ast::node_t &node) { static bool range_is_potential_path(const wcstring &src, const source_range_t &range, const operation_context_t &ctx, const wcstring &working_directory) { + // Skip strings exceeding PATH_MAX. See #7837. + // Note some paths may exceed PATH_MAX, but this is just for highlighting. + if (range.length > PATH_MAX) { + return false; + } // Get the node source, unescape it, and then pass it to is_potential_path along with the // working directory (as a one element list). bool result = false;