-
Notifications
You must be signed in to change notification settings - Fork 234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
newsubgid: add deny_setgroups option to /etc/subgid #99
base: master
Are you sure you want to change the base?
Changes from all commits
fdfb3b9
4a43149
0d368da
b1a1af3
626af91
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -152,7 +152,8 @@ | |
int i; | ||
char **tmp; | ||
|
||
assert (NULL != list); | ||
if (NULL == list) | ||
return NULL; | ||
|
||
for (i = 0; NULL != list[i]; i++); | ||
|
||
|
@@ -169,6 +170,23 @@ | |
return tmp; | ||
} | ||
|
||
/* | ||
* Free a list. | ||
* The output list isn't modified, but the memory is freed. | ||
*/ | ||
void free_list (char *const *list) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did this to match the signature of |
||
{ | ||
int i; | ||
|
||
if (NULL == list) | ||
return; | ||
|
||
for (i = 0; NULL != list[i]; i++) | ||
free(list[i]); | ||
free((void *)list); | ||
} | ||
|
||
|
||
/* | ||
* Check if member is part of the input list | ||
* The input list is not modified, but in order to allow the use of this | ||
|
@@ -269,3 +287,30 @@ bool is_on_list (char *const *list, const char *member) | |
return array; | ||
} | ||
|
||
/* | ||
* comma_from_list - inverse of comma_to_list | ||
*/ | ||
|
||
/*@only@*/char *comma_from_list (char *const *list) | ||
{ | ||
char *comma; | ||
int i, commalen = 0; | ||
|
||
if (NULL == list) | ||
return NULL; | ||
|
||
for (i = 0; NULL != list[i]; i++) | ||
commalen += strlen(list[i]) + 1; | ||
|
||
comma = xmalloc(commalen + 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically +1 shouldn't be needed here right? Each entry is followed by either comma or \0, and you add +1 to the length of each entry as you add up. |
||
memset(comma, '\0', commalen + 1); | ||
|
||
for (i = 0; NULL != list[i]; i++) { | ||
int j = strlen(comma); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't really performance critical, but re-calculating j at each iteration here is unnecessary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, but you're using strncat which doesn't give you the printed length, I see :) |
||
if (j > 0) | ||
comma[j++] = ','; | ||
strncat(comma, list[i], commalen - j); | ||
} | ||
|
||
return comma; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iiuc this is a gnu extension, probably not safe for shadow to use, so please make it options ? options : ""