fix potential null pointer dereference.

Signed-off-by: wangzhiqiang <wangzhiqiang95@huawei.com>
This commit is contained in:
wangzhiqiang
2023-02-10 15:02:23 +08:00
parent 4fc619853d
commit ec0efe7068
10 changed files with 110 additions and 5 deletions

View File

@@ -80,13 +80,19 @@ static int token_add(
r = -EINVAL;
jobj = json_object_new_object();
if (!jobj)
if (!jobj) {
r = -ENOMEM;
goto out;
}
/* type is mandatory field in all tokens and must match handler name member */
json_object_object_add(jobj, "type", json_object_new_string(TOKEN_NAME));
jobj_keyslots = json_object_new_array();
if (!jobj_keyslots) {
r = -ENOMEM;
goto out;
}
/* mandatory array field (may be empty and assigned later */
json_object_object_add(jobj, "keyslots", jobj_keyslots);