Fix a NULL pointer dereference, reported by the Coverity tool:
CID 321267 (#1 of 1): Dereference null return value (NULL_RETURNS)6.
dereference: Dereferencing a pointer that might be NULL scope when
calling strlen.
check for the return value from strstr(), before dereferencing it.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
ret = cgroup_create_scope2(cg, 0, &opts);
if (!ret && set_default) {
scope = strstr(cg->name, "/");
+ if (!scope) {
+ err("%s: Invalid scope name %s, expected <slice>/<scope>\n",
+ prog_name, cg->name);
+ ret = ECGINVAL;
+ goto err;
+ }
len = strlen(cg->name) - strlen(scope);
strncpy(slice, cg->name, len);
slice[len] = '\0';