File: cfdisk-fix-memory-leak-and-possible-NULL-dereference-gcc-.patch

package info (click to toggle)
util-linux 2.41-5
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 95,208 kB
  • sloc: ansic: 179,016; sh: 22,689; yacc: 1,284; makefile: 528; xml: 422; python: 316; lex: 89; ruby: 75; csh: 37; exp: 19; sed: 16; perl: 15; sql: 9
file content (32 lines) | stat: -rw-r--r-- 1,072 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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;