Skip to contentSkip to conversation

gawk: Fix CVE-2026-40467

PATCH In review Darsh Kelaiya -X (dkelaiya - E INFOCHIPS PRIVATE LIMITED at Cisco) 2 participants 8 messages Jul 22

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 gawk: Fix CVE-2026-40467

From: Darsh Kelaiya <[email protected]>

This patch applies the upstream fix as referenced in [2], using the commit shown in [1].

[1] https://cgit.git.savannah.gnu.org/cgit/gawk.git/commit/?id=a2d18c74109e41bec29a23098eba2e00057286d8
[2] https://nvd.nist.gov/vuln/detail/CVE-2026-40467

---
 .../gawk/gawk/CVE-2026-40467.patch            | 63 +++++++++++++++++++
 meta/recipes-extended/gawk/gawk_5.3.0.bb      |  1 +
 2 files changed, 64 insertions(+)
 create mode 100644 meta/recipes-extended/gawk/gawk/CVE-2026-40467.patch
meta/recipes-extended/gawk/gawk/CVE-2026-40467.patch new file +63 -0
new file mode 100644
index 0000000000..d813db5f8b
@@ -0,0 +1,63 @@
+From 22fd9e360251f70b34e9b46635b6d75bce49202f Mon Sep 17 00:00:00 2001
+From: "Arnold D. Robbins" <[email protected]>
+Date: Fri, 3 Apr 2026 12:02:11 +0300
+Subject: [PATCH] Small memory management fix in io.c.
+
+CVE: CVE-2026-40467
+Upstream-Status: Backport [https://cgit.git.savannah.gnu.org/cgit/gawk.git/commit/?id=a2d18c74109e41bec29a23098eba2e00057286d8]
+
+(cherry picked from commit a2d18c74109e41bec29a23098eba2e00057286d8)
+Signed-off-by: Darsh Kelaiya <[email protected]>
+---
+ ChangeLog | 6 ++++++
+ io.c      | 5 ++++-
+ 2 files changed, 10 insertions(+), 1 deletion(-)
+
+diff --git a/ChangeLog b/ChangeLog
+index 2fa8b2f0..6bc88ebb 100644
+--- a/ChangeLog
++++ b/ChangeLog
+@@ -1,3 +1,9 @@
++2026-04-03         Arnold D. Robbins     <[email protected]>
++
++	* io.c (do_getline_redir): Don't DEREF redir_exp too early.
++	Thanks to Michał Majchrowicz <[email protected]>
++	for the report.
++
+ 2023-11-02         Arnold D. Robbins     <[email protected]>
+ 
+ 	* 5.3.0: Release tar ball made.
+diff --git a/io.c b/io.c
+index 44671ebd..4db4b21d 100644
+--- a/io.c
++++ b/io.c
+@@ -2836,22 +2836,25 @@ do_getline_redir(int into_variable, enum redirval redirtype)
+ 	assert(redirtype != redirect_none);
+ 	redir_exp = TOP();
+ 	rp = redirect(redir_exp, redirtype, & redir_error, false);
+-	DEREF(redir_exp);
+ 	decr_sp();
+ 	if (rp == NULL) {
+ 		if (redir_error) { /* failed redirect */
+ 			if (! do_traditional)
+ 				update_ERRNO_int(redir_error);
+ 		}
++		DEREF(redir_exp);
+ 		return make_number((AWKNUM) -1.0);
+ 	} else if ((rp->flag & RED_TWOWAY) != 0 && rp->iop == NULL) {
+ 		if (is_non_fatal_redirect(redir_exp->stptr, redir_exp->stlen)) {
+ 			update_ERRNO_int(EBADF);
++			DEREF(redir_exp);
+ 			return make_number((AWKNUM) -1.0);
+ 		}
+ 		(void) close_rp(rp, CLOSE_ALL);
++		DEREF(redir_exp);	// we're about to die, but what the heck, release it anyway
+ 		fatal(_("getline: attempt to read from closed read end of two-way pipe"));
+ 	}
++	DEREF(redir_exp);
+ 	iop = rp->iop;
+ 	if (iop == NULL)		/* end of input */
+ 		return make_number((AWKNUM) 0.0);
+-- 
+2.44.4
+
meta/recipes-extended/gawk/gawk_5.3.0.bb +1 -0
index b1d1fe7ae4..56d7d7f76a 100644
@@ -22,6 +22,7 @@ SRC_URI = "${GNU_MIRROR}/gawk/gawk-${PV}.tar.gz \
            file://0001-m4-readline-add-missing-includes.patch \
            file://run-ptest \
            file://0001-Fix-some-C23-compilatio-issues.patch \
+           file://CVE-2026-40467.patch \
            "
 
 SRC_URI[sha256sum] = "378f8864ec21cfceaa048f7e1869ac9b4597b449087caf1eb55e440d30273336"
Signature · 1 line
2.35.6
#1 lore raw

PATCH 2/4 gawk: Fix CVE-2026-40468

From: Darsh Kelaiya <[email protected]>

This patch applies the upstream fix as referenced in [2], using the commit shown in [1].

[1] https://cgit.git.savannah.gnu.org/cgit/gawk.git/commit/?id=062f2f2581b991362c046f7f2e238ffa34e6f8c7
[2] https://nvd.nist.gov/vuln/detail/CVE-2026-40468

---
 .../gawk/gawk/CVE-2026-40468.patch            | 65 +++++++++++++++++++
 meta/recipes-extended/gawk/gawk_5.3.0.bb      |  1 +
 2 files changed, 66 insertions(+)
 create mode 100644 meta/recipes-extended/gawk/gawk/CVE-2026-40468.patch
meta/recipes-extended/gawk/gawk/CVE-2026-40468.patch new file +65 -0
new file mode 100644
index 0000000000..607f641615
@@ -0,0 +1,65 @@
+From e281dfa04afc4660419ad69c9f24bc6b4067f8d8 Mon Sep 17 00:00:00 2001
+From: "Arnold D. Robbins" <[email protected]>
+Date: Sat, 4 Apr 2026 21:45:58 +0300
+Subject: [PATCH] Minor integer overflow fixes.
+
+CVE: CVE-2026-40468
+Upstream-Status: Backport [https://cgit.git.savannah.gnu.org/cgit/gawk.git/commit/?id=062f2f2581b991362c046f7f2e238ffa34e6f8c7]
+
+Backport Changes:
+- Adapt the parse_escape() type change for gawk 5.3.0, where i is
+  declared int instead of long.
+
+(cherry picked from commit 062f2f2581b991362c046f7f2e238ffa34e6f8c7)
+Signed-off-by: Darsh Kelaiya <[email protected]>
+---
+ ChangeLog | 8 ++++++++
+ builtin.c | 2 +-
+ node.c    | 2 +-
+ 3 files changed, 10 insertions(+), 2 deletions(-)
+
+diff --git a/ChangeLog b/ChangeLog
+index 6bc88ebb..e691b241 100644
+--- a/ChangeLog
++++ b/ChangeLog
+@@ -1,3 +1,11 @@
++2026-04-04         Arnold D. Robbins     <[email protected]>
++
++	* builtin.c (do_sub): Make `sofar' be size_t to avoid
++	integer overflows.  Thanks to Michał Majchrowicz
++	<[email protected]> for the report.
++	* node.c (parse_escape): Change `i' to int64_t to avoid
++	overflows. Thanks to ASan with gcc -m32.
++
+ 2026-04-03         Arnold D. Robbins     <[email protected]>
+ 
+ 	* io.c (do_getline_redir): Don't DEREF redir_exp too early.
+diff --git a/builtin.c b/builtin.c
+index ba3459db..80ab6069 100644
+--- a/builtin.c
++++ b/builtin.c
+@@ -2985,7 +2985,7 @@ do_sub(int nargs, unsigned int flags)
+ 	char *repl;
+ 	char *replend;
+ 	size_t repllen;
+-	int sofar;
++	size_t sofar;
+ 	int ampersands;
+ 	int matches = 0;
+ 	Regexp *rp;
+diff --git a/node.c b/node.c
+index f08a57d7..12a8fab4 100644
+--- a/node.c
++++ b/node.c
+@@ -571,7 +571,7 @@ parse_escape(const char **string_ptr, const char **result, size_t *nbytes)
+ 	static char buf[MB_LEN_MAX];
+ 	enum escape_results retval = ESCAPE_OK;
+ 	int c = *(*string_ptr)++;
+-	int i;
++	int64_t i;
+ 	int count;
+ 	int j;
+ 	const char *start;
+-- 
+2.44.4
+
meta/recipes-extended/gawk/gawk_5.3.0.bb +1 -0
index 56d7d7f76a..d79b0222a6 100644
@@ -23,6 +23,7 @@ SRC_URI = "${GNU_MIRROR}/gawk/gawk-${PV}.tar.gz \
            file://run-ptest \
            file://0001-Fix-some-C23-compilatio-issues.patch \
            file://CVE-2026-40467.patch \
+           file://CVE-2026-40468.patch \
            "
 
 SRC_URI[sha256sum] = "378f8864ec21cfceaa048f7e1869ac9b4597b449087caf1eb55e440d30273336"
Signature · 1 line
2.35.6
Reviewed-by on v1 2/4
#2 lore raw

Re: [OE-core][scarthgap][PATCH 2/4] gawk: Fix CVE-2026-40468

Looks good to me.

________________________________
From: [email protected] <[email protected]> on behalf of Darsh Kelaiya -X (dkelaiya - E INFOCHIPS PRIVATE LIMITED at Cisco) via lists.openembedded.org <[email protected]>
Sent: Wednesday, July 22, 2026 11:56 AM
To: [email protected] <[email protected]>
Cc: [email protected] <[email protected]>; Darsh Kelaiya <[email protected]>
Subject: [OE-core][scarthgap][PATCH 2/4] gawk: Fix CVE-2026-40468

From: Darsh Kelaiya <[email protected]>

This patch applies the upstream fix as referenced in [2], using the commit shown in [1].

[1] https://cgit.git.savannah.gnu.org/cgit/gawk.git/commit/?id=062f2f2581b991362c046f7f2e238ffa34e6f8c7
[2] https://nvd.nist.gov/vuln/detail/CVE-2026-40468

---
 .../gawk/gawk/CVE-2026-40468.patch            | 65 +++++++++++++++++++
 meta/recipes-extended/gawk/gawk_5.3.0.bb      |  1 +
 2 files changed, 66 insertions(+)
 create mode 100644 meta/recipes-extended/gawk/gawk/CVE-2026-40468.patch
meta/recipes-extended/gawk/gawk/CVE-2026-40468.patch new file +65 -0
new file mode 100644
index 0000000000..607f641615
@@ -0,0 +1,65 @@
+From e281dfa04afc4660419ad69c9f24bc6b4067f8d8 Mon Sep 17 00:00:00 2001
+From: "Arnold D. Robbins" <[email protected]>
+Date: Sat, 4 Apr 2026 21:45:58 +0300
+Subject: [PATCH] Minor integer overflow fixes.
+
+CVE: CVE-2026-40468
+Upstream-Status: Backport [https://cgit.git.savannah.gnu.org/cgit/gawk.git/commit/?id=062f2f2581b991362c046f7f2e238ffa34e6f8c7]
+
+Backport Changes:
+- Adapt the parse_escape() type change for gawk 5.3.0, where i is
+  declared int instead of long.
+
+(cherry picked from commit 062f2f2581b991362c046f7f2e238ffa34e6f8c7)
+Signed-off-by: Darsh Kelaiya <[email protected]>
+---
+ ChangeLog | 8 ++++++++
+ builtin.c | 2 +-
+ node.c    | 2 +-
+ 3 files changed, 10 insertions(+), 2 deletions(-)
+
+diff --git a/ChangeLog b/ChangeLog
+index 6bc88ebb..e691b241 100644
+--- a/ChangeLog
++++ b/ChangeLog
+@@ -1,3 +1,11 @@
++2026-04-04         Arnold D. Robbins     <[email protected]>
++
++      * builtin.c (do_sub): Make `sofar' be size_t to avoid
++      integer overflows.  Thanks to Michał Majchrowicz
++      <[email protected]> for the report.
++      * node.c (parse_escape): Change `i' to int64_t to avoid
++      overflows. Thanks to ASan with gcc -m32.
++
+ 2026-04-03         Arnold D. Robbins     <[email protected]>
+
+        * io.c (do_getline_redir): Don't DEREF redir_exp too early.
+diff --git a/builtin.c b/builtin.c
+index ba3459db..80ab6069 100644
+--- a/builtin.c
++++ b/builtin.c
+@@ -2985,7 +2985,7 @@ do_sub(int nargs, unsigned int flags)
+        char *repl;
+        char *replend;
+        size_t repllen;
+-      int sofar;
++      size_t sofar;
+        int ampersands;
+        int matches = 0;
+        Regexp *rp;
+diff --git a/node.c b/node.c
+index f08a57d7..12a8fab4 100644
+--- a/node.c
++++ b/node.c
+@@ -571,7 +571,7 @@ parse_escape(const char **string_ptr, const char **result, size_t *nbytes)
+        static char buf[MB_LEN_MAX];
+        enum escape_results retval = ESCAPE_OK;
+        int c = *(*string_ptr)++;
+-      int i;
++      int64_t i;
+        int count;
+        int j;
+        const char *start;
+--
+2.44.4
+
meta/recipes-extended/gawk/gawk_5.3.0.bb +1 -0
index 56d7d7f76a..d79b0222a6 100644
@@ -23,6 +23,7 @@ SRC_URI = "${GNU_MIRROR}/gawk/gawk-${PV}.tar.gz \
            file://run-ptest \
            file://0001-Fix-some-C23-compilatio-issues.patch \
            file://CVE-2026-40467.patch \
+           file://CVE-2026-40468.patch \
            "
 
 SRC_URI[sha256sum] = "378f8864ec21cfceaa048f7e1869ac9b4597b449087caf1eb55e440d30273336"

--
2.35.6

#3 lore raw

PATCH 3/4 gawk: Fix CVE-2026-40469

In reply to Darsh Kelaiya -X (dkelaiya - E INFOCHIPS PRIVATE LIMITED at Cisco)

From: Darsh Kelaiya <[email protected]>

NVD [3] identifies upstream merge commit [2] as the fix. The CVE-specific change is its second parent [1], which adds 32-bit overflow checking in do_sub().

[1] https://cgit.git.savannah.gnu.org/cgit/gawk.git/commit/?id=aa7272a6e1184cdd21ab8f89200219abd8053eda
[2] https://cgit.git.savannah.gnu.org/cgit/gawk.git/commit/?id=ae1b2d508f46913269a9e62aceda3636afe8147b
[3] https://nvd.nist.gov/vuln/detail/CVE-2026-40469

---
 .../gawk/gawk/CVE-2026-40469.patch            | 90 +++++++++++++++++++
 meta/recipes-extended/gawk/gawk_5.3.0.bb      |  1 +
 2 files changed, 91 insertions(+)
 create mode 100644 meta/recipes-extended/gawk/gawk/CVE-2026-40469.patch
meta/recipes-extended/gawk/gawk/CVE-2026-40469.patch new file +90 -0
new file mode 100644
index 0000000000..49b6a23b01
@@ -0,0 +1,90 @@
+From f907980a3e7a58006b796308021c8410a24e0f3c Mon Sep 17 00:00:00 2001
+From: "Arnold D. Robbins" <[email protected]>
+Date: Mon, 6 Apr 2026 10:56:38 +0300
+Subject: [PATCH] Add overflow checking in do_sub for 32 bit systems.
+
+CVE: CVE-2026-40469
+Upstream-Status: Backport [https://cgit.git.savannah.gnu.org/cgit/gawk.git/commit/?id=aa7272a6e1184cdd21ab8f89200219abd8053eda]
+
+(cherry picked from commit aa7272a6e1184cdd21ab8f89200219abd8053eda)
+Signed-off-by: Darsh Kelaiya <[email protected]>
+---
+ ChangeLog |  9 +++++++++
+ builtin.c | 25 ++++++++++++++++++++-----
+ 2 files changed, 29 insertions(+), 5 deletions(-)
+
+diff --git a/ChangeLog b/ChangeLog
+index e691b241..74eea81f 100644
+--- a/ChangeLog
++++ b/ChangeLog
+@@ -1,3 +1,12 @@
++2026-04-06         Arnold D. Robbins     <[email protected]>
++
++	* builtin.c (do_sub): Check for overflow in calculation of size
++	of result buffer by doing the math in 64 bits. This provides
++	a fatal message on 32 bit systems if overflow happens instead
++	of letting dynamic memory get corrupted and likely causing
++	a core dump. Thanks to Michał Majchrowicz <[email protected]>
++	for the report and fix.
++
+ 2026-04-04         Arnold D. Robbins     <[email protected]>
+ 
+ 	* builtin.c (do_sub): Make `sofar' be size_t to avoid
+diff --git a/builtin.c b/builtin.c
+index 80ab6069..d63cf47b 100644
+--- a/builtin.c
++++ b/builtin.c
+@@ -2998,11 +2998,13 @@ do_sub(int nargs, unsigned int flags)
+ 	long current;
+ 	bool lastmatchnonzero;
+ 	char *mb_indices = NULL;
++	const char *fname = NULL;	// for fatal message, below
+ 
+ 	if ((flags & GENSUB) != 0) {
+ 		double d;
+ 		NODE *glob_flag;
+ 
++		fname = "gensub";
+ 		check_exact_args(nargs, "gensub", 4);
+ 
+ 		tmp = PEEK(3);
+@@ -3033,11 +3035,9 @@ do_sub(int nargs, unsigned int flags)
+ 		}
+ 		DEREF(glob_flag);
+ 	} else {
+-		if ((flags & GSUB) != 0) {
+-			check_exact_args(nargs, "gsub", 3);
+-		} else {
+-			check_exact_args(nargs, "sub", 3);
+-		}
++		fname = ((flags & GSUB) != 0) ? "gsub" : "sub";
++
++		check_exact_args(nargs, fname, 3);
+ 
+ 		/* take care of regexp early, in case re_update is fatal */
+ 
+@@ -3153,6 +3153,21 @@ do_sub(int nargs, unsigned int flags)
+ 		 * vary since ampersand is actual text of regexp match.
+ 		 */
+ 
++		// 4/2026: This overflow check simply provides a fatal
++		// message instead of letting realloc() die later after
++		// a buffer overrun.  It simply makes the user experience better,
++		// but does not prevent gawk from dying miserably.  I suppose
++		// it's worth the trouble, but just barely.
++
++		/* uint64_t so the product is 64-bit even on 32-bit ILP32 builds */
++		uint64_t repl_contribution =
++			(uint64_t)(unsigned int)ampersands
++			* (uint64_t)(uintptr_t)(matchend - matchstart);
++		if (repl_contribution > (uint64_t)SIZE_MAX
++		    || repl_contribution > (uint64_t)SIZE_MAX - (size_t)(matchend - text)
++						- repllen - 1)
++			fatal(_("%s: replacement expansion too large"), fname);
++
+ 		/*
+ 		 * add 1 to len to handle "empty" case where
+ 		 * matchend == matchstart and we force a match on a single
+-- 
+2.44.4
+
meta/recipes-extended/gawk/gawk_5.3.0.bb +1 -0
index d79b0222a6..7bd34a3ff8 100644
@@ -24,6 +24,7 @@ SRC_URI = "${GNU_MIRROR}/gawk/gawk-${PV}.tar.gz \
            file://0001-Fix-some-C23-compilatio-issues.patch \
            file://CVE-2026-40467.patch \
            file://CVE-2026-40468.patch \
+           file://CVE-2026-40469.patch \
            "
 
 SRC_URI[sha256sum] = "378f8864ec21cfceaa048f7e1869ac9b4597b449087caf1eb55e440d30273336"
Signature · 1 line
2.35.6
Reviewed-by on v1 3/4
#4 lore raw

Re: [OE-core][scarthgap][PATCH 3/4] gawk: Fix CVE-2026-40469

Looks good to me.

________________________________
From: [email protected] <[email protected]> on behalf of Darsh Kelaiya -X (dkelaiya - E INFOCHIPS PRIVATE LIMITED at Cisco) via lists.openembedded.org <[email protected]>
Sent: Wednesday, July 22, 2026 11:56 AM
To: [email protected] <[email protected]>
Cc: [email protected] <[email protected]>; Darsh Kelaiya <[email protected]>
Subject: [OE-core][scarthgap][PATCH 3/4] gawk: Fix CVE-2026-40469

From: Darsh Kelaiya <[email protected]>

NVD [3] identifies upstream merge commit [2] as the fix. The CVE-specific change is its second parent [1], which adds 32-bit overflow checking in do_sub().

[1] https://cgit.git.savannah.gnu.org/cgit/gawk.git/commit/?id=aa7272a6e1184cdd21ab8f89200219abd8053eda
[2] https://cgit.git.savannah.gnu.org/cgit/gawk.git/commit/?id=ae1b2d508f46913269a9e62aceda3636afe8147b
[3] https://nvd.nist.gov/vuln/detail/CVE-2026-40469

---
 .../gawk/gawk/CVE-2026-40469.patch            | 90 +++++++++++++++++++
 meta/recipes-extended/gawk/gawk_5.3.0.bb      |  1 +
 2 files changed, 91 insertions(+)
 create mode 100644 meta/recipes-extended/gawk/gawk/CVE-2026-40469.patch
meta/recipes-extended/gawk/gawk/CVE-2026-40469.patch new file +90 -0
new file mode 100644
index 0000000000..49b6a23b01
@@ -0,0 +1,90 @@
+From f907980a3e7a58006b796308021c8410a24e0f3c Mon Sep 17 00:00:00 2001
+From: "Arnold D. Robbins" <[email protected]>
+Date: Mon, 6 Apr 2026 10:56:38 +0300
+Subject: [PATCH] Add overflow checking in do_sub for 32 bit systems.
+
+CVE: CVE-2026-40469
+Upstream-Status: Backport [https://cgit.git.savannah.gnu.org/cgit/gawk.git/commit/?id=aa7272a6e1184cdd21ab8f89200219abd8053eda]
+
+(cherry picked from commit aa7272a6e1184cdd21ab8f89200219abd8053eda)
+Signed-off-by: Darsh Kelaiya <[email protected]>
+---
+ ChangeLog |  9 +++++++++
+ builtin.c | 25 ++++++++++++++++++++-----
+ 2 files changed, 29 insertions(+), 5 deletions(-)
+
+diff --git a/ChangeLog b/ChangeLog
+index e691b241..74eea81f 100644
+--- a/ChangeLog
++++ b/ChangeLog
+@@ -1,3 +1,12 @@
++2026-04-06         Arnold D. Robbins     <[email protected]>
++
++      * builtin.c (do_sub): Check for overflow in calculation of size
++      of result buffer by doing the math in 64 bits. This provides
++      a fatal message on 32 bit systems if overflow happens instead
++      of letting dynamic memory get corrupted and likely causing
++      a core dump. Thanks to Michał Majchrowicz <[email protected]>
++      for the report and fix.
++
+ 2026-04-04         Arnold D. Robbins     <[email protected]>
+
+        * builtin.c (do_sub): Make `sofar' be size_t to avoid
+diff --git a/builtin.c b/builtin.c
+index 80ab6069..d63cf47b 100644
+--- a/builtin.c
++++ b/builtin.c
+@@ -2998,11 +2998,13 @@ do_sub(int nargs, unsigned int flags)
+        long current;
+        bool lastmatchnonzero;
+        char *mb_indices = NULL;
++      const char *fname = NULL;       // for fatal message, below
+
+        if ((flags & GENSUB) != 0) {
+                double d;
+                NODE *glob_flag;
+
++              fname = "gensub";
+                check_exact_args(nargs, "gensub", 4);
+
+                tmp = PEEK(3);
+@@ -3033,11 +3035,9 @@ do_sub(int nargs, unsigned int flags)
+                }
+                DEREF(glob_flag);
+        } else {
+-              if ((flags & GSUB) != 0) {
+-                      check_exact_args(nargs, "gsub", 3);
+-              } else {
+-                      check_exact_args(nargs, "sub", 3);
+-              }
++              fname = ((flags & GSUB) != 0) ? "gsub" : "sub";
++
++              check_exact_args(nargs, fname, 3);
+
+                /* take care of regexp early, in case re_update is fatal */
+
+@@ -3153,6 +3153,21 @@ do_sub(int nargs, unsigned int flags)
+                 * vary since ampersand is actual text of regexp match.
+                 */
+
++              // 4/2026: This overflow check simply provides a fatal
++              // message instead of letting realloc() die later after
++              // a buffer overrun.  It simply makes the user experience better,
++              // but does not prevent gawk from dying miserably.  I suppose
++              // it's worth the trouble, but just barely.
++
++              /* uint64_t so the product is 64-bit even on 32-bit ILP32 builds */
++              uint64_t repl_contribution =
++                      (uint64_t)(unsigned int)ampersands
++                      * (uint64_t)(uintptr_t)(matchend - matchstart);
++              if (repl_contribution > (uint64_t)SIZE_MAX
++                  || repl_contribution > (uint64_t)SIZE_MAX - (size_t)(matchend - text)
++                                              - repllen - 1)
++                      fatal(_("%s: replacement expansion too large"), fname);
++
+                /*
+                 * add 1 to len to handle "empty" case where
+                 * matchend == matchstart and we force a match on a single
+--
+2.44.4
+
meta/recipes-extended/gawk/gawk_5.3.0.bb +1 -0
index d79b0222a6..7bd34a3ff8 100644
@@ -24,6 +24,7 @@ SRC_URI = "${GNU_MIRROR}/gawk/gawk-${PV}.tar.gz \
            file://0001-Fix-some-C23-compilatio-issues.patch \
            file://CVE-2026-40467.patch \
            file://CVE-2026-40468.patch \
+           file://CVE-2026-40469.patch \
            "
 
 SRC_URI[sha256sum] = "378f8864ec21cfceaa048f7e1869ac9b4597b449087caf1eb55e440d30273336"

--
2.35.6

#5 lore raw

PATCH 4/4 gawk: Fix CVE-2026-40553

In reply to Darsh Kelaiya -X (dkelaiya - E INFOCHIPS PRIVATE LIMITED at Cisco)

From: Darsh Kelaiya <[email protected]>

This patch applies the upstream fix as referenced in [3], using the commit shown in [1]. It also applies the corrective follow-up [2], which fixes the snprintf() truncation boundary check. Both commits are included in gawk 5.4.1, identified as the fixed release in [4].

[1] https://cgit.git.savannah.gnu.org/cgit/gawk.git/commit/?id=cca0366144336b49aaa7d5d949966ce8e2c70843
[2] https://cgit.git.savannah.gnu.org/cgit/gawk.git/commit/?id=bfa2e4b890a44100a99d26b54af385479528b12e
[3] https://nvd.nist.gov/vuln/detail/CVE-2026-40553
[4] https://cert.pl/en/posts/2026/07/CVE-2026-40467/

---
 .../gawk/gawk/CVE-2026-40553_p1.patch         | 50 +++++++++++++++++++
 .../gawk/gawk/CVE-2026-40553_p2.patch         | 44 ++++++++++++++++
 meta/recipes-extended/gawk/gawk_5.3.0.bb      |  2 +
 3 files changed, 96 insertions(+)
 create mode 100644 meta/recipes-extended/gawk/gawk/CVE-2026-40553_p1.patch
 create mode 100644 meta/recipes-extended/gawk/gawk/CVE-2026-40553_p2.patch
meta/recipes-extended/gawk/gawk/CVE-2026-40553_p1.patch new file +50 -0
new file mode 100644
index 0000000000..07b7df488a
@@ -0,0 +1,50 @@
+From aa39cac4bda6333be0f6253ecb7dfade26cb9641 Mon Sep 17 00:00:00 2001
+From: "Arnold D. Robbins" <[email protected]>
+Date: Wed, 15 Apr 2026 09:39:02 +0300
+Subject: [PATCH] Avoid buffer overflow in extension/readdir.c.
+
+CVE: CVE-2026-40553
+Upstream-Status: Backport [https://cgit.git.savannah.gnu.org/cgit/gawk.git/commit/?id=cca0366144336b49aaa7d5d949966ce8e2c70843]
+
+(cherry picked from commit cca0366144336b49aaa7d5d949966ce8e2c70843)
+Signed-off-by: Darsh Kelaiya <[email protected]>
+---
+ extension/ChangeLog | 6 ++++++
+ extension/readdir.c | 6 +++++-
+ 2 files changed, 11 insertions(+), 1 deletion(-)
+
+diff --git a/extension/ChangeLog b/extension/ChangeLog
+index 40ed6dd0..52a4c6ab 100644
+--- a/extension/ChangeLog
++++ b/extension/ChangeLog
+@@ -1,3 +1,9 @@
++2026-04-15         Arnold D. Robbins     <[email protected]>
++
++	* readdir.c (ftype): Use snprintf() to check for buffer
++	overflow in the file name before calling stat(). Thanks to
++	Marcin Wyczechowski <[email protected]> for the report.
++
+ 2023-11-02         Arnold D. Robbins     <[email protected]>
+ 
+ 	* 5.3.0: Release tar ball made.
+diff --git a/extension/readdir.c b/extension/readdir.c
+index 788e1d1e..b525fe21 100644
+--- a/extension/readdir.c
++++ b/extension/readdir.c
+@@ -117,8 +117,12 @@ ftype(struct dirent *entry, const char *dirname)
+ #endif
+ 	char fname[PATH_MAX];
+ 	struct stat sbuf;
++	int count;
++
++	count = snprintf(fname, sizeof(fname), "%s/%s", dirname, entry->d_name);
++	if (count > sizeof(fname))
++		return "u";	// buffer overflow. skip stat() call.
+ 
+-	sprintf(fname, "%s/%s", dirname, entry->d_name);
+ 	if (stat(fname, &sbuf) == 0) {
+ 		if (S_ISBLK(sbuf.st_mode))
+ 			return "b";
+-- 
+2.44.4
+
meta/recipes-extended/gawk/gawk/CVE-2026-40553_p2.patch new file +44 -0

44 lines not on this page · raw message

meta/recipes-extended/gawk/gawk_5.3.0.bb +2 -0
index 7bd34a3ff8..d71f655ba6 100644
@@ -25,6 +25,8 @@ SRC_URI = "${GNU_MIRROR}/gawk/gawk-${PV}.tar.gz \
            file://CVE-2026-40467.patch \
            file://CVE-2026-40468.patch \
            file://CVE-2026-40469.patch \
+           file://CVE-2026-40553_p1.patch \
+           file://CVE-2026-40553_p2.patch \
            "
 
 SRC_URI[sha256sum] = "378f8864ec21cfceaa048f7e1869ac9b4597b449087caf1eb55e440d30273336"
Signature · 1 line
2.35.6
Reviewed-by on v1 4/4
#6 lore raw

Re: [OE-core][scarthgap][PATCH 4/4] gawk: Fix CVE-2026-40553

Looks good to me.

________________________________
From: [email protected] <[email protected]> on behalf of Darsh Kelaiya -X (dkelaiya - E INFOCHIPS PRIVATE LIMITED at Cisco) via lists.openembedded.org <[email protected]>
Sent: Wednesday, July 22, 2026 11:56 AM
To: [email protected] <[email protected]>
Cc: [email protected] <[email protected]>; Darsh Kelaiya <[email protected]>
Subject: [OE-core][scarthgap][PATCH 4/4] gawk: Fix CVE-2026-40553

From: Darsh Kelaiya <[email protected]>

This patch applies the upstream fix as referenced in [3], using the commit shown in [1]. It also applies the corrective follow-up [2], which fixes the snprintf() truncation boundary check. Both commits are included in gawk 5.4.1, identified as the fixed release in [4].

[1] https://cgit.git.savannah.gnu.org/cgit/gawk.git/commit/?id=cca0366144336b49aaa7d5d949966ce8e2c70843
[2] https://cgit.git.savannah.gnu.org/cgit/gawk.git/commit/?id=bfa2e4b890a44100a99d26b54af385479528b12e
[3] https://nvd.nist.gov/vuln/detail/CVE-2026-40553
[4] https://cert.pl/en/posts/2026/07/CVE-2026-40467/

---
 .../gawk/gawk/CVE-2026-40553_p1.patch         | 50 +++++++++++++++++++
 .../gawk/gawk/CVE-2026-40553_p2.patch         | 44 ++++++++++++++++
 meta/recipes-extended/gawk/gawk_5.3.0.bb      |  2 +
 3 files changed, 96 insertions(+)
 create mode 100644 meta/recipes-extended/gawk/gawk/CVE-2026-40553_p1.patch
 create mode 100644 meta/recipes-extended/gawk/gawk/CVE-2026-40553_p2.patch
meta/recipes-extended/gawk/gawk/CVE-2026-40553_p1.patch new file +50 -0
new file mode 100644
index 0000000000..07b7df488a
@@ -0,0 +1,50 @@
+From aa39cac4bda6333be0f6253ecb7dfade26cb9641 Mon Sep 17 00:00:00 2001
+From: "Arnold D. Robbins" <[email protected]>
+Date: Wed, 15 Apr 2026 09:39:02 +0300
+Subject: [PATCH] Avoid buffer overflow in extension/readdir.c.
+
+CVE: CVE-2026-40553
+Upstream-Status: Backport [https://cgit.git.savannah.gnu.org/cgit/gawk.git/commit/?id=cca0366144336b49aaa7d5d949966ce8e2c70843]
+
+(cherry picked from commit cca0366144336b49aaa7d5d949966ce8e2c70843)
+Signed-off-by: Darsh Kelaiya <[email protected]>
+---
+ extension/ChangeLog | 6 ++++++
+ extension/readdir.c | 6 +++++-
+ 2 files changed, 11 insertions(+), 1 deletion(-)
+
+diff --git a/extension/ChangeLog b/extension/ChangeLog
+index 40ed6dd0..52a4c6ab 100644
+--- a/extension/ChangeLog
++++ b/extension/ChangeLog
+@@ -1,3 +1,9 @@
++2026-04-15         Arnold D. Robbins     <[email protected]>
++
++      * readdir.c (ftype): Use snprintf() to check for buffer
++      overflow in the file name before calling stat(). Thanks to
++      Marcin Wyczechowski <[email protected]> for the report.
++
+ 2023-11-02         Arnold D. Robbins     <[email protected]>
+
+        * 5.3.0: Release tar ball made.
+diff --git a/extension/readdir.c b/extension/readdir.c
+index 788e1d1e..b525fe21 100644
+--- a/extension/readdir.c
++++ b/extension/readdir.c
+@@ -117,8 +117,12 @@ ftype(struct dirent *entry, const char *dirname)
+ #endif
+        char fname[PATH_MAX];
+        struct stat sbuf;
++      int count;
++
++      count = snprintf(fname, sizeof(fname), "%s/%s", dirname, entry->d_name);
++      if (count > sizeof(fname))
++              return "u";     // buffer overflow. skip stat() call.
+
+-      sprintf(fname, "%s/%s", dirname, entry->d_name);
+        if (stat(fname, &sbuf) == 0) {
+                if (S_ISBLK(sbuf.st_mode))
+                        return "b";
+--
+2.44.4
+
meta/recipes-extended/gawk/gawk/CVE-2026-40553_p2.patch new file +44 -0

44 lines not on this page · raw message

meta/recipes-extended/gawk/gawk_5.3.0.bb +2 -0
index 7bd34a3ff8..d71f655ba6 100644
@@ -25,6 +25,8 @@ SRC_URI = "${GNU_MIRROR}/gawk/gawk-${PV}.tar.gz \
            file://CVE-2026-40467.patch \
            file://CVE-2026-40468.patch \
            file://CVE-2026-40469.patch \
+           file://CVE-2026-40553_p1.patch \
+           file://CVE-2026-40553_p2.patch \
            "
 
 SRC_URI[sha256sum] = "378f8864ec21cfceaa048f7e1869ac9b4597b449087caf1eb55e440d30273336"

--
2.35.6

Reviewed-by on v1 1/4
#7 lore raw
In reply to Darsh Kelaiya -X (dkelaiya - E INFOCHIPS PRIVATE LIMITED at Cisco)

Looks good to me.

________________________________
From: [email protected] <[email protected]> on behalf of Darsh Kelaiya -X (dkelaiya - E INFOCHIPS PRIVATE LIMITED at Cisco) via lists.openembedded.org <[email protected]>
Sent: Wednesday, July 22, 2026 11:56 AM
To: [email protected] <[email protected]>
Cc: [email protected] <[email protected]>; Darsh Kelaiya <[email protected]>
Subject: [OE-core][scarthgap][PATCH 1/4] gawk: Fix CVE-2026-40467

From: Darsh Kelaiya <[email protected]>

This patch applies the upstream fix as referenced in [2], using the commit shown in [1].

[1] https://cgit.git.savannah.gnu.org/cgit/gawk.git/commit/?id=a2d18c74109e41bec29a23098eba2e00057286d8
[2] https://nvd.nist.gov/vuln/detail/CVE-2026-40467

---
 .../gawk/gawk/CVE-2026-40467.patch            | 63 +++++++++++++++++++
 meta/recipes-extended/gawk/gawk_5.3.0.bb      |  1 +
 2 files changed, 64 insertions(+)
 create mode 100644 meta/recipes-extended/gawk/gawk/CVE-2026-40467.patch
meta/recipes-extended/gawk/gawk/CVE-2026-40467.patch new file +63 -0
new file mode 100644
index 0000000000..d813db5f8b
@@ -0,0 +1,63 @@
+From 22fd9e360251f70b34e9b46635b6d75bce49202f Mon Sep 17 00:00:00 2001
+From: "Arnold D. Robbins" <[email protected]>
+Date: Fri, 3 Apr 2026 12:02:11 +0300
+Subject: [PATCH] Small memory management fix in io.c.
+
+CVE: CVE-2026-40467
+Upstream-Status: Backport [https://cgit.git.savannah.gnu.org/cgit/gawk.git/commit/?id=a2d18c74109e41bec29a23098eba2e00057286d8]
+
+(cherry picked from commit a2d18c74109e41bec29a23098eba2e00057286d8)
+Signed-off-by: Darsh Kelaiya <[email protected]>
+---
+ ChangeLog | 6 ++++++
+ io.c      | 5 ++++-
+ 2 files changed, 10 insertions(+), 1 deletion(-)
+
+diff --git a/ChangeLog b/ChangeLog
+index 2fa8b2f0..6bc88ebb 100644
+--- a/ChangeLog
++++ b/ChangeLog
+@@ -1,3 +1,9 @@
++2026-04-03         Arnold D. Robbins     <[email protected]>
++
++      * io.c (do_getline_redir): Don't DEREF redir_exp too early.
++      Thanks to Michał Majchrowicz <[email protected]>
++      for the report.
++
+ 2023-11-02         Arnold D. Robbins     <[email protected]>
+
+        * 5.3.0: Release tar ball made.
+diff --git a/io.c b/io.c
+index 44671ebd..4db4b21d 100644
+--- a/io.c
++++ b/io.c
+@@ -2836,22 +2836,25 @@ do_getline_redir(int into_variable, enum redirval redirtype)
+        assert(redirtype != redirect_none);
+        redir_exp = TOP();
+        rp = redirect(redir_exp, redirtype, & redir_error, false);
+-      DEREF(redir_exp);
+        decr_sp();
+        if (rp == NULL) {
+                if (redir_error) { /* failed redirect */
+                        if (! do_traditional)
+                                update_ERRNO_int(redir_error);
+                }
++              DEREF(redir_exp);
+                return make_number((AWKNUM) -1.0);
+        } else if ((rp->flag & RED_TWOWAY) != 0 && rp->iop == NULL) {
+                if (is_non_fatal_redirect(redir_exp->stptr, redir_exp->stlen)) {
+                        update_ERRNO_int(EBADF);
++                      DEREF(redir_exp);
+                        return make_number((AWKNUM) -1.0);
+                }
+                (void) close_rp(rp, CLOSE_ALL);
++              DEREF(redir_exp);       // we're about to die, but what the heck, release it anyway
+                fatal(_("getline: attempt to read from closed read end of two-way pipe"));
+        }
++      DEREF(redir_exp);
+        iop = rp->iop;
+        if (iop == NULL)                /* end of input */
+                return make_number((AWKNUM) 0.0);
+--
+2.44.4
+
meta/recipes-extended/gawk/gawk_5.3.0.bb +1 -0
index b1d1fe7ae4..56d7d7f76a 100644
@@ -22,6 +22,7 @@ SRC_URI = "${GNU_MIRROR}/gawk/gawk-${PV}.tar.gz \
            file://0001-m4-readline-add-missing-includes.patch \
            file://run-ptest \
            file://0001-Fix-some-C23-compilatio-issues.patch \
+           file://CVE-2026-40467.patch \
            "
 
 SRC_URI[sha256sum] = "378f8864ec21cfceaa048f7e1869ac9b4597b449087caf1eb55e440d30273336"

--
2.35.6