Changeset 570 for trunk/src/sh_static.c
- Timestamp:
- Sep 5, 2021, 12:40:51 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/sh_static.c
r552 r570 464 464 { 465 465 FILE *grf; 466 gid_t *group_list; 467 int num_groups, rv; 466 gid_t *group_list = NULL; 467 size_t num_groups; 468 int rv; 468 469 char **m; 469 470 struct group group; … … 474 475 475 476 /* We alloc space for 8 gids at a time. */ 476 if ( ((group_list = calloc(8,sizeof(gid_t *))) != NULL)477 if (buff && ((group_list = calloc(8,sizeof(gid_t *))) != NULL) 477 478 && ((grf = fopen(_PATH_GROUP, "r")) != NULL) 478 479 ) { … … 489 490 if (!strcmp(*m, user)) { 490 491 if (!(num_groups & 7)) { 491 gid_t *tmp = (gid_t *) 492 realloc(group_list, 493 (num_groups+8) * sizeof(gid_t *)); 494 if (!tmp) { 495 rv = -1; 496 goto DO_CLOSE; 497 } 498 group_list = tmp; 492 gid_t *tmp = NULL; 493 if (num_groups > (SIZE_MAX - 8)) { 494 rv = -1; 495 goto DO_CLOSE; 496 } 497 if ((num_groups+8) <= (SIZE_MAX / sizeof(gid_t *))) { 498 tmp = (gid_t *) 499 realloc(group_list, 500 (num_groups+8) * sizeof(gid_t *)); 501 } 502 if (!tmp) { 503 rv = -1; 504 goto DO_CLOSE; 505 } 506 group_list = tmp; 499 507 } 500 508 group_list[num_groups++] = group.gr_gid; … … 512 520 /* group_list will be NULL if initial malloc failed, which may trigger 513 521 * warnings from various malloc debuggers. */ 514 free(group_list); 515 free(buff); 522 if (group_list) free(group_list); 523 if (buff) free(buff); 524 /* cppcheck-suppress resourceLeak */ 516 525 return rv; 517 526 }
Note:
See TracChangeset
for help on using the changeset viewer.