Skip to content

Commit

Permalink
Fix minor memory check bug in pcre2test
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipHazel committed Jan 25, 2023
1 parent fa5ec50 commit 69d6b24
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 33,9 @@ milliseconds to microseconds. This is more useful for modern CPUs.
7. Applied PR #193, which makes the requirement for C99 explicit in
configure.ac and CMakeLists.txt.

8. Fixed a bug in pcre2test when a ridiculously large string repeat required a
stupid amount of memory. It now gives a clean realloc() failure error.


Version 10.42 11-December-2022
------------------------------
Expand Down
17 changes: 13 additions & 4 deletions src/pcre2test.c
Original file line number Diff line number Diff line change
Expand Up @@ -6839,11 6839,15 @@ extended if replication is involved). */
needlen = (size_t)((len 1) * code_unit_size);
if (dbuffer == NULL || needlen >= dbuffer_size)
{
while (needlen >= dbuffer_size) dbuffer_size *= 2;
while (needlen >= dbuffer_size)
{
if (dbuffer_size < SIZE_MAX/2) dbuffer_size *= 2;
else dbuffer_size = needlen 1;
}
dbuffer = (uint8_t *)realloc(dbuffer, dbuffer_size);
if (dbuffer == NULL)
{
fprintf(stderr, "pcre2test: realloc(%d) failed\n", (int)dbuffer_size);
fprintf(stderr, "pcre2test: realloc(%" SIZ_FORM ") failed\n", dbuffer_size);
exit(1);
}
}
Expand Down Expand Up @@ -6900,11 6904,16 @@ while ((c = *p ) != 0)
{
size_t qoffset = CAST8VAR(q) - dbuffer;
size_t rep_offset = start_rep - dbuffer;
while (needlen >= dbuffer_size) dbuffer_size *= 2;
while (needlen >= dbuffer_size)
{
if (dbuffer_size < SIZE_MAX/2) dbuffer_size *= 2;
else dbuffer_size = needlen 1;
}
dbuffer = (uint8_t *)realloc(dbuffer, dbuffer_size);
if (dbuffer == NULL)
{
fprintf(stderr, "pcre2test: realloc(%d) failed\n", (int)dbuffer_size);
fprintf(stderr, "pcre2test: realloc(%" SIZ_FORM ") failed\n",
dbuffer_size);
exit(1);
}
SETCASTPTR(q, dbuffer qoffset);
Expand Down

0 comments on commit 69d6b24

Please sign in to comment.