Commit 1b7eaf07 by Henrik Kjölhede

Added check against negative malloc and cleaned up comments

parent 3043883c
...@@ -106,6 +106,12 @@ static char **get_groupnames(void) ...@@ -106,6 +106,12 @@ static char **get_groupnames(void)
struct group *gr; struct group *gr;
ngroups = getgroups(0, NULL); ngroups = getgroups(0, NULL);
if (ngroups == -1) {
fprintf(stderr, "Failed to get number of groups user belongs to\n");
return NULL;
}
group_ids = (gid_t *)malloc(sizeof(gid_t)*ngroups); group_ids = (gid_t *)malloc(sizeof(gid_t)*ngroups);
ret = getgroups(ngroups, group_ids); ret = getgroups(ngroups, group_ids);
...@@ -242,11 +248,13 @@ static int get_alloted(char *me, char *intype, char *link, struct alloted_s **al ...@@ -242,11 +248,13 @@ static int get_alloted(char *me, char *intype, char *link, struct alloted_s **al
if (strcmp(link, br) != 0) if (strcmp(link, br) != 0)
continue; continue;
/* found the user with the appropriate settings, therefore finish the search.
* what to do if there are more than one applicable lines? not specified in the docs.
* since getline is implemented with realloc, we don't need to free line until exiting func.
*/
append_alloted(alloted, me, n); append_alloted(alloted, me, n);
count += n; count += n;
break; // found the user with the appropriate settings, therefore finish the search. break;
// what to do if there are more than one applicable lines? not specified in the docs.
// since getline is implemented with realloc, we don't need to free line until exiting func.
} }
// now parse any possible groups specified // now parse any possible groups specified
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment