Skip to content
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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 46 additions & 1 deletion libmisc/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@
int i;
char **tmp;

assert (NULL != list);
if (NULL == list)
return NULL;

for (i = 0; NULL != list[i]; i++);

Expand All @@ -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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: const char **list ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this to match the signature of dup_list, but I don't really mind either way.

{
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
Expand Down Expand Up @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The 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);
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The 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;
}