Skip to contentSkip to conversation

libconfuse: patch CVE-2022-40320

PATCH New Ankur Tyagi 1 participant 1 message Oct 14, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libconfuse: patch CVE-2022-40320

From: Peter Marko <[email protected]>

Pick patch per [1] poiting to [2] pointing to [3].

[1] https://nvd.nist.gov/vuln/detail/CVE-2022-40320
[2] https://github.com/libconfuse/libconfuse/issues/163
[3] https://github.com/libconfuse/libconfuse/commit/d73777c2c3566fb2647727bb56d9a2295b81669b

(cherry picked from commit c048c0410133241b2cfbb3d2cbeb532afff99e58)
---
 .../libconfuse/files/CVE-2022-40320.patch     | 42 +++++++++++++++++++
 .../libconfuse/libconfuse_3.3.bb              |  5 ++-
 2 files changed, 46 insertions(+), 1 deletion(-)
 create mode 100755 meta-networking/recipes-support/libconfuse/files/CVE-2022-40320.patch
meta-networking/recipes-support/libconfuse/files/CVE-2022-40320.patch new file +42 -0
new file mode 100755
index 0000000000..52296b9c0f
@@ -0,0 +1,42 @@
+From d73777c2c3566fb2647727bb56d9a2295b81669b Mon Sep 17 00:00:00 2001
+From: Joachim Wiberg <[email protected]>
+Date: Fri, 2 Sep 2022 16:12:46 +0200
+Subject: [PATCH] Fix #163: unterminated username used with getpwnam()
+
+Signed-off-by: Joachim Wiberg <[email protected]>
+
+CVE: CVE-2022-40320
+Upstream-Status: Backport [https://github.com/libconfuse/libconfuse/commit/d73777c2c3566fb2647727bb56d9a2295b81669b]
+Signed-off-by: Peter Marko <[email protected]>
+---
+ src/confuse.c | 9 ++++++---
+ 1 file changed, 6 insertions(+), 3 deletions(-)
+
+diff --git a/src/confuse.c b/src/confuse.c
+index 6d1fdbd..05566b5 100644
+--- a/src/confuse.c
++++ b/src/confuse.c
+@@ -1872,17 +1872,20 @@ DLLIMPORT char *cfg_tilde_expand(const char *filename)
+ 			file = filename + 1;
+ 		} else {
+ 			/* ~user or ~user/path */
+-			char *user;
++			char *user; /* ~user or ~user/path */
++			size_t len;
+ 
+ 			file = strchr(filename, '/');
+ 			if (file == 0)
+ 				file = filename + strlen(filename);
+ 
+-			user = malloc(file - filename);
++			len = file - filename - 1;
++			user = malloc(len + 1);
+ 			if (!user)
+ 				return NULL;
+ 
+-			strncpy(user, filename + 1, file - filename - 1);
++			strncpy(user, &filename[1], len);
++			user[len] = 0;
+ 			passwd = getpwnam(user);
+ 			free(user);
+ 		}
meta-networking/recipes-support/libconfuse/libconfuse_3.3.bb +4 -1
index b8d0536eb3..9a339326ca 100644
@@ -3,7 +3,10 @@ LICENSE = "ISC"
 LIC_FILES_CHKSUM = "file://LICENSE;md5=42fa47330d4051cd219f7d99d023de3a"
 
 SRCREV = "a42aebf13db33afd575da6e63f55163d371f776d"
-SRC_URI = "git://github.com/libconfuse/libconfuse.git;branch=master;protocol=https"
+SRC_URI = " \
+    git://github.com/libconfuse/libconfuse.git;branch=master;protocol=https \
+    file://CVE-2022-40320.patch \
+"
 
 inherit autotools-brokensep pkgconfig gettext