libsepol: simplify string copying

Use strdup(3) instead of allocating memory and then manually copying the
content.

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
Acked-by: James Carter <jwcart2@gmail.com>
This commit is contained in:
Christian Göttsche 2022-11-09 21:09:39 +01:00 committed by James Carter
parent aaaed69911
commit 06df377829

View File

@ -776,12 +776,11 @@ static int roles_init(policydb_t * p)
rc = -ENOMEM;
goto out;
}
key = malloc(strlen(OBJECT_R) + 1);
key = strdup(OBJECT_R);
if (!key) {
rc = -ENOMEM;
goto out_free_role;
}
strcpy(key, OBJECT_R);
rc = symtab_insert(p, SYM_ROLES, key, role,
(p->policy_type ==
POLICY_MOD ? SCOPE_REQ : SCOPE_DECL), 1,