Anastasia Klimchuk submitted this change.

View Change


Approvals: build bot (Jenkins): Verified David Hendricks: Looks good to me, approved Angel Pons: Looks good to me, approved Anastasia Klimchuk: Looks good to me, approved
layout: Check return values for strdup in register_include_arg

strdup return values should be checked for NULL to catch the
potential error case of out of memory.

This patch re-writes ternary conditionals so that strdup return
values could be checked for all branches fof execution.

Follow up on
commit 45d50a101e8073191e6d88143990ed91d3bfe815

Ticket: https://ticket.coreboot.org/issues/372

Original-Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Original-Reviewed-on: https://review.coreboot.org/c/flashrom/+/70006
Original-Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Original-Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Original-Reviewed-by: David Hendricks <david.hendricks@gmail.com>
Original-Reviewed-by: Angel Pons <th3fanbus@gmail.com>
(cherry picked from commit 59ce5615b768fe9d4d2506cb13c6781cd83a12e6)

Change-Id: I6c22196be6847a8c9704f1de936604a51b4b8a28
Signed-off-by: Evan Benn <evanbenn@google.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/70322
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-by: David Hendricks <david.hendricks@gmail.com>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
---
M layout.c
1 file changed, 51 insertions(+), 3 deletions(-)

diff --git a/layout.c b/layout.c
index be88428..a1bb147 100644
--- a/layout.c
+++ b/layout.c
@@ -120,7 +120,7 @@
struct layout_include_args *tmp;
char *colon;
char *name;
- char *file;
+ char *file = NULL; /* file is optional, so defaults to NULL */

if (arg == NULL) {
msg_gerr("<NULL> is a bad region name.\n");
@@ -133,8 +133,22 @@
msg_gerr("Missing filename parameter in %s\n", arg);
return 1;
}
- name = colon ? strndup(arg, colon - arg) : strdup(arg);
- file = colon ? strdup(colon + 1) : NULL;
+
+ if (colon) {
+ name = strndup(arg, colon - arg);
+ if (!name) {
+ msg_gerr("Out of memory");
+ goto error;
+ }
+
+ file = strdup(colon + 1);
+ if (!file) {
+ msg_gerr("Out of memory");
+ goto error;
+ }
+ } else {
+ name = strdup(arg);
+ }

for (tmp = *args; tmp; tmp = tmp->next) {
if (!strcmp(tmp->name, name)) {

To view, visit change 70322. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: 1.3.x
Gerrit-Change-Id: I6c22196be6847a8c9704f1de936604a51b4b8a28
Gerrit-Change-Number: 70322
Gerrit-PatchSet: 3
Gerrit-Owner: Evan Benn <evanbenn@google.com>
Gerrit-Reviewer: Anastasia Klimchuk <aklm@chromium.org>
Gerrit-Reviewer: Angel Pons <th3fanbus@gmail.com>
Gerrit-Reviewer: David Hendricks <david.hendricks@gmail.com>
Gerrit-Reviewer: build bot (Jenkins) <no-reply@coreboot.org>
Gerrit-CC: Edward O'Callaghan <quasisec@chromium.org>
Gerrit-MessageType: merged