From 378c6abdef5d500114ed720bff8f22f6f96d9def Mon Sep 17 00:00:00 2001 From: jinzhiguang Date: Thu, 13 Jun 2024 17:11:40 +0800 Subject: [PATCH] ldmtool: fix NULL pointer dereference Signed-off-by: jinzhiguang (cherry picked from commit f12db8f5cf015ce981c8e61c51fc321fa904bc4f) --- ...ldmtool-fix-NULL-pointer-dereference.patch | 47 +++++++++++++++++++ libldm.spec | 7 ++- 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 0001-ldmtool-fix-NULL-pointer-dereference.patch diff --git a/0001-ldmtool-fix-NULL-pointer-dereference.patch b/0001-ldmtool-fix-NULL-pointer-dereference.patch new file mode 100644 index 0000000..16b48b5 --- /dev/null +++ b/0001-ldmtool-fix-NULL-pointer-dereference.patch @@ -0,0 +1,47 @@ +From 674da9bd4f482cd5e07e3f8f4b648d366b2c23bb Mon Sep 17 00:00:00 2001 +From: Vincent Mailhol +Date: Tue, 20 Jun 2023 17:00:24 +0900 +Subject: [PATCH 1/1] ldmtool: fix NULL pointer dereference + +If /sys/block can not be opened, get_devices() returns NULL. + +cmdline() does not check this result and below code snippet: + + scanned = get_devices(); + devices = (gchar **) scanned->data; + +results in a segmentation fault. + +Add a check on scanned. + +Relevant logs: + + Unable to open /sys/block: No such file or directory + [ 0.777352] ldmtool[164]: segfault at 0 ip 0000563a225cd6a5 sp 00007ffe54965a60 error 4 in ldmtool[563a225cb000+3000] + [ 0.778278] Code: 18 64 48 33 1c 25 28 00 00 00 75 5e 48 83 c4 28 5b 5d 41 5c 41 5d 41 5e 41 5f c3 66 2e 0f 1f 84 00 00 00 00 00 e8 db fd ff ff <4c> 8b 20 48 89 44 24 08 4c 89 e7 e8 0b e1 ff ff 45 31 c0 4c 89 e1 + +Fixes: 25d9635e4ee5 ("Add ldmtool") +Signed-off-by: Vincent Mailhol +Reviewed-by: Laszlo Ersek +Acked-by: Richard W.M. Jones +See: https://listman.redhat.com/archives/libguestfs/2023-June/031841.html +--- + src/ldmtool.c | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/src/ldmtool.c b/src/ldmtool.c +index 6957c1a..dbe2c8c 100644 +--- a/src/ldmtool.c ++++ b/src/ldmtool.c +@@ -746,6 +746,8 @@ cmdline(LDM * const ldm, gchar **devices, + GArray * scanned = NULL; + if (!devices) { + scanned = get_devices(); ++ if (!scanned) ++ return FALSE; + devices = (gchar **) scanned->data; + } + +-- +2.27.0 + diff --git a/libldm.spec b/libldm.spec index 4786460..04d0661 100644 --- a/libldm.spec +++ b/libldm.spec @@ -1,11 +1,13 @@ Name: libldm Version: 0.2.5 -Release: 1 +Release: 2 Summary: A tool and library for managing Microsoft Windows Dynamic Disks License: LGPLv3+ and GPLv3+ URL: https://github.com/mdbooth/libldm Source0: https://github.com/mdbooth/libldm/archive/%{name}-%{version}.tar.gz +Patch0001: 0001-ldmtool-fix-NULL-pointer-dereference.patch + BuildRequires: autoconf, automake, libtool, glib2-devel >= 2.26.0, json-glib-devel >= 0.14.0 BuildRequires: device-mapper-devel >= 1.02, zlib-devel, libuuid-devel, readline-devel, gtk-doc @@ -56,6 +58,9 @@ autoreconf -i %{_mandir}/man*/* %changelog +* Thu Jun 13 2024 jinzhiguang - 0.2.5-2 +- ldmtool: fix NULL pointer dereference + * Mon Aug 22 2022 wangxiaomeng - 0.2.5-1 - Update version to 0.2.5