[packages/less] Rel 2. Fix use-after-free expanding ${VAR} in lesskey #env section.
arekm
arekm at pld-linux.org
Thu Oct 29 08:39:37 CET 2026
commit b9f8b831de7f9f23b0a4b8ef4939a742edfe21f8
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date: Wed Oct 28 23:55:23 2026 +0100
Rel 2. Fix use-after-free expanding ${VAR} in lesskey #env section.
less-expand_evars-uaf.patch | 47 +++++++++++++++++++++++++++++++++++++++++++++
less-libtinfo.patch | 30 -----------------------------
less.spec | 9 +++++----
3 files changed, 52 insertions(+), 34 deletions(-)
---
diff --git a/less.spec b/less.spec
index df06835..8a5baf3 100644
--- a/less.spec
+++ b/less.spec
@@ -9,7 +9,7 @@ Summary(tr.UTF-8): Metin dosyası görüntüleyici - more benzeri
Summary(uk.UTF-8): Програма для перегляду текстових файлів схожа на more, але краща
Name: less
Version: 710
-Release: 1
+Release: 2
License: GPL v3+
Group: Applications/Text
#Source0Download: http://www.greenwoodsoftware.com/less/download.html
@@ -20,8 +20,9 @@ Source1: http://www.mif.pg.gda.pl/homepages/ankry/man-PLD/%{name}-non-english-ma
Source2: %{name}echo.1
Patch0: %{name}-shell.patch
Patch1: %{name}-multilib.patch
-Patch2: %{name}-libtinfo.patch
-URL: http://www.greenwoodsoftware.com/less/
+# use-after-free on ${VAR} in lesskey #env; https://github.com/gwsw/less/commit/d46bb8e74dcf992c4f7eb840424f2339039e9fbb
+Patch3: %{name}-expand_evars-uaf.patch
+URL: https://www.greenwoodsoftware.com/less/
BuildRequires: autoconf >= 2.50
BuildRequires: ncurses-devel >= 5.0
BuildRequires: rpmbuild(macros) >= 1.317
@@ -76,7 +77,7 @@ sağlar.
%setup -q
%patch -P0 -p1
%patch -P1 -p1
-%patch -P2 -p1
+%patch -P3 -p1
%build
%{__autoconf}
diff --git a/less-expand_evars-uaf.patch b/less-expand_evars-uaf.patch
new file mode 100644
index 0000000..017fa21
--- /dev/null
+++ b/less-expand_evars-uaf.patch
@@ -0,0 +1,47 @@
+From d46bb8e74dcf992c4f7eb840424f2339039e9fbb Mon Sep 17 00:00:00 2001
+From: Mark Nudelman <markn at greenwoodsoftware.com>
+Date: Tue, 29 Sep 2026 09:27:04 -0700
+Subject: [PATCH] Fix use-after-free in expand_evars.
+
+expand_evars finds instances of ${VAR} in a buffer and expands them to
+the value of the env var by calling lgetenv("VAR") and appending the
+result to an xbuf. But the value returned from lgetenv could be a
+substring within the xbuf that we are working on. When appending to it,
+we may free and reallocate the contents, invalidating the lgetenv
+result. Save a copy of the lgetenv result separate from the xbuf.
+
+This has always been a bug, but previously didn't happen because of
+the way that expand_evars was invoked from the decode.c code. Change
+5b0d521fe55aad4e4ce5d44a2b2bd0e4129e68b5 changes the way expand_evars
+is called and makes the bug more likely to manifest.
+
+Related to #831.
+---
+ evar.c | 7 ++++++-
+ 1 file changed, 6 insertions(+), 1 deletion(-)
+
+diff --git a/evar.c b/evar.c
+index e723fa76..a6a29f70 100644
+--- a/evar.c
++++ b/evar.c
+@@ -171,6 +171,7 @@ public void expand_evars(mutable char *buf, size_t len, struct xbuffer *xbuf)
+ if (i+1 < len && buf[i] == '$' && buf[i+1] == '{')
+ {
+ constant char *evar;
++ char *evar2;
+ char term;
+ size_t e;
+ i += 2; /* skip "${" */
+@@ -183,7 +184,11 @@ public void expand_evars(mutable char *buf, size_t len, struct xbuffer *xbuf)
+ buf[e++] = '\0';
+ evar = lgetenv_ext(&buf[i], xbuf->data, xbuf->end);
+ if (evar == NULL) evar = "";
+- i = add_evar(xbuf, buf, len, e, evar, term);
++ /* Need to save a copy of evar because it might be part of xbuf
++ * and could get freed when we add to xbuf in add_evar. */
++ evar2 = save(evar);
++ i = add_evar(xbuf, buf, len, e, evar2, term);
++ free(evar2);
+ } else
+ {
+ xbuf_add_char(xbuf, buf[i++]);
diff --git a/less-libtinfo.patch b/less-libtinfo.patch
deleted file mode 100644
index b85bfc5..0000000
--- a/less-libtinfo.patch
+++ /dev/null
@@ -1,30 +0,0 @@
-diff -urNp -x '*.orig' less-563.org/configure.ac less-563/configure.ac
---- less-563.org/configure.ac 2020-06-14 05:34:53.000000000 +0200
-+++ less-563/configure.ac 2021-03-21 01:03:15.189335808 +0100
-@@ -23,6 +23,7 @@ AC_PROG_INSTALL
- AC_SYS_LARGEFILE
-
- # Checks for general libraries.
-+AC_CHECK_LIB(tinfow, tgoto, [have_tinfow=yes], [have_tinfow=no])
- AC_CHECK_LIB(tinfo, tgoto, [have_tinfo=yes], [have_tinfo=no])
- AC_CHECK_LIB(tinfow, tgoto, [have_tinfow=yes], [have_tinfow=no])
- AC_CHECK_LIB(xcurses, initscr, [have_xcurses=yes], [have_xcurses=no])
-@@ -54,6 +55,18 @@ if test $curses_broken = 0; then
-
- # -- Try tinfo.
- if test "x$TERMLIBS" = x; then
-+ if test $have_tinfow = yes; then
-+ TERMLIBS="-ltinfow"
-+ SAVE_LIBS=$LIBS
-+ LIBS="$LIBS $TERMLIBS"
-+ AC_TRY_LINK(, [tgetent(0,0); tgetflag(0); tgetnum(0); tgetstr(0,0);],
-+ [termok=yes], [termok=no])
-+ LIBS=$SAVE_LIBS
-+ if test $termok = no; then TERMLIBS=""; fi
-+ fi
-+fi
-+
-+if test "x$TERMLIBS" = x; then
- if test $have_tinfo = yes; then
- TERMLIBS="-ltinfo"
- SAVE_LIBS=$LIBS
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/packages/less.git/commitdiff/b9f8b831de7f9f23b0a4b8ef4939a742edfe21f8
More information about the pld-cvs-commit
mailing list