32 lines
1 KiB
Diff
32 lines
1 KiB
Diff
From: Karel Zak <kzak@redhat.com>
|
|
Date: Tue, 25 Mar 2025 12:14:14 +0100
|
|
Subject: cfdisk: fix memory leak and possible NULL dereference [gcc-analyzer]
|
|
|
|
Signed-off-by: Karel Zak <kzak@redhat.com>
|
|
(cherry picked from commit 33ca468b67d34dead8fb8b41dc9f328971e5fe70)
|
|
---
|
|
disk-utils/cfdisk.c | 4 +++-
|
|
1 file changed, 3 insertions(+), 1 deletion(-)
|
|
|
|
diff --git a/disk-utils/cfdisk.c b/disk-utils/cfdisk.c
|
|
index d0bb57a..e8a8b95 100644
|
|
--- a/disk-utils/cfdisk.c
|
|
+++ b/disk-utils/cfdisk.c
|
|
@@ -947,6 +947,7 @@ static void menu_set_title(struct cfdisk_menu *m, const char *title)
|
|
m->width = len + MENU_TITLE_PADDING;
|
|
str = xstrdup(title);
|
|
}
|
|
+ free(m->title);
|
|
m->title = str;
|
|
}
|
|
|
|
@@ -2173,7 +2174,8 @@ static int ui_create_label(struct cfdisk *cf)
|
|
nitems = fdisk_get_nlabels(cf->cxt);
|
|
cm = xcalloc(nitems + 1, sizeof(struct cfdisk_menuitem));
|
|
|
|
- while (fdisk_next_label(cf->cxt, &lb) == 0) {
|
|
+ while (fdisk_next_label(cf->cxt, &lb) == 0 && i < nitems) {
|
|
+
|
|
if (fdisk_label_is_disabled(lb) ||
|
|
fdisk_label_get_type(lb) == FDISK_DISKLABEL_BSD)
|
|
continue;
|