Skip to content

Commit

Permalink
pcre2posix: fix crash on recent regerror code
Browse files Browse the repository at this point in the history
Since 0710ce2 (pcre2posix: avoid snprintf quirks in regerror (#333),
2023-11-15), a call for snprintf was replaced by a pair of strncpy
and buf[errbuf_size - 1] = 0, but it didn't account for the case
where errbuf_size == 0.

Make the code conditional to mimic the original logic and avoid
crashing.
  • Loading branch information
carenas committed Nov 16, 2023
1 parent 8575e36 commit bbd0fba
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/pcre2posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,11 @@ if (preg != NULL && (int)preg->re_erroffset != -1)
else
{
len = strlen(message);
strncpy(errbuf, message, errbuf_size);
if (errbuf_size <= len) errbuf[errbuf_size - 1] = '\0';
if (errbuf_size != 0)
{
strncpy(errbuf, message, errbuf_size);
if (errbuf_size <= len) errbuf[errbuf_size - 1] = '\0';
}
ret = (int)len;
}

Expand Down

0 comments on commit bbd0fba

Please sign in to comment.