mirror of
https://git.openafs.org/openafs.git
synced 2025-01-18 15:00:12 +00:00
cmd: Assert that *alloc() returns success
Several static analysis tools have identified various problems: - missing checks to ensure *alloc was successful (infer) To resolve the above problems: - Add asserts to verify that the *alloc was successful before using the memory. This commit is a reorganization of commits developed by Pat Riehecky, who ran the static analysis tools and developed the fixes. Note: Most of the callers to cmd_AddParmAlias and cmd_OptionAsList do not check the returned value, so asserts are used instead of returning ENOMEM. Change-Id: Ic44f6d34240c13c2626567f9d698d2480d2e8672 Reviewed-on: https://gerrit.openafs.org/14680 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
This commit is contained in:
parent
3d2e66c179
commit
f987feab84
@ -620,7 +620,9 @@ cmd_AddParmAlias(struct cmd_syndesc *as, int pos, char *alias)
|
||||
return CMD_EXCESSPARMS;
|
||||
|
||||
item = calloc(1, sizeof(struct cmd_item));
|
||||
assert(item != NULL);
|
||||
item->data = strdup(alias);
|
||||
assert(item->data != NULL);
|
||||
item->next = as->parms[pos].aliases;
|
||||
as->parms[pos].aliases = item;
|
||||
|
||||
@ -1445,8 +1447,10 @@ cmd_OptionAsList(struct cmd_syndesc *syn, int pos, struct cmd_item **value)
|
||||
start = str;
|
||||
while ((end = strchr(start, ' '))) {
|
||||
item = calloc(1, sizeof(struct cmd_item));
|
||||
assert(item != NULL);
|
||||
len = end - start + 1;
|
||||
item->data = malloc(len);
|
||||
assert(item->data != NULL);
|
||||
strlcpy(item->data, start, len);
|
||||
*last = item;
|
||||
last = &item->next;
|
||||
@ -1456,8 +1460,10 @@ cmd_OptionAsList(struct cmd_syndesc *syn, int pos, struct cmd_item **value)
|
||||
/* Catch the final element */
|
||||
if (*start != '\0') {
|
||||
item = calloc(1, sizeof(struct cmd_item));
|
||||
assert(item != NULL);
|
||||
len = strlen(start) + 1;
|
||||
item->data = malloc(len);
|
||||
assert(item->data != NULL);
|
||||
strlcpy(item->data, start, len);
|
||||
*last = item;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user