Skip to content

Commit 5159be8

Browse files
authored
Merge commit from fork
Completes the buffer-overflow fix from #87, which bounded writes into `pcre_str` but left the initial `strcpy` of `pattern` into `l_pattern` at the top of `ec_glob` unguarded. Sufficiently long patterns smash the stack before any of the bounds-checked code runs. Fix CVE-2026-40489
1 parent b4724e4 commit 5159be8

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/lib/ec_glob.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,12 @@ int ec_glob(const char *pattern, const char *string)
9696
_Bool are_braces_paired = 1;
9797
UT_array * nums; /* number ranges */
9898
int ret = 0;
99+
size_t pattern_len = strlen(pattern);
99100

100-
strcpy(l_pattern, pattern);
101+
/* Reject patterns that would overflow l_pattern in the copy below. */
102+
if (pattern_len >= sizeof(l_pattern))
103+
return -1;
104+
memcpy(l_pattern, pattern, pattern_len + 1);
101105
p_pcre = pcre_str + 1;
102106
pcre_str_end = pcre_str + 2 * PATTERN_MAX;
103107

0 commit comments

Comments
 (0)