From 3de80ada6aac139e78958d74b61625179b760e4f Mon Sep 17 00:00:00 2001 From: Bogdan Pintea Date: Mon, 19 Feb 2018 21:18:02 +0100 Subject: [PATCH] add patch file against ujson4c library - fix a bug in UJObjectUnpack() function with assignment of output parameters ( https://github.com/esnme/ujson4c/issues/10 ) - fix a bug in UUJDecod() function with un-checked mem allocation ( https://github.com/esnme/ujson4c/issues/9 ) --- ujson4c.diff | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 ujson4c.diff diff --git a/ujson4c.diff b/ujson4c.diff new file mode 100644 index 00000000..32dd66e2 --- /dev/null +++ b/ujson4c.diff @@ -0,0 +1,70 @@ +diff --git a/src/ujdecode.c b/src/ujdecode.c +index 4b5a62d..161d909 100644 +--- a/src/ujdecode.c ++++ b/src/ujdecode.c +@@ -686,10 +686,10 @@ int UJObjectUnpack(UJObject objObj, int keys, const char *format, const wchar_t + int ki; + int ks = 0; + const wchar_t *keyNames[64]; +- va_list args; +- UJObject *outValue; ++ UJObject *outValues[64]; ++ va_list args; ++ UJObject *outValue; + +- va_start(args, _keyNames); + + if (!UJIsObject(objObj)) + { +@@ -703,10 +703,14 @@ int UJObjectUnpack(UJObject objObj, int keys, const char *format, const wchar_t + return -1; + } + ++ va_start(args, _keyNames); + for (ki = 0; ki < keys; ki ++) + { + keyNames[ki] = _keyNames[ki]; ++ outValue = va_arg(args, UJObject *); ++ outValues[ki] = outValue; + } ++ va_end(args); + + while (UJIterObject(&iter, &key, &value)) + { +@@ -731,12 +735,10 @@ int UJObjectUnpack(UJObject objObj, int keys, const char *format, const wchar_t + + found ++; + +- outValue = va_arg(args, UJObject); +- +- if (outValue != NULL) +- { +- *outValue = value; +- } ++ if (outValues[ki]) ++ { ++ *outValues[ki] = value; ++ } + keyNames[ki] = NULL; + + if (ki == ks) +@@ -746,7 +748,6 @@ int UJObjectUnpack(UJObject objObj, int keys, const char *format, const wchar_t + } + } + +- va_end(args); + + return found; + } +@@ -788,6 +789,11 @@ UJObject UJDecode(const char *input, size_t cbInput, UJHeapFuncs *hf, void **out + decoder.realloc = realloc; + cbInitialHeap = 16384; + initialHeap = malloc(cbInitialHeap); ++ ++ if (initialHeap == NULL) ++ { ++ return NULL; ++ } + } + else + {