Skip to content

Commit

Permalink
eal: verify strdup return
Browse files Browse the repository at this point in the history
[ upstream commit 5821a384a4ca611e0f67786400b9f5b18f34a416 ]

Add verify strdup() return value logic.

Fixes: 293c53d ("eal: add telemetry callbacks")
Fixes: 0d0f478 ("eal/linux: add uevent parse and process")

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
  • Loading branch information
fengchengwen authored and bluca committed Mar 7, 2024
1 parent 0de12ca commit 10d9146
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
24 changes: 22 additions & 2 deletions lib/eal/common/eal_common_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ eal_save_args(int argc, char **argv)
if (strcmp(argv[i], "--") == 0)
break;
eal_args[i] = strdup(argv[i]);
if (eal_args[i] == NULL)
goto error;
}
eal_args[i++] = NULL; /* always finish with NULL */

Expand All @@ -234,13 +236,31 @@ eal_save_args(int argc, char **argv)

eal_app_args = calloc(argc - i + 1, sizeof(*eal_args));
if (eal_app_args == NULL)
return -1;
goto error;

for (j = 0; i < argc; j++, i++)
for (j = 0; i < argc; j++, i++) {
eal_app_args[j] = strdup(argv[i]);
if (eal_app_args[j] == NULL)
goto error;
}
eal_app_args[j] = NULL;

return 0;

error:
if (eal_app_args != NULL) {
i = 0;
while (eal_app_args[i] != NULL)
free(eal_app_args[i++]);
free(eal_app_args);
eal_app_args = NULL;
}
i = 0;
while (eal_args[i] != NULL)
free(eal_args[i++]);
free(eal_args);
eal_args = NULL;
return -1;
}
#endif

Expand Down
2 changes: 2 additions & 0 deletions lib/eal/linux/eal_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ dev_uev_parse(const char *buf, struct rte_dev_event *event, int length)
i += 14;
strlcpy(pci_slot_name, buf, sizeof(subsystem));
event->devname = strdup(pci_slot_name);
if (event->devname == NULL)
return -1;
}
for (; i < length; i++) {
if (*buf == '\0')
Expand Down

0 comments on commit 10d9146

Please sign in to comment.