Copy capabilities list before strtok_r

With this fix /proc/<pid>/cmdline is preserved.
This commit is contained in:
Davide Berardi 2016-11-26 16:17:48 +01:00
parent cb80692707
commit 9eb9a87150
1 changed files with 7 additions and 1 deletions

View File

@ -55,8 +55,14 @@ int capset_from_namelist(char *namelist, uint64_t *capset) {
char *onecap;
char *tmptok;
char *spacetok;
size_t namelistlen = strlen(namelist) + 1;
char namelist_cpy[namelistlen];
char *namelist_ptr = namelist_cpy;
*capset = 0;
for (; (onecap = strtok_r(namelist,",",&tmptok)) != NULL; namelist = NULL)
strncpy(namelist_ptr, namelist, namelistlen);
for (; (onecap = strtok_r(namelist_ptr,",",&tmptok)) != NULL; namelist_ptr = NULL)
rv |= addcap(strtok_r(onecap," \t",&spacetok), capset);
return rv;
}