Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/pcre2_convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -1215,9 +1215,11 @@ for (int i = 0; i < 2; i++)
/* Allocate memory for the buffer, with hidden space for an allocator at
the start. The next time round the loop runs the conversion for real. */

allocated = PRIV(memctl_malloc)(sizeof(pcre2_memctl) +
(*bufflenptr + 1)*PCRE2_CODE_UNIT_WIDTH, (pcre2_memctl *)ccontext);
if (allocated == NULL)
if (*bufflenptr > ((PCRE2_SIZE_MAX - sizeof(pcre2_memctl)) /
CU2BYTES(1)) - 1 ||
(allocated = PRIV(memctl_malloc)(sizeof(pcre2_memctl) +
CU2BYTES(*bufflenptr + 1),
(pcre2_memctl *)ccontext)) == NULL)
{
*bufflenptr = 0; /* Error offset */
return PCRE2_ERROR_NOMEMORY;
Expand Down
7 changes: 4 additions & 3 deletions src/pcre2_substring.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,10 @@ PCRE2_SIZE size;
PCRE2_UCHAR *yield;
rc = pcre2_substring_length_bynumber(match_data, stringnumber, &size);
if (rc < 0) return rc;
yield = PRIV(memctl_malloc)(sizeof(pcre2_memctl) +
(size + 1)*PCRE2_CODE_UNIT_WIDTH, (pcre2_memctl *)match_data);
if (yield == NULL) return PCRE2_ERROR_NOMEMORY;
if (size > ((PCRE2_SIZE_MAX - sizeof(pcre2_memctl)) / CU2BYTES(1)) - 1 ||
(yield = PRIV(memctl_malloc)(sizeof(pcre2_memctl) +
CU2BYTES(size + 1), (pcre2_memctl *)match_data)) == NULL)
return PCRE2_ERROR_NOMEMORY;
yield = (PCRE2_UCHAR *)(((char *)yield) + sizeof(pcre2_memctl));
if (size != 0) memcpy(yield, match_data->subject + match_data->ovector[stringnumber*2],
CU2BYTES(size));
Expand Down