[packages/libnl] Rel 2. Fix heap overflow in the ematch lexer, build with swig 4.5

arekm arekm at pld-linux.org
Thu Oct 29 09:42:25 CET 2026


commit e9e431f023b5d6ba0d3f48cf4291c241dbeea48f
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date:   Thu Oct 29 09:27:27 2026 +0100

    Rel 2. Fix heap overflow in the ematch lexer, build with swig 4.5
    
    Drop python-netlink: swig >= 4.4 no longer supports Python 2.

 libnl-ematch-quoted-overflow.patch | 30 ++++++++++++++
 libnl-python3-capi.patch           | 85 ++++++++++++++++++++++++++++++++++++++
 libnl.spec                         | 52 ++++-------------------
 3 files changed, 124 insertions(+), 43 deletions(-)
---
diff --git a/libnl.spec b/libnl.spec
index 7364e09..837230b 100644
--- a/libnl.spec
+++ b/libnl.spec
@@ -2,17 +2,15 @@
 # Conditional build:
 %bcond_without	apidocs		# API documentation
 %bcond_without	python		# Python netlink module (any)
-%bcond_without	python2		# CPython 2.x netlink module
 %bcond_without	python3		# CPython 3.x netlink module
 %bcond_without	static_libs	# static libraries
 %bcond_without	tests		# unit tests
 %bcond_with	net_tests	# unit tests using unshare for net ns
 
 %if %{without python}
-%undefine	with_python2
 %undefine	with_python3
 %else
-%if %{without python2} && %{without python3}
+%if %{without python3}
 %undefine	with_python
 %endif
 %endif
@@ -21,7 +19,7 @@ Summary:	Netlink sockets library
 Summary(pl.UTF-8):	Biblioteka do obsługi gniazd netlink
 Name:		libnl
 Version:	3.12.0
-Release:	1
+Release:	2
 Epoch:		1
 License:	LGPL v2.1
 Group:		Libraries
@@ -29,6 +27,10 @@ Source0:	https://github.com/thom311/libnl/releases/download/libnl3_12_0/%{name}-
 # Source0-md5:	f9112ca215807fe65eecd583d8f180cc
 Source1:	https://github.com/thom311/libnl/releases/download/libnl3_12_0/%{name}-doc-%{version}.tar.gz
 # Source1-md5:	befe7b001c82640f8e937c603afc7edc
+# quoted ematch strings over 32 bytes overflow the lexer buffer; https://github.com/thom311/libnl/issues/457
+Patch0:		%{name}-ematch-quoted-overflow.patch
+# Python 2 C-API calls in the swig interface; https://github.com/thom311/libnl/pull/463
+Patch1:		%{name}-python3-capi.patch
 URL:		http://www.infradead.org/~tgr/libnl/
 BuildRequires:	autoconf >= 2.50
 BuildRequires:	automake
@@ -38,7 +40,6 @@ BuildRequires:	flex >= 2.5.34
 BuildRequires:	libtool >= 2:2
 BuildRequires:	linux-libc-headers >= 7:2.6.23
 BuildRequires:	pkgconfig
-%{?with_python2:BuildRequires:	python-devel >= 1:2.7}
 %{?with_python3:BuildRequires:	python3-devel >= 1:3.2}
 BuildRequires:	rpm-build >= 4.6
 %{?with_python:BuildRequires:	rpm-pythonprov}
@@ -57,6 +58,7 @@ BuildRequires:	source-highlight
 BuildRequires:	tetex-dvips
 BuildRequires:	tetex-format-latex
 %endif
+Obsoletes:	python-netlink < 1:3.12.0-2
 BuildRoot:	%{tmpdir}/%{name}-%{version}-root-%(id -u -n)
 
 %description
@@ -108,18 +110,6 @@ generated from sources by doxygen.
 Dokumentacja API biblioteki libnl oraz wprowadzenie w formacie HTML
 wygenerowane ze źródeł za pomocą doxygena.
 
-%package -n python-netlink
-Summary:	Python 2 wrapper for netlink protocols
-Summary(pl.UTF-8):	Interfejs Pythona 2 do protokołów netlink
-Group:		Libraries/Python
-Requires:	%{name}%{?_isa} = %{epoch}:%{version}-%{release}
-
-%description -n python-netlink
-Python 2 wrapper for netlink protocols.
-
-%description -n python-netlink -l pl.UTF-8
-Interfejs Pythona 2 do protokołów netlink.
-
 %package -n python3-netlink
 Summary:	Python 3 wrapper for netlink protocols
 Summary(pl.UTF-8):	Interfejs Pythona 3 do protokołów netlink
@@ -135,6 +125,8 @@ Interfejs Pythona 3 do protokołów netlink.
 %prep
 %setup -q -a1
 %{__mv} libnl-doc-%{version} doc
+%patch -P0 -p1
+%patch -P1 -p1
 
 %if %{without net_tests}
 %{__sed} -i -e 's/^AM_CONDITIONAL(WITH_CHECK.*/AM_CONDITIONAL(WITH_CHECK, false)/' configure.ac
@@ -162,9 +154,6 @@ Interfejs Pythona 3 do protokołów netlink.
 cd python
 CFLAGS="%{rpmcflags}"
 LDFLAGS="%{rpmldflags} -L$(pwd)/../lib/.libs"
-%if %{with python2}
-%py_build
-%endif
 %if %{with python3}
 %py3_build
 %endif
@@ -181,10 +170,6 @@ rm -rf $RPM_BUILD_ROOT
 
 %if %{with python}
 cd python
-%if %{with python2}
-%py_install
-%py_postclean
-%endif
 %if %{with python3}
 %py3_install
 %endif
@@ -293,25 +278,6 @@ rm -rf $RPM_BUILD_ROOT
 %doc doc/{*.html,libnl.css,api,images,stylesheets}
 %endif
 
-%if %{with python2}
-%files -n python-netlink
-%defattr(644,root,root,755)
-%dir %{py_sitedir}/netlink
-%{py_sitedir}/netlink/_capi.so
-%{py_sitedir}/netlink/*.py[co]
-%dir %{py_sitedir}/netlink/genl
-%{py_sitedir}/netlink/genl/_capi.so
-%{py_sitedir}/netlink/genl/*.py[co]
-%dir %{py_sitedir}/netlink/route
-%{py_sitedir}/netlink/route/_capi.so
-%{py_sitedir}/netlink/route/*.py[co]
-%dir %{py_sitedir}/netlink/route/links
-%{py_sitedir}/netlink/route/links/*.py[co]
-%dir %{py_sitedir}/netlink/route/qdisc
-%{py_sitedir}/netlink/route/qdisc/*.py[co]
-%{py_sitedir}/netlink-1.0-py*.egg-info
-%endif
-
 %if %{with python3}
 %files -n python3-netlink
 %defattr(644,root,root,755)
diff --git a/libnl-ematch-quoted-overflow.patch b/libnl-ematch-quoted-overflow.patch
new file mode 100644
index 0000000..14bf7df
--- /dev/null
+++ b/libnl-ematch-quoted-overflow.patch
@@ -0,0 +1,30 @@
+diff -urN a/lib/route/cls/ematch_grammar.l b/lib/route/cls/ematch_grammar.l
+--- a/lib/route/cls/ematch_grammar.l	2025-11-30 08:47:11.000000000 +0100
++++ b/lib/route/cls/ematch_grammar.l	2026-10-29 01:59:24.692823042 +0100
+@@ -47,9 +47,23 @@
+ 			}
+ 
+ <QUOTE>[^\\\n\"]+	{
+-				memcpy(yylval->q.data + yylval->q.index, yytext,
+-				       strlen(yytext));
+-				yylval->q.index += strlen(yytext);
++				size_t need = (size_t) yylval->q.index + yyleng + 1;
++
++				if (need > yylval->q.len) {
++					char *p = realloc(yylval->q.data, need);
++
++					if (!p) {
++						free(yylval->q.data);
++						yylval->q.data = NULL;
++						return ERROR;
++					}
++					memset(p + yylval->q.len, 0, need - yylval->q.len);
++					yylval->q.data = p;
++					yylval->q.len = need;
++				}
++
++				memcpy(yylval->q.data + yylval->q.index, yytext, yyleng);
++				yylval->q.index += yyleng;
+ 			}
+ 
+ <QUOTE>\"		{
diff --git a/libnl-python3-capi.patch b/libnl-python3-capi.patch
new file mode 100644
index 0000000..daf8847
--- /dev/null
+++ b/libnl-python3-capi.patch
@@ -0,0 +1,85 @@
+From 9cc3dbb569864fa8fb5a0d5a0710b5c63c08a885 Mon Sep 17 00:00:00 2001
+From: Boris P <borisp at tekeli.org>
+Date: Fri, 23 Oct 2026 21:14:19 +0200
+Subject: [PATCH] python: replace removed Python 2 C-API calls in swig
+ interface files
+
+PyInt_Check/AsLong/FromLong and PyString_Check/AsString do not exist in
+the Python 3 C-API. Before GCC 14 the generated wrappers only warned;
+with implicit function declarations becoming hard errors the bindings
+fail to build (seen with GCC 16 on Python 3.9).
+
+Replace with PyLong_* respectively PyUnicode_Check/PyUnicode_AsUTF8.
+Tested downstream in Macaroni OS: bindings build and all three
+netlink.*_capi modules import cleanly.
+
+PLD: take the str length from PyUnicode_AsUTF8AndSize(); Py_SIZE() of a
+str is its character count and truncated non-ASCII attributes.
+---
+diff -urN a/python/netlink/capi.i b/python/netlink/capi.i
+--- a/python/netlink/capi.i	2016-12-10 16:04:32.000000000 +0100
++++ b/python/netlink/capi.i	2026-10-29 02:02:23.902273433 +0100
+@@ -625,8 +625,8 @@
+ 	}
+ 	resobj = PyObject_CallObject(funcobj, cbparobj);
+ 	Py_DECREF(cbparobj);
+-	if (resobj && PyInt_Check(resobj))
+-		result = (int)PyInt_AsLong(resobj);
++	if (resobj && PyLong_Check(resobj))
++		result = (int)PyLong_AsLong(resobj);
+ 	else
+ 		result = NL_STOP;
+ 	Py_XDECREF(resobj);
+@@ -661,8 +661,8 @@
+ 	}
+ 	resobj = PyObject_CallObject(funcobj, cbparobj);
+ 	Py_DECREF(cbparobj);
+-	if (resobj && PyInt_Check(resobj))
+-		result = (int)PyInt_AsLong(resobj);
++	if (resobj && PyLong_Check(resobj))
++		result = (int)PyLong_AsLong(resobj);
+ 	else
+ 		result = NL_STOP;
+ 	Py_XDECREF(resobj);
+@@ -814,11 +814,17 @@
+ extern int		nla_type(const struct nlattr *);
+ 
+ %typemap(in) (int, const void *) {
+-	$1 = Py_SIZE($input);
+ 	if (PyByteArray_Check($input)) {
++		$1 = PyByteArray_Size($input);
+ 		$2 = ($2_ltype)PyByteArray_AsString($input);
+-	} else if (PyString_Check($input)) {
+-		$2 = ($2_ltype)PyString_AsString($input);
++	} else if (PyUnicode_Check($input)) {
++		Py_ssize_t len;
++
++		/* Py_SIZE() of a str counts characters, not UTF-8 bytes */
++		$2 = ($2_ltype)PyUnicode_AsUTF8AndSize($input, &len);
++		if (!$2)
++			SWIG_fail;
++		$1 = len;
+ 	} else
+ 		SWIG_exception(SWIG_TypeError,
+ 			       "pointer must be bytearray or string.");
+@@ -887,7 +893,7 @@
+ 		attrs = PyDict_New();
+ 		for (i = 0; i <= max; i++)
+ 			if (tb_msg[i]) {
+-				k = PyInt_FromLong((long)i);
++				k = PyLong_FromLong((long)i);
+ 				v = SWIG_NewPointerObj(SWIG_as_voidptr(tb_msg[i]), SWIGTYPE_p_nlattr, 0 |  0 );
+ 				PyDict_SetItem(attrs, k, v);
+ 			}
+diff -urN a/python/netlink/genl/capi.i b/python/netlink/genl/capi.i
+--- a/python/netlink/genl/capi.i	2016-12-10 16:04:32.000000000 +0100
++++ b/python/netlink/genl/capi.i	2026-10-29 02:02:23.830399165 +0100
+@@ -99,7 +99,7 @@
+ 		attrs = PyDict_New();
+ 		for (i = 0; i <= max; i++)
+ 			if (tb_msg[i]) {
+-				k = PyInt_FromLong((long)i);
++				k = PyLong_FromLong((long)i);
+ 				v = SWIG_NewPointerObj(SWIG_as_voidptr(tb_msg[i]), SWIGTYPE_p_nlattr, 0 |  0 );
+ 				PyDict_SetItem(attrs, k, v);
+ 			}
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/libnl.git/commitdiff/e9e431f023b5d6ba0d3f48cf4291c241dbeea48f



More information about the pld-cvs-commit mailing list