diff --git a/backport-Avoid-stealing-data-from-an-input-program-that-uses-.patch b/backport-Avoid-stealing-data-from-an-input-program-that-uses-.patch deleted file mode 100644 index d907543e847828fa1e524861545a3a672455ddf6..0000000000000000000000000000000000000000 --- a/backport-Avoid-stealing-data-from-an-input-program-that-uses-.patch +++ /dev/null @@ -1,35 +0,0 @@ -From c8df315c742fc470e766244ce8efe305a98d720a Mon Sep 17 00:00:00 2001 -From: Mark Nudelman -Date: Sun, 28 May 2023 15:28:42 -0700 -Subject: [PATCH] Avoid stealing data from an input program that uses the tty - at startup, like sudo. - ---- - os.c | 4 +++- - 1 file changed, 3 insertions(+), 1 deletion(-) - -diff --git a/os.c b/os.c -index af95834..7206277 100644 ---- a/os.c -+++ b/os.c -@@ -114,6 +114,8 @@ static int check_poll(int fd, int tty) - { - struct pollfd poller[2] = { { fd, POLLIN, 0 }, { tty, POLLIN, 0 } }; - int timeout = (waiting_for_data && !(scanning_eof && follow_mode == FOLLOW_NAME)) ? -1 : waiting_for_data_delay; -+ if (!any_data) -+ return (0); - poll(poller, 2, timeout); - #if LESSTEST - if (ttyin_name == NULL) /* Check for ^X only on a real tty. */ -@@ -136,7 +138,7 @@ static int check_poll(int fd, int tty) - * to allow a program piping data into less to have temporary - * access to the tty (like sudo asking for a password). - */ -- if (any_data && (poller[0].revents & (POLLIN|POLLHUP|POLLERR)) == 0) -+ if ((poller[0].revents & (POLLIN|POLLHUP|POLLERR)) == 0) - /* No data available; let caller take action, then try again. */ - return (READ_AGAIN); - /* There is data (or HUP/ERR) available. Safe to call read() without blocking. */ --- -2.33.0 - diff --git a/backport-CVE-2024-32487.patch b/backport-CVE-2024-32487.patch deleted file mode 100644 index 7af27372e130d6861a2357286bf40baae01edfee..0000000000000000000000000000000000000000 --- a/backport-CVE-2024-32487.patch +++ /dev/null @@ -1,70 +0,0 @@ -From 007521ac3c95bc76e3d59c6dbfe75d06c8075c33 Mon Sep 17 00:00:00 2001 -From: Mark Nudelman -Date: Thu, 11 Apr 2024 17:49:48 -0700 -Subject: [PATCH] Fix bug when viewing a file whose name contains a newline. - ---- - filename.c | 29 ++++++++++++++++++++++++----- - 1 file changed, 24 insertions(+), 5 deletions(-) - -diff --git a/filename.c b/filename.c -index 5d7a5ef..987c24a 100644 ---- a/filename.c -+++ b/filename.c -@@ -133,6 +133,15 @@ static int metachar(char c) - return (strchr(metachars(), c) != NULL); - } - -+/* -+ * Must use quotes rather than escape char for this metachar? -+ */ -+static int must_quote(char c) -+{ -+ /* {{ Maybe the set of must_quote chars should be configurable? }} */ -+ return (c == '\n'); -+} -+ - /* - * Insert a backslash before each metacharacter in a string. - */ -@@ -165,6 +174,9 @@ public char * shell_quoten(constant char *s, size_t slen) - * doesn't support escape chars. Use quotes. - */ - use_quotes = 1; -+ } else if (must_quote(*p)) -+ { -+ len += 3; /* open quote + char + close quote */ - } else - { - /* -@@ -195,15 +207,22 @@ public char * shell_quoten(constant char *s, size_t slen) - constant char *es = s + slen; - while (s < es) - { -- if (metachar(*s)) -+ if (!metachar(*s)) - { -- /* -- * Add the escape char. -- */ -+ *np++ = *s++; -+ } else if (must_quote(*s)) -+ { -+ /* Surround the char with quotes. */ -+ *np++ = openquote; -+ *np++ = *s++; -+ *np++ = closequote; -+ } else -+ { -+ /* Insert an escape char before the char. */ - strcpy(np, esc); - np += esclen; -+ *np++ = *s++; - } -- *np++ = *s++; - } - *np = '\0'; - } --- -2.43.0 - diff --git a/backport-Don-t-return-READ_AGAIN-from-iread-if-no-data-has-ye.patch b/backport-Don-t-return-READ_AGAIN-from-iread-if-no-data-has-ye.patch deleted file mode 100644 index 9eaf13c9800c28236036ebb7bb0f95edfb0437dd..0000000000000000000000000000000000000000 --- a/backport-Don-t-return-READ_AGAIN-from-iread-if-no-data-has-ye.patch +++ /dev/null @@ -1,49 +0,0 @@ -From 5e93b7b4f99c3cdda3ab38d19fbf20b17f2536f7 Mon Sep 17 00:00:00 2001 -From: Mark Nudelman -Date: Sat, 27 May 2023 18:56:08 -0700 -Subject: [PATCH] Don't return READ_AGAIN from iread if no data has yet been - received, to allow a program piping data into less to have temporary access - to the tty (like sudo asking for a password). - ---- - os.c | 10 +++++++++- - 1 file changed, 9 insertions(+), 1 deletion(-) - -diff --git a/os.c b/os.c -index 56e3bf3..7f2d692 100644 ---- a/os.c -+++ b/os.c -@@ -72,6 +72,7 @@ public int consecutive_nulls = 0; - /* Milliseconds to wait for data before displaying "waiting for data" message. */ - static int waiting_for_data_delay = 4000; - static jmp_buf read_label; -+static int any_data = FALSE; - - extern int sigs; - extern int ignore_eoi; -@@ -130,7 +131,12 @@ static int check_poll(int fd, int tty) - if (ignore_eoi && exit_F_on_close && (poller[0].revents & (POLLHUP|POLLIN)) == POLLHUP) - /* Break out of F loop on HUP due to --exit-follow-on-close. */ - return (READ_INTR); -- if ((poller[0].revents & (POLLIN|POLLHUP|POLLERR)) == 0) -+ /* -+ * Don't return READ_AGAIN if no data has yet been received, -+ * to allow a program piping data into less to have temporary -+ * access to the tty (like sudo asking for a password). -+ */ -+ if (any_data && (poller[0].revents & (POLLIN|POLLHUP|POLLERR)) == 0) - /* No data available; let caller take action, then try again. */ - return (READ_AGAIN); - /* There is data (or HUP/ERR) available. Safe to call read() without blocking. */ -@@ -282,6 +288,8 @@ start: - #endif - return (READ_ERR); - } -+ if (n > 0) -+ any_data = TRUE; - return (n); - } - --- -2.33.0 - diff --git a/backport-Fix-for-previous-fix.patch b/backport-Fix-for-previous-fix.patch deleted file mode 100644 index 530bad400fd3808775ad510969c518d48dbbaba3..0000000000000000000000000000000000000000 --- a/backport-Fix-for-previous-fix.patch +++ /dev/null @@ -1,25 +0,0 @@ -From fd2a746b7c967c9f8d3739daf6701f8d3267442f Mon Sep 17 00:00:00 2001 -From: Mark Nudelman -Date: Sun, 28 May 2023 12:07:31 -0700 -Subject: [PATCH] Fix for previous fix. - ---- - os.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/os.c b/os.c -index 7f2d692..af95834 100644 ---- a/os.c -+++ b/os.c -@@ -288,7 +288,7 @@ start: - #endif - return (READ_ERR); - } -- if (n > 0) -+ if (fd != tty && n > 0) - any_data = TRUE; - return (n); - } --- -2.33.0 - diff --git a/backport-Fixed-typo.patch b/backport-Fixed-typo.patch deleted file mode 100644 index 19be9e6901de6497cf4b71c9c59ecd638f4c7a0c..0000000000000000000000000000000000000000 --- a/backport-Fixed-typo.patch +++ /dev/null @@ -1,22 +0,0 @@ -From 7a0cb4dcab040a4274e9d0d1301c7e925ba9ca18 Mon Sep 17 00:00:00 2001 -From: Stefan -Date: Mon, 29 May 2023 19:23:01 +0200 -Subject: [PATCH] Fixed typo (#366) - ---- - screen.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/screen.c b/screen.c -index b76a4ea2..1e97c66e 100644 ---- a/screen.c -+++ b/screen.c -@@ -1702,7 +1702,7 @@ static void ltputs(char *str, int affcnt, int (*f_putc)(int)) - #endif /* MSDOS_COMPILER */ - - /* -- * Configure the termimal so mouse clicks and wheel moves -+ * Configure the terminal so mouse clicks and wheel moves - * produce input to less. - */ - public void init_mouse(void) diff --git a/backport-Implement-osc8_open.patch b/backport-Implement-osc8_open.patch deleted file mode 100644 index ee2605b2fbcf95e5b858d9ce558004ce69db1622..0000000000000000000000000000000000000000 --- a/backport-Implement-osc8_open.patch +++ /dev/null @@ -1,69 +0,0 @@ -From 90d9d12ba9d3818a0074f33c5153b577d07aa8fd Mon Sep 17 00:00:00 2001 -From: Mark Nudelman -Date: Tue, 16 Jan 2024 18:14:33 -0800 -Subject: [PATCH] Implement osc8_open(). - ---- - filename.c | 16 +++++++++++----- - 1 file changed, 11 insertions(+), 5 deletions(-) - -diff --git a/filename.c b/filename.c -index 672dc94..5d7a5ef 100644 ---- a/filename.c -+++ b/filename.c -@@ -136,7 +136,7 @@ static int metachar(char c) - /* - * Insert a backslash before each metacharacter in a string. - */ --public char * shell_quote(constant char *s) -+public char * shell_quoten(constant char *s, size_t slen) - { - constant char *p; - char *np; -@@ -151,7 +151,7 @@ public char * shell_quote(constant char *s) - * Determine how big a string we need to allocate. - */ - len = 1; /* Trailing null byte */ -- for (p = s; *p != '\0'; p++) -+ for (p = s; p < s + slen; p++) - { - len++; - if (*p == openquote || *p == closequote) -@@ -181,7 +181,7 @@ public char * shell_quote(constant char *s) - * We can't quote a string that contains quotes. - */ - return (NULL); -- len = (int) strlen(s) + 3; -+ len = slen + 3; - } - /* - * Allocate and construct the new string. -@@ -189,10 +189,11 @@ public char * shell_quote(constant char *s) - newstr = np = (char *) ecalloc(len, sizeof(char)); - if (use_quotes) - { -- SNPRINTF3(newstr, len, "%c%s%c", openquote, s, closequote); -+ SNPRINTF4(newstr, len, "%c%.*s%c", openquote, (int) slen, s, closequote); - } else - { -- while (*s != '\0') -+ constant char *es = s + slen; -+ while (s < es) - { - if (metachar(*s)) - { -@@ -209,6 +210,11 @@ public char * shell_quote(constant char *s) - return (newstr); - } - -+public char * shell_quote(char *s) -+{ -+ return shell_quoten(s, strlen(s)); -+} -+ - /* - * Return a pathname that points to a specified file in a specified directory. - * Return NULL if the file does not exist in the directory. --- -2.43.0 - diff --git a/backport-Move-any_data-under-if-USE_POLL-and-ensure-that-tty-variable.patch b/backport-Move-any_data-under-if-USE_POLL-and-ensure-that-tty-variable.patch deleted file mode 100644 index d93a28f5e73564b3437e4de4d655add7bc8f4f10..0000000000000000000000000000000000000000 --- a/backport-Move-any_data-under-if-USE_POLL-and-ensure-that-tty-variable.patch +++ /dev/null @@ -1,41 +0,0 @@ -From bd05d5102880eca0ea2a1f1f713dd2e568bc164c Mon Sep 17 00:00:00 2001 -From: Mark Nudelman -Date: Mon, 29 May 2023 10:20:38 -0700 -Subject: [PATCH] Move any_data under #if USE_POLL and ensure that tty variable - is not accessed when it does not exist (in MSDOS build). - ---- - os.c | 4 +++- - 1 file changed, 3 insertions(+), 1 deletion(-) - -diff --git a/os.c b/os.c -index 0edc859f..b9097c41 100644 ---- a/os.c -+++ b/os.c -@@ -48,6 +48,7 @@ static int use_poll = TRUE; - #endif - #if USE_POLL - #include -+static int any_data = FALSE; - #endif - - /* -@@ -72,7 +73,6 @@ public int consecutive_nulls = 0; - /* Milliseconds to wait for data before displaying "waiting for data" message. */ - static int waiting_for_data_delay = 4000; - static jmp_buf read_label; --static int any_data = FALSE; - - extern int sigs; - extern int ignore_eoi; -@@ -292,8 +292,10 @@ public int iread(int fd, unsigned char *buf, unsigned int len) - #endif - return (READ_ERR); - } -+#if USE_POLL - if (fd != tty && n > 0) - any_data = TRUE; -+#endif - return (n); - } - diff --git a/backport-Some-constifying.patch b/backport-Some-constifying.patch deleted file mode 100644 index 19c8ca55809313904e691766b44cca3c1a15a86f..0000000000000000000000000000000000000000 --- a/backport-Some-constifying.patch +++ /dev/null @@ -1,59 +0,0 @@ -From 756acc92c9d6bea9929d9105207e081054be05fb Mon Sep 17 00:00:00 2001 -From: Mark Nudelman -Date: Mon, 6 Nov 2023 11:44:08 -0800 -Subject: [PATCH] Some constifying. - ---- - filename.c | 17 +++++++++-------- - 1 file changed, 9 insertions(+), 8 deletions(-) - -diff --git a/filename.c b/filename.c -index a8726dc..672dc94 100644 ---- a/filename.c -+++ b/filename.c -@@ -136,12 +136,13 @@ static int metachar(char c) - /* - * Insert a backslash before each metacharacter in a string. - */ --public char * shell_quote(char *s) -+public char * shell_quote(constant char *s) - { -- char *p; -+ constant char *p; -+ char *np; - char *newstr; - int len; -- char *esc = get_meta_escape(); -+ constant char *esc = get_meta_escape(); - int esclen = (int) strlen(esc); - int use_quotes = 0; - int have_quotes = 0; -@@ -185,7 +186,7 @@ public char * shell_quote(char *s) - /* - * Allocate and construct the new string. - */ -- newstr = p = (char *) ecalloc(len, sizeof(char)); -+ newstr = np = (char *) ecalloc(len, sizeof(char)); - if (use_quotes) - { - SNPRINTF3(newstr, len, "%c%s%c", openquote, s, closequote); -@@ -198,12 +199,12 @@ public char * shell_quote(char *s) - /* - * Add the escape char. - */ -- strcpy(p, esc); -- p += esclen; -+ strcpy(np, esc); -+ np += esclen; - } -- *p++ = *s++; -+ *np++ = *s++; - } -- *p = '\0'; -+ *np = '\0'; - } - return (newstr); - } --- -2.43.0 - diff --git a/less-633.tar.gz b/less-633.tar.gz deleted file mode 100644 index 6f96facacee591b9d9c1a83fbed49f02a8ebb429..0000000000000000000000000000000000000000 Binary files a/less-633.tar.gz and /dev/null differ diff --git a/less-661.tar.gz b/less-661.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..6f452b1b0b51e57b71a44b097085c9a20e79aa29 Binary files /dev/null and b/less-661.tar.gz differ diff --git a/less.csh b/less.csh new file mode 100644 index 0000000000000000000000000000000000000000..d3c1f8e348197542fff481d89cc4ba14cbba817b --- /dev/null +++ b/less.csh @@ -0,0 +1,15 @@ +# less initialization script (csh) + +# All less.*sh files should have the same semantics! + +# In case you are curious, the test for non-emptiness is not as easy as in +# Bourne shell. This "eval" construct is probably inspired by Stack +# Overflow question 13343392. +if ( $?LESSOPEN && { eval 'test ! -z "$LESSOPEN"' } ) then + : +else + if ( -x /usr/bin/lesspipe.sh ) then + # The '||' here is intentional, see rhbz#1254837. + setenv LESSOPEN "||/usr/bin/lesspipe.sh %s" + endif +endif diff --git a/less.sh b/less.sh new file mode 100644 index 0000000000000000000000000000000000000000..189bbd2c84174c23b3097403e61b9289f9d01283 --- /dev/null +++ b/less.sh @@ -0,0 +1,8 @@ +# less initialization script (sh) + +# All less.*sh files should have the same semantics! + +if [ -z "$LESSOPEN" ] && [ -x /usr/bin/lesspipe.sh ]; then + # The '||' here is intentional, see rhbz#1254837. + export LESSOPEN="||/usr/bin/lesspipe.sh %s" +fi diff --git a/less.spec b/less.spec index 8248f9aacece2e1d58aa74a7ea1a88dccd0893be..52c708931cbab58981c5b427dcac37ba490e8132 100644 --- a/less.spec +++ b/less.spec @@ -1,20 +1,15 @@ Name: less -Version: 633 -Release: 4 +Version: 661 +Release: 1 Summary: Less is a pager that displays text files. -License: GPLv3+ or BSD +License: GPL-3.0-only and BSD-2-Clause URL: http://www.greenwoodsoftware.com/less Source0: http://www.greenwoodsoftware.com/less/%{name}-%{version}.tar.gz +Source1: lesspipe.sh +Source2: less.sh +Source3: less.csh Patch0: less-394-time.patch Patch1: less-475-fsync.patch -Patch2: backport-Some-constifying.patch -Patch3: backport-Implement-osc8_open.patch -Patch4: backport-CVE-2024-32487.patch -Patch5: backport-Don-t-return-READ_AGAIN-from-iread-if-no-data-has-ye.patch -Patch6: backport-Fix-for-previous-fix.patch -Patch7: backport-Avoid-stealing-data-from-an-input-program-that-uses-.patch -Patch8: backport-Fixed-typo.patch -Patch9: backport-Move-any_data-under-if-USE_POLL-and-ensure-that-tty-variable.patch BuildRequires: gcc make ncurses-devel autoconf automake libtool @@ -41,18 +36,25 @@ autoreconf -ivf %install %make_install - +mkdir -p %{buildroot}%{_sysconfdir}/profile.d +install -p %{S:1} %{buildroot}%{_bindir} +install -p -m 644 %{S:2} %{buildroot}%{_sysconfdir}/profile.d +install -p -m 644 %{S:3} %{buildroot}%{_sysconfdir}/profile.d %files -%defattr(-,root,root) %license LICENSE COPYING %{_bindir}/less* +%{_sysconfdir}/profile.d/* %files help %doc README NEWS INSTALL %{_mandir}/man1/* %changelog +* Sun Jul 14 2024 Funda Wang - 661-1 +- Update to 661 +- add lesspipe as most other distros do + * Sat May 11 2024 zhangxingrong - 633-4 - backport some upstream patch diff --git a/lesspipe.sh b/lesspipe.sh new file mode 100644 index 0000000000000000000000000000000000000000..f2df6a1fe4904b22fac1228407f9fe126e1180aa --- /dev/null +++ b/lesspipe.sh @@ -0,0 +1,128 @@ +#!/bin/sh +# +# To use this filter with less, define LESSOPEN: +# export LESSOPEN="|/usr/bin/lesspipe.sh %s" +# +# The script should return zero if the output was valid and non-zero +# otherwise, so less could detect even a valid empty output +# (for example while uncompressing gzipped empty file). +# For backward-compatibility, this is not required by default. To turn +# this functionality there should be another vertical bar (|) straight +# after the first one in the LESSOPEN environment variable: +# export LESSOPEN="||/usr/bin/lesspipe.sh %s" + +if [ ! -e "$1" ] ; then + exit 1 +fi + +if [ -d "$1" ] ; then + ls -alF -- "$1" + exit $? +fi + +exec 2>/dev/null + +# Allow for user defined filters +if [ -x ~/.lessfilter ]; then + ~/.lessfilter "$1" + if [ $? -eq 0 ]; then + exit 0 + fi +fi + +manfilter () +{ + if test -x /usr/bin/man ; then + # See rhbz#1241543 for more info. Well, actually we firstly + # used 'man -l', then we switched to groff, and then we again + # switched back to 'man -l'. + /usr/bin/man -P /usr/bin/cat -l "$1" + elif test -x /usr/bin/groff; then + # This is from pre-rhbz#1241543-time. + groff -Tascii -mandoc "$1" | cat -s + else + echo "WARNING:" + echo "WARNING: to better show manual pages, install 'man-db' package" + echo "WARNING:" + cat "$1" + fi +} + +export MAN_KEEP_FORMATTING=1 + +case "$1" in +*.[1-9n].bz2|*.[1-9]x.bz2|*.man.bz2|*.[1-9n].[glx]z|*.[1-9]x.[glx]z|*.man.[glx]z|*.[1-9n].lzma|*.[1-9]x.lzma|*.man.lzma|*.[1-9n].zst|*.[1-9]x.zst|*.man.zst|*.[1-9n].br|*.[1-9]x.br|*.man.br) + case "$1" in + *.gz) DECOMPRESSOR="gzip -dc" ;; + *.bz2) DECOMPRESSOR="bzip2 -dc" ;; + *.lz) DECOMPRESSOR="lzip -dc" ;; + *.zst) DECOMPRESSOR="zstd -dcq" ;; + *.br) DECOMPRESSOR="brotli -dc" ;; + *.xz|*.lzma) DECOMPRESSOR="xz -dc" ;; + esac + if [ -n "$DECOMPRESSOR" ] && $DECOMPRESSOR -- "$1" | file - | grep -q troff; then + $DECOMPRESSOR -- "$1" | manfilter - + exit $? + fi ;;& +*.[1-9n]|*.[1-9]x|*.man) + if file "$1" | grep -q troff; then + manfilter "$1" + exit $? + fi ;;& +*.tar) tar tvvf "$1"; exit $? ;; +*.tgz|*.tar.gz|*.tar.[zZ]) tar tzvvf "$1"; exit $? ;; +*.tar.xz) tar Jtvvf "$1"; exit $? ;; +*.xz|*.lzma) xz -dc -- "$1"; exit $? ;; +*.tar.lz) tar --lzip -tvvf "$1"; exit $? ;; +*.lz) lzip -dc -- "$1"; exit $? ;; +*.tar.zst) tar --zstd -tvvf "$1"; exit $? ;; +*.zst) zstd -dcq -- "$1"; exit $? ;; +*.tar.br) brotli -dc -- "$1" | tar tvvf -; exit $? ;; +*.br) brotli -dc -- "$1"; exit $? ;; +*.tar.bz2|*.tbz2) bzip2 -dc -- "$1" | tar tvvf -; exit $? ;; +*.[zZ]|*.gz) gzip -dc -- "$1"; exit $? ;; +*.bz2) bzip2 -dc -- "$1"; exit $? ;; +*.zip|*.jar|*.nbm) zipinfo -- "$1"; exit $? ;; +# --nomanifest -> rhbz#1450277 +*.rpm) rpm -qpivl --changelog --nomanifest -- "$1"; exit $? ;; +*.cpi|*.cpio) cpio -itv < "$1"; exit $? ;; +*.gpg) + if [ -x /usr/bin/gpg2 ]; then + gpg2 -d "$1" + exit $? + elif [ -x /usr/bin/gpg ]; then + gpg -d "$1" + exit $? + else + echo "No GnuPG available." + echo "Install gnupg2 or gnupg to show encrypted files." + exit 1 + fi ;; +*.gif|*.jpeg|*.jpg|*.pcd|*.png|*.tga|*.tiff|*.tif) + if [ -x /usr/bin/identify ]; then + identify "$1" + exit $? + elif [ -x /usr/bin/gm ]; then + gm identify "$1" + exit $? + else + echo "No identify available" + echo "Install ImageMagick or GraphicsMagick to browse images" + exit 1 + fi ;; +*) + if [ -x /usr/bin/file ] && [ -x /usr/bin/iconv ] && [ -x /usr/bin/cut ]; then + case `file -b "$1"` in + *UTF-16*) conv='UTF-16' ;; + *UTF-32*) conv='UTF-32' ;; + esac + if [ -n "$conv" ]; then + env=`echo $LANG | cut -d. -f2` + if [ -n "$env" -a "$conv" != "$env" ]; then + iconv -f $conv -t $env "$1" + exit $? + fi + fi + fi + exit 1 +esac