mirror of
https://github.com/stefanberger/swtpm.git
synced 2026-08-20 10:10:30 +00:00
swtpm_setup: Handle case when returned profile Name is null
The profile '{"Name": null}' will not lead to a parser error but return
NULL for the 'Name'. Therefore, check for variable name being a NULL
pointer. Since the user may provide this type of profile this could have
lead to crashes when name was accessed.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
This commit is contained in:
parent
e02bf61a22
commit
fcda38b463
@ -97,8 +97,13 @@ int check_json_profile(const gchar *swtpm_capabilities_json, const char *json_pr
|
||||
int ret;
|
||||
|
||||
ret = json_get_map_value(json_profile, "Name", &name);
|
||||
if (ret)
|
||||
/* { "Name": null } does not lead to parser failure but return name = NULL */
|
||||
if (ret || name == NULL) {
|
||||
ret = 1;
|
||||
logerr(gl_LOGFILE, "Failed to get 'Name' from profile '%s'.\n",
|
||||
json_profile);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (strlen(name) > 32) {
|
||||
logerr(gl_LOGFILE, "Profile name must not exceed 32 characters.\n");
|
||||
|
||||
@ -474,6 +474,7 @@ int json_get_map_value(const char *json_input, const char *field_name,
|
||||
goto error_unref_jr;
|
||||
}
|
||||
*value = g_strdup(json_reader_get_string_value(jr));
|
||||
/* caller should handle *value == NULL */
|
||||
|
||||
ret = 0;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user