MXS-1456: Fix crash on empty script value
If a script variable resolves to an empty string, the replacement attempt will fail with an out-of-memory error. The following realloc call will fail as it requires a positive value for the new size.
This commit is contained in:
@ -220,10 +220,12 @@ bool externcmd_substitute_arg(EXTERNCMD* cmd, const char* match, const char* rep
|
|||||||
size_t size_orig = strlen(cmd->argv[i]);
|
size_t size_orig = strlen(cmd->argv[i]);
|
||||||
size_t size_replace = strlen(replace);
|
size_t size_replace = strlen(replace);
|
||||||
size_t size = MXS_MAX(size_orig, size_replace);
|
size_t size = MXS_MAX(size_orig, size_replace);
|
||||||
char* dest = MXS_MALLOC(size);
|
char* dest;
|
||||||
if (dest)
|
|
||||||
|
if (size && (dest = MXS_MALLOC(size)))
|
||||||
{
|
{
|
||||||
mxs_pcre2_result_t rc = mxs_pcre2_substitute(re, cmd->argv[i], replace, &dest, &size);
|
mxs_pcre2_result_t rc = mxs_pcre2_substitute(re, cmd->argv[i], replace, &dest, &size);
|
||||||
|
|
||||||
switch (rc)
|
switch (rc)
|
||||||
{
|
{
|
||||||
case MXS_PCRE2_ERROR:
|
case MXS_PCRE2_ERROR:
|
||||||
|
Reference in New Issue
Block a user