Skip to content

Commit

Permalink
add patch file against ujson4c library
Browse files Browse the repository at this point in the history
- fix a bug in UJObjectUnpack() function with assignment of output
  parameters ( esnme/ujson4c#10 )
- fix a bug in UUJDecod() function with un-checked mem allocation
  ( esnme/ujson4c#9 )
  • Loading branch information
bpintea committed Feb 19, 2018
1 parent ccb0686 commit 4ee53fb
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions ujson4c.diff
Original file line number Diff line number Diff line change
@@ -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
{

0 comments on commit 4ee53fb

Please sign in to comment.