Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FAPI: Fix segfault if json field is null. #2880

Merged
Merged
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
16 changes: 14 additions & 2 deletions src/tss2-fapi/tpm_json_deserialize.c
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (*sub_jso) {
    return true;
} else {
    return false;
}

could be simplified to:

return (*sub_jso);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could give some static code analysis alarms.

return !!(*sub_jso);

might however work.
But I also don't mind the explicit version.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice solution return !!(*sub_jso); but i would prefer the explicit version. @AndreasFuchsTPM could you please approve the PR.

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
Loading