Skip to content

Commit 1dd1c3d

Browse files
fix invalid JSON when OSADL lookup matches structural key
osadl_print_license() extracted the object between the first '{' and first '}' after a matched key, assuming a flat license entry. When a license token collided with a structural key (e.g. the top-level "licenses" key whose value holds nested objects), the first '}' closed an inner object, emitting an unbalanced '{' and breaking the JSON output. Guard against a missing '{' and reject matches whose object contains a nested '{', so only flat per-license entries are emitted.
1 parent 0e1913e commit 1dd1c3d

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

‎src/license.c‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,18 @@ int osadl_print_license(char *output, const char *license, bool more_keys_after)
244244
if (!content)
245245
return 0;
246246

247-
content = strchr(content, '{') + 1;
248-
if (content)
247+
char *open = strchr(content, '{');
248+
if (!open)
249+
return 0;
250+
content = open + 1;
249251
{
250252
char *end = strchr(content, '}');
253+
/* Only accept flat license entries: if the object contains a nested
254+
object, this key is a structural one (e.g. the top-level "licenses"
255+
key), not a per-license entry, and copying it would emit unbalanced
256+
braces and break the JSON. */
257+
if (end && memchr(content, '{', end - content))
258+
return 0;
251259
if (end)
252260
{
253261
int key_len = end - content;

0 commit comments

Comments
 (0)