-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add patch file against ujson4c library
- 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
Showing
1 changed file
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ |