Skip to content

Commit a6b8bfc

Browse files
committed
Fix memory error when a plain string argument is parsed.
Parsing memory, not added in CalcLen, is added in CheckMemory. Oups... last commit was buggy modified: storage/connect/jsonudf.cpp
1 parent d3dc52e commit a6b8bfc

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

storage/connect/jsonudf.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,15 +1414,23 @@ static my_bool CheckMemory(PGLOBAL g, UDF_INIT *initid, UDF_ARGS *args, uint n,
14141414
unsigned long rl, ml;
14151415
my_bool b = false;
14161416

1417-
n = MY_MIN(n, args->arg_count);
1417+
n = MY_MIN(n, args->arg_count);
14181418

14191419
for (uint i = 0; i < n; i++)
14201420
if (IsJson(args, i) == 2 ||
1421-
(b == (m && !i && args->arg_type[0] == STRING_RESULT && !IsJson(args, 0)))) {
1421+
(b = (m && !i && args->arg_type[0] == STRING_RESULT && !IsJson(args, 0)))) {
14221422
if (CalcLen(args, obj, rl, ml, mod))
14231423
return true;
1424-
else if (b)
1425-
ml += args->lengths[0] * M; // Was not done in CalcLen
1424+
else if (b) {
1425+
ulong len;
1426+
char *p = args->args[0];
1427+
1428+
// Is this a file name?
1429+
if (strchr("[{ \t\r\n", *p) || !(len = GetFileLength(p)))
1430+
len = args->lengths[0];
1431+
1432+
ml += len * M; // Was not done in CalcLen
1433+
} // endif b
14261434

14271435
if (ml > g->Sarea_Size) {
14281436
free(g->Sarea);
@@ -3813,8 +3821,6 @@ char *jfile_make(UDF_INIT *initid, UDF_ARGS *args, char *result,
38133821
} else if (initid->const_item)
38143822
g->N = 1;
38153823

3816-
PlugSubSet(g, g->Sarea, g->Sarea_Size);
3817-
38183824
if ((n = IsJson(args, 0)) == 3) {
38193825
// Get default file name and pretty
38203826
PBSON bsp = (PBSON)args->args[0];

0 commit comments

Comments
 (0)