From 0c63ac976687020cb6ba4575d6f64292b42f84ed Mon Sep 17 00:00:00 2001
From: azhovan <azhovan@outlook.com>
Date: Thu, 19 Nov 2026 22:00:06 +0100
Subject: [PATCH] Backport the CVE-2026-19773 fixes to Bookworm

---
 debian/patches/0004-CVE-2026-19773.patch      | 22 +++++++++++++++++++
 .../0005-CVE-2026-19773-uri-args.patch        | 22 +++++++++++++++++++
 debian/patches/series                         |  2 ++
 3 files changed, 46 insertions(+)
 create mode 100644 debian/patches/0004-CVE-2026-19773.patch
 create mode 100644 debian/patches/0005-CVE-2026-19773-uri-args.patch

diff --git a/debian/patches/0004-CVE-2026-19773.patch b/debian/patches/0004-CVE-2026-19773.patch
new file mode 100644
index 0000000..dec96cd
--- /dev/null
+++ b/debian/patches/0004-CVE-2026-19773.patch
@@ -0,0 +1,22 @@
+Description: Check the HTTP/2 header buffer before appending a byte
+ In 4.1.6, data_length records the allocation size and has the same
+ unsigned type as the write position. Keep the existing post-write
+ check so a full buffer is reported at the same point as before.
+ Reported by Maher Azzouzi working with TrendAI Zero Day Initiative.
+Author: Andy Green <andy@warmcat.com>
+Origin: backport, https://github.com/warmcat/libwebsockets/commit/824151862f37bc72f46d9a3e01d5b9408d313a0b
+Bug-Debian: https://bugs.debian.org/1149178
+Forwarded: not-needed
+
+--- a/lib/roles/h2/hpack.c
++++ b/lib/roles/h2/hpack.c
+@@ -280,6 +280,9 @@
+ {
+ 	struct allocated_headers *ah = wsi->http.ah;
+ 
++	if (ah->pos >= ah->data_length)
++		return 1;
++
+ 	ah->data[ah->pos++] = c;
+ 	ah->frags[ah->nfrag].len++;
+ 
diff --git a/debian/patches/0005-CVE-2026-19773-uri-args.patch b/debian/patches/0005-CVE-2026-19773-uri-args.patch
new file mode 100644
index 0000000..e115fb6
--- /dev/null
+++ b/debian/patches/0005-CVE-2026-19773-uri-args.patch
@@ -0,0 +1,22 @@
+Description: Check the header position when starting URI arguments
+ Use the existing excessive-header error path if the new fragment
+ starts outside the allocated header buffer.
+Author: Feng Xue <feng.xue@outlook.com>
+Origin: backport, https://github.com/warmcat/libwebsockets/commit/0c6cef0922c531f2662e87e74e17c191fa18162b
+Bug-Debian: https://bugs.debian.org/1149178
+Forwarded: not-needed
+
+--- a/lib/roles/http/parsers.c
++++ b/lib/roles/http/parsers.c
+@@ -918,7 +918,11 @@
+ 		ah->nfrag++;
+ 		if (ah->nfrag >= LWS_ARRAY_SIZE(ah->frags))
+ 			goto excessive;
++
+ 		ah->frags[ah->nfrag].offset = ++ah->pos;
++		if (ah->pos >= ah->data_length)
++			goto excessive;
++
+ 		ah->frags[ah->nfrag].len = 0;
+ 		ah->frags[ah->nfrag].nfrag = 0;
+ 
diff --git a/debian/patches/series b/debian/patches/series
index b0b5380..6c63013 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -4,3 +4,5 @@
 0001-CVE-2026-10650.patch
 0002-CVE-2025-11678.patch
 0003-CVE-2025-11677.patch
+0004-CVE-2026-19773.patch
+0005-CVE-2026-19773-uri-args.patch

base-commit: af78af58557fb50a6f3e9f6ed6f506fae8eaff9b
