From a6b8bfcafd71804244954ddd4f9cdd0fc4ba7e68 Mon Sep 17 00:00:00 2001 From: Olivier Bertrand Date: Sat, 5 Dec 2015 17:30:03 +0100 Subject: 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 --- storage/connect/jsonudf.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'storage') diff --git a/storage/connect/jsonudf.cpp b/storage/connect/jsonudf.cpp index f66c52139f9..4fa21b84224 100644 --- a/storage/connect/jsonudf.cpp +++ b/storage/connect/jsonudf.cpp @@ -1414,15 +1414,23 @@ static my_bool CheckMemory(PGLOBAL g, UDF_INIT *initid, UDF_ARGS *args, uint n, unsigned long rl, ml; my_bool b = false; - n = MY_MIN(n, args->arg_count); + n = MY_MIN(n, args->arg_count); for (uint i = 0; i < n; i++) if (IsJson(args, i) == 2 || - (b == (m && !i && args->arg_type[0] == STRING_RESULT && !IsJson(args, 0)))) { + (b = (m && !i && args->arg_type[0] == STRING_RESULT && !IsJson(args, 0)))) { if (CalcLen(args, obj, rl, ml, mod)) return true; - else if (b) - ml += args->lengths[0] * M; // Was not done in CalcLen + else if (b) { + ulong len; + char *p = args->args[0]; + + // Is this a file name? + if (strchr("[{ \t\r\n", *p) || !(len = GetFileLength(p))) + len = args->lengths[0]; + + ml += len * M; // Was not done in CalcLen + } // endif b if (ml > g->Sarea_Size) { free(g->Sarea); @@ -3813,8 +3821,6 @@ char *jfile_make(UDF_INIT *initid, UDF_ARGS *args, char *result, } else if (initid->const_item) g->N = 1; - PlugSubSet(g, g->Sarea, g->Sarea_Size); - if ((n = IsJson(args, 0)) == 3) { // Get default file name and pretty PBSON bsp = (PBSON)args->args[0]; -- cgit v1.2.1