Skip to content

Commit

Permalink
FAPI: Fix segfault if json field is null.
Browse files Browse the repository at this point in the history
The function json_object_object_get_ex does not create a
json object for the parameter value in the case "key":null.
This caused a segfault in json deserialization.
Fixes: tpm2-software#2878

Signed-off-by: Juergen Repp <[email protected]>
  • Loading branch information
JuergenReppSIT committed Jul 31, 2024
1 parent ac930eb commit 82d8aab
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/tss2-fapi/tpm_json_deserialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,25 @@ ifapi_get_sub_object(json_object *jso, char *name, json_object **sub_jso)
{
int i;
if (json_object_object_get_ex(jso, name, sub_jso)) {
return true;
if (*sub_jso) {
return true;
} else {
return false;
}
} else {
char name2[strlen(name) + 1];
for (i = 0; name[i]; i++)
name2[i] = (char) tolower(name[i]);
name2[strlen(name)] = '\0';
return json_object_object_get_ex(jso, name2, sub_jso);
if (json_object_object_get_ex(jso, name2, sub_jso)) {
if (*sub_jso) {
return true;
} else {
return false;
}
} else {
return false;
}
}
}

Expand Down

0 comments on commit 82d8aab

Please sign in to comment.