From eaf9751f5dce3a91368ffd99bccc978d5812e4fb Mon Sep 17 00:00:00 2001 From: Toomas Soome Date: Tue, 29 Nov 2022 13:52:50 +0200 Subject: 9293 bootadm: empty line between boot entries in menu.lst cause bootadm list-menu to segfault Reviewed by: Andrew Stormont Approved by: Dan McDonald --- usr/src/cmd/boot/bootadm/bootadm_loader.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/usr/src/cmd/boot/bootadm/bootadm_loader.c b/usr/src/cmd/boot/bootadm/bootadm_loader.c index e2d99b24b0..2d15fdbc42 100644 --- a/usr/src/cmd/boot/bootadm/bootadm_loader.c +++ b/usr/src/cmd/boot/bootadm/bootadm_loader.c @@ -325,29 +325,34 @@ menu_read(struct menu_lst *menu, char *menu_path) ret = BAM_ERROR; goto done; } + if (buf[0] == '\n') /* Skip empty lines */ + continue; + key = strtok(buf, " \n"); - if (strcmp(key, "title") != 0) { + if (key == NULL || strcmp(key, "title") != 0) { ret = BAM_ERROR; goto done; } value = strtok(NULL, " \n"); - if ((title = strdup(value)) == NULL) { + if (value == NULL || (title = strdup(value)) == NULL) { ret = BAM_ERROR; goto done; } - if (fgets(buf, PATH_MAX, fp) == NULL) { - ret = BAM_ERROR; - goto done; - } + do { + if (fgets(buf, PATH_MAX, fp) == NULL) { + ret = BAM_ERROR; + goto done; + } + } while (buf[0] == '\n'); /* Skip empty lines */ key = strtok(buf, " \n"); - if ((type = strdup(key)) == NULL) { + if (key == NULL || (type = strdup(key)) == NULL) { ret = BAM_ERROR; goto done; } value = strtok(NULL, " \n"); - if ((bootfs = strdup(value)) == NULL) { + if (value == NULL || (bootfs = strdup(value)) == NULL) { ret = BAM_ERROR; goto done; } -- cgit v1.2.3