Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ v3.0.4 - YYYY-MM-DD
- Fixed `ippValidateAttribute` not returning `false` for too-long URIs.
- Fixed a memory leak in `httpGetSecurity` when using GNU TLS.
- Fixed a memory leak in `cupsJWTImportString`.
- Fixed a buffer overflow in `cupsJSONExportString` when exporting a child
node.
- Fixed a bug in `cupsJWTExportString` with JSON output.


Expand Down
30 changes: 25 additions & 5 deletions cups/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ cupsJSONExportString(cups_json_t *json) // I - JSON root node

while (current)
{
if (current->parent && current->parent->value.child != current)
if (current != json && current->parent && current->parent->value.child != current)
length ++; // Comma or colon separator

switch (current->type)
Expand Down Expand Up @@ -295,6 +295,11 @@ cupsJSONExportString(cups_json_t *json) // I - JSON root node
// Descend
current = current->value.child;
}
else if (current == json)
{
// Done with the node being exported...
current = NULL;
}
else if (current->sibling)
{
// Visit sibling
Expand All @@ -306,7 +311,12 @@ cupsJSONExportString(cups_json_t *json) // I - JSON root node
current = current->parent;
while (current)
{
if (current->sibling)
if (current == json)
{
current = NULL;
break;
}
else if (current->sibling)
{
current = current->sibling;
break;
Expand Down Expand Up @@ -335,7 +345,7 @@ cupsJSONExportString(cups_json_t *json) // I - JSON root node

while (current)
{
if (current->parent && current->parent->value.child != current)
if (current != json && current->parent && current->parent->value.child != current)
{
// Add separator
if (current->type == CUPS_JTYPE_KEY || current->parent->type == CUPS_JTYPE_ARRAY)
Expand Down Expand Up @@ -443,7 +453,12 @@ cupsJSONExportString(cups_json_t *json) // I - JSON root node
else if (current->type == CUPS_JTYPE_OBJECT)
*ptr++ = '}';

if (current->sibling)
if (current == json)
{
// Done with the node being exported...
current = NULL;
}
else if (current->sibling)
{
// Visit sibling
current = current->sibling;
Expand All @@ -459,7 +474,12 @@ cupsJSONExportString(cups_json_t *json) // I - JSON root node
else if (current->type == CUPS_JTYPE_OBJECT)
*ptr++ = '}';

if (current->sibling)
if (current == json)
{
current = NULL;
break;
}
else if (current->sibling)
{
current = current->sibling;
break;
Expand Down
18 changes: 18 additions & 0 deletions cups/testjson.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,24 @@ main(int argc, // I - Number of command-line arguments
testEndMessage(false, "unable to load Unicode surrogate escapes");
}

testBegin("cupsJSONExportString(child object)");
if ((json = cupsJSONImportString("{\"a\":{\"b\":[1,2],\"c\":{\"d\":true}},\"e\":null}")) != NULL)
{
if ((s = cupsJSONExportString(cupsJSONFind(json, "a"))) == NULL)
testEndMessage(false, "%s", cupsGetErrorString());
else if (strcmp(s, "{\"b\":[1,2],\"c\":{\"d\":true}}"))
testEndMessage(false, "got '%s'", s);
else
testEndMessage(true, "%s", s);

free(s);
cupsJSONDelete(json);
}
else
{
testEndMessage(false, "%s", cupsGetErrorString());
}

testBegin("cupsJSONImportURL('https://accounts.google.com/.well-known/openid-configuration', no last modified)");
json = cupsJSONImportURL("https://accounts.google.com/.well-known/openid-configuration", &last_modified);

Expand Down
Loading