2 Commits

Author SHA256 Message Date
Werner Fink
578eeeff43 Add patch bsc1245199.patch
Fix histfile missing timestamp for the oldest record (bsc#1245199)

Signed-off-by: Werner Fink <werner@suse.de>
2025-10-23 16:31:52 +02:00
d5e7391c1f Sync changes to SLFO-1.2 branch 2025-08-20 12:59:13 +02:00
10 changed files with 561 additions and 18 deletions

124
bsc1245199.patch Normal file
View File

@@ -0,0 +1,124 @@
based on commit 64b2b7c08d427796d75411f5d3ea46e585ad2d4b
Author: Chet Ramey <chet.ramey@case.edu>
Date: Mon Mar 27 09:28:12 2023 -0400
fixes for glibc time/gettimeofday issue; fix issue with history file containing one line too few if saving timestamps; fix for signal arriving while displaying readline completions
---
histfile.c | 60 ++++++++++++++++++++++++++++++++++++++++++++----------------
1 file changed, 44 insertions(+), 16 deletions(-)
--- a/histfile.c
+++ b/histfile.c 2025-05-02 15:48:40.000000000 +0200
@@ -526,10 +548,14 @@ history_truncate_file (const char *fname
buffer = (char *)NULL;
filename = history_filename (fname);
+ if (filename == 0)
+ return 0;
tempname = 0;
- file = filename ? open (filename, O_RDONLY|O_BINARY, 0666) : -1;
+ file = open (filename, O_RDONLY|O_BINARY, 0666);
rv = exists = 0;
+ orig_lines = lines;
+
/* Don't try to truncate non-regular files. */
if (file == -1 || fstat (file, &finfo) == -1)
{
@@ -578,6 +604,15 @@ history_truncate_file (const char *fname
goto truncate_exit;
}
+ /* Don't bother with any of this if we're truncating to zero length. */
+ if (lines == 0)
+ {
+ close (file);
+ buffer[chars_read = 0] = '\0';
+ bp = buffer;
+ goto truncate_write;
+ }
+
chars_read = read (file, buffer, file_size);
close (file);
@@ -586,31 +621,38 @@ history_truncate_file (const char *fname
rv = (chars_read < 0) ? errno : 0;
goto truncate_exit;
}
+ buffer[chars_read] = '\0'; /* for the initial check of bp1[1] */
- orig_lines = lines;
/* Count backwards from the end of buffer until we have passed
LINES lines. bp1 is set funny initially. But since bp[1] can't
be a comment character (since it's off the end) and *bp can't be
- both a newline and the history comment character, it should be OK. */
- for (bp1 = bp = buffer + chars_read - 1; lines && bp > buffer; bp--)
+ both a newline and the history comment character, it should be OK.
+ If we are writing history timestamps, we need to add one to LINES
+ because we decrement it one extra time the first time through the loop
+ and we need the final timestamp line. */
+ lines += history_write_timestamps;
+ for (bp1 = bp = buffer + chars_read - 1; lines > 0 && bp > buffer; bp--)
{
if (*bp == '\n' && HIST_TIMESTAMP_START(bp1) == 0)
lines--;
bp1 = bp;
}
- /* If this is the first line, then the file contains exactly the
+ /* This is the right line, so move to its start. If we're writing history
+ timestamps, we want to go back until *bp == '\n' and bp1 starts a
+ history timestamp. If we're not, just move back to *bp == '\n'.
+ If this is the first line, then the file contains exactly the
number of lines we want to truncate to, so we don't need to do
- anything. It's the first line if we don't find a newline between
- the current value of i and 0. Otherwise, write from the start of
- this line until the end of the buffer. */
+ anything, and we'll end up with bp == buffer.
+ Otherwise, write from the start of this line until the end of the
+ buffer. */
for ( ; bp > buffer; bp--)
{
- if (*bp == '\n' && HIST_TIMESTAMP_START(bp1) == 0)
- {
+ if (*bp == '\n' && (history_write_timestamps == 0 || HIST_TIMESTAMP_START(bp1)))
+ {
bp++;
break;
- }
+ }
bp1 = bp;
}
@@ -624,17 +666,25 @@ history_truncate_file (const char *fname
goto truncate_exit;
}
+truncate_write:
tempname = history_tempfile (filename);
+ rv = 0;
if ((file = open (tempname, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0600)) != -1)
{
if (write (file, bp, chars_read - (bp - buffer)) < 0)
- rv = errno;
-
- if (fstat (file, &nfinfo) < 0 && rv == 0)
- rv = errno;
+ {
+ rv = errno;
+ close (file);
+ }
+
+ if (rv == 0 && fstat (file, &nfinfo) < 0)
+ {
+ rv = errno;
+ close (file);
+ }
- if (close (file) < 0 && rv == 0)
+ if (rv == 0 && close (file) < 0)
rv = errno;
}
else

View File

@@ -5,10 +5,9 @@
doc/readline.3 | 11 +++++++++++
examples/fileman.c | 2 +-
history.h | 1 +
readline.c | 7 +++++--
readline.h | 3 ++-
support/shobj-conf | 5 +++--
9 files changed, 28 insertions(+), 13 deletions(-)
8 files changed, 23 insertions(+), 11 deletions(-)
--- Makefile.in
+++ Makefile.in 2022-04-28 12:16:56.148759888 +0000
@@ -120,22 +119,6 @@
# include <readline/rlstdc.h>
# include <readline/rltypedefs.h>
#endif
--- readline.c
+++ readline.c 2022-04-28 12:16:56.152759816 +0000
@@ -906,8 +906,11 @@ _rl_dispatch_subseq (register int key, K
{
/* Special case rl_do_lowercase_version (). */
if (func == rl_do_lowercase_version)
- /* Should we do anything special if key == ANYOTHERKEY? */
- return (_rl_dispatch (_rl_to_lower ((unsigned char)key), map));
+ {
+ if (key == ANYOTHERKEY)
+ return -1;
+ return (_rl_dispatch (_rl_to_lower ((unsigned char)key), map));
+ }
rl_executing_keymap = map;
rl_executing_key = key;
--- readline.h
+++ readline.h 2022-04-28 12:17:48.115828027 +0000
@@ -32,6 +32,7 @@ extern "C" {

View File

@@ -1,3 +1,26 @@
-------------------------------------------------------------------
Tue Oct 14 11:36:41 UTC 2025 - Dr. Werner Fink <werner@suse.de>
- Add patch bsc1245199.patch
* Fix histfile missing timestamp for the oldest record (bsc#1245199)
-------------------------------------------------------------------
Mon Aug 19 09:02:51 UTC 2024 - Dr. Werner Fink <werner@suse.de>
- Add upstream patches
* readline82-011
Some systems (e.g., macOS) send signals early on in interactive
initialization, so readline should retry a failed open of the init file.
* readline82-012
If a user happens to bind do-lowercase-version to something that isn't a
capital letter, so _rl_to_lower doesn't change anything and the result is
still bound to do-lowercase-version, readline can recurse infinitely.
* readline82-013
When readline is accumulating bytes until it reads a complete multibyte
character, reading a byte that makes the multibyte character invalid can
result in discarding the bytes in the partial character.
- Port patch readline-8.2.dif
-------------------------------------------------------------------
Tue Jan 16 07:49:48 UTC 2024 - Dr. Werner Fink <werner@suse.de>

View File

@@ -46,6 +46,9 @@ Patch107: readline82-007
Patch108: readline82-008
Patch109: readline82-009
Patch110: readline82-010
Patch111: readline82-011
Patch112: readline82-012
Patch113: readline82-013
Source101: readline82-001.sig
Source102: readline82-002.sig
Source103: readline82-003.sig
@@ -56,11 +59,15 @@ Source107: readline82-007.sig
Source108: readline82-008.sig
Source109: readline82-009.sig
Source110: readline82-010.sig
Source111: readline82-011.sig
Source112: readline82-012.sig
Source113: readline82-013.sig
# local patches
Patch200: readline-%{rversion}.dif
Patch201: readline-6.3-input.dif
Patch202: readline-5.2-conf.patch
Patch203: readline-6.2-metamode.patch
Patch204: bsc1245199.patch
Patch205: readline-6.2-xmalloc.dif
Patch206: readline-6.3-destdir.patch
Patch207: readline-6.3-rltrace.patch
@@ -138,10 +145,14 @@ as well as programming with the interface of the readline library.
%patch -P108 -p0
%patch -P109 -p0
%patch -P110 -p0
%patch -P111 -p0
%patch -P112 -p0
%patch -P113 -p0
# local patches
%patch -P201 -p2 -b .zerotty
%patch -P202 -p2 -b .conf
%patch -P203 -p2 -b .metamode
%patch -P204 -p1
%patch -P205 -b .xm
%patch -P206 -b .destdir
%patch -P207 -p2 -b .tmp

75
readline82-011 Normal file
View File

@@ -0,0 +1,75 @@
READLINE PATCH REPORT
=====================
Readline-Release: 8.2
Patch-ID: readline82-011
Bug-Reported-by: Grisha Levit <grishalevit@gmail.com>
Bug-Reference-ID: <CAMu=BrqWa_iNkiEwchpFmtrUhFrAanOO8pjy7VCKqRKUvqdsbw@mail.gmail.com>
Bug-Reference-URL: https://lists.gnu.org/archive/html/bug-bash/2024-02/msg00075.html
Bug-Description:
Patch (apply with `patch -p0'):
Some systems (e.g., macOS) send signals early on in interactive initialization,
so readline should retry a failed open of the init file.
*** ../readline-8.2-patched/bind.c Wed Feb 9 11:02:22 2022
--- bind.c Tue Apr 23 15:07:13 2024
***************
*** 979,987 ****
int i, file;
! file = -1;
! if (((file = open (filename, O_RDONLY, 0666)) < 0) || (fstat (file, &finfo) < 0))
{
if (file >= 0)
close (file);
return ((char *)NULL);
}
--- 969,986 ----
int i, file;
! file = open (filename, O_RDONLY, 0666);
! /* If the open is interrupted, retry once */
! if (file < 0 && errno == EINTR)
{
+ RL_CHECK_SIGNALS ();
+ file = open (filename, O_RDONLY, 0666);
+ }
+
+ if ((file < 0) || (fstat (file, &finfo) < 0))
+ {
+ i = errno;
if (file >= 0)
close (file);
+ errno = i;
return ((char *)NULL);
}
***************
*** 992,999 ****
--- 991,1001 ----
if (file_size != finfo.st_size || file_size + 1 < file_size)
{
+ i = errno;
if (file >= 0)
close (file);
#if defined (EFBIG)
errno = EFBIG;
+ #else
+ errno = i;
#endif
return ((char *)NULL);
*** ../readline-8.2/patchlevel 2013-11-15 08:11:11.000000000 -0500
--- patchlevel 2014-03-21 08:28:40.000000000 -0400
***************
*** 1,3 ****
# Do not edit -- exists only for use by patch
! 10
--- 1,3 ----
# Do not edit -- exists only for use by patch
! 11

BIN
readline82-011.sig Normal file

Binary file not shown.

93
readline82-012 Normal file
View File

@@ -0,0 +1,93 @@
READLINE PATCH REPORT
=====================
Readline-Release: 8.2
Patch-ID: readline82-012
Bug-Reported-by: Grisha Levit <grishalevit@gmail.com>
Bug-Reference-ID: <CAMu=BroaH+41uumYt89FPqt8Fsatj-d6mZzmPV2HZYjtcbvbvw@mail.gmail.com>
Bug-Reference-URL: https://lists.gnu.org/archive/html/bug-readline/2023-11/msg00019.html
Bug-Description:
If a user happens to bind do-lowercase-version to something that isn't a
capital letter, so _rl_to_lower doesn't change anything and the result is
still bound to do-lowercase-version, readline can recurse infinitely.
Patch (apply with `patch -p0'):
*** ../readline-8.2-patched/readline.c Thu Aug 11 18:35:37 2022
--- readline.c Fri Feb 2 12:05:36 2024
***************
*** 900,905 ****
/* Special case rl_do_lowercase_version (). */
if (func == rl_do_lowercase_version)
! /* Should we do anything special if key == ANYOTHERKEY? */
! return (_rl_dispatch (_rl_to_lower ((unsigned char)key), map));
rl_executing_keymap = map;
--- 912,926 ----
/* Special case rl_do_lowercase_version (). */
if (func == rl_do_lowercase_version)
! {
! /* Should we do anything special if key == ANYOTHERKEY? */
! newkey = _rl_to_lower ((unsigned char)key);
! if (newkey != key)
! return (_rl_dispatch (newkey, map));
! else
! {
! rl_ding (); /* gentle failure */
! return 0;
! }
! }
rl_executing_keymap = map;
***************
*** 1110,1114 ****
func = m[ANYOTHERKEY].function;
if (type == ISFUNC && func == rl_do_lowercase_version)
! r = _rl_dispatch (_rl_to_lower ((unsigned char)key), map);
else if (type == ISFUNC)
{
--- 1131,1139 ----
func = m[ANYOTHERKEY].function;
if (type == ISFUNC && func == rl_do_lowercase_version)
! {
! int newkey = _rl_to_lower ((unsigned char)key);
! /* check that there is actually a lowercase version to avoid infinite recursion */
! r = (newkey != key) ? _rl_dispatch (newkey, map) : 1;
! }
else if (type == ISFUNC)
{
*** ../readline-8.2-patched/isearch.c Thu Aug 11 18:35:37 2022
--- isearch.c Fri Feb 2 12:05:36 2024
***************
*** 429,433 ****
f = cxt->keymap[c].function;
if (f == rl_do_lowercase_version)
! f = cxt->keymap[_rl_to_lower (c)].function;
}
--- 431,439 ----
f = cxt->keymap[c].function;
if (f == rl_do_lowercase_version)
! {
! f = cxt->keymap[_rl_to_lower (c)].function;
! if (f == rl_do_lowercase_version)
! f = rl_insert;
! }
}
*** ../readline-8.2/patchlevel 2013-11-15 08:11:11.000000000 -0500
--- patchlevel 2014-03-21 08:28:40.000000000 -0400
***************
*** 1,3 ****
# Do not edit -- exists only for use by patch
! 11
--- 1,3 ----
# Do not edit -- exists only for use by patch
! 12

BIN
readline82-012.sig Normal file

Binary file not shown.

234
readline82-013 Normal file
View File

@@ -0,0 +1,234 @@
READLINE PATCH REPORT
=====================
Readline-Release: 8.2
Patch-ID: readline82-013
Bug-Reported-by: Grisha Levit <grishalevit@gmail.com>
Bug-Reference-ID: <CAMu=Brrv5qKY6LPfw8PxqNXNO8rNsZo0Fb=BcFb-uHObWPqnrw@mail.gmail.
Bug-Reference-URL: https://lists.gnu.org/archive/html/bug-bash/2023-04/msg00082.html
Bug-Description:
When readline is accumulating bytes until it reads a complete multibyte
character, reading a byte that makes the multibyte character invalid can
result in discarding the bytes in the partial character.
Patch (apply with `patch -p0'):
*** ../readline-8.2-patched/text.c Mon May 1 09:37:52 2023
--- text.c Mon May 29 12:22:29 2023
***************
*** 86,90 ****
rl_insert_text (const char *string)
{
! register int i, l;
l = (string && *string) ? strlen (string) : 0;
--- 86,91 ----
rl_insert_text (const char *string)
{
! register int i;
! size_t l;
l = (string && *string) ? strlen (string) : 0;
***************
*** 705,709 ****
/* Insert the character C at the current location, moving point forward.
If C introduces a multibyte sequence, we read the whole sequence and
! then insert the multibyte char into the line buffer. */
int
_rl_insert_char (int count, int c)
--- 706,714 ----
/* Insert the character C at the current location, moving point forward.
If C introduces a multibyte sequence, we read the whole sequence and
! then insert the multibyte char into the line buffer.
! If C == 0, we immediately insert any pending partial multibyte character,
! assuming that we have read a character that doesn't map to self-insert.
! This doesn't completely handle characters that are part of a multibyte
! character but map to editing functions. */
int
_rl_insert_char (int count, int c)
***************
*** 719,727 ****
#endif
if (count <= 0)
return 0;
! #if defined (HANDLE_MULTIBYTE)
! if (MB_CUR_MAX == 1 || rl_byte_oriented)
{
incoming[0] = c;
--- 724,749 ----
#endif
+ #if !defined (HANDLE_MULTIBYTE)
if (count <= 0)
return 0;
+ #else
+ if (count < 0)
+ return 0;
+ if (count == 0)
+ {
+ if (pending_bytes_length == 0)
+ return 0;
+ if (stored_count <= 0)
+ stored_count = count;
+ else
+ count = stored_count;
! memcpy (incoming, pending_bytes, pending_bytes_length);
! incoming[pending_bytes_length] = '\0';
! incoming_length = pending_bytes_length;
! pending_bytes_length = 0;
! memset (&ps, 0, sizeof (mbstate_t));
! }
! else if (MB_CUR_MAX == 1 || rl_byte_oriented)
{
incoming[0] = c;
***************
*** 731,734 ****
--- 753,759 ----
else if (_rl_utf8locale && (c & 0x80) == 0)
{
+ if (pending_bytes_length)
+ _rl_insert_char (0, 0);
+
incoming[0] = c;
incoming[1] = '\0';
***************
*** 765,769 ****
incoming_length = 1;
pending_bytes_length--;
! memmove (pending_bytes, pending_bytes + 1, pending_bytes_length);
/* Clear the state of the byte sequence, because in this case the
effect of mbstate is undefined. */
--- 790,795 ----
incoming_length = 1;
pending_bytes_length--;
! if (pending_bytes_length)
! memmove (pending_bytes, pending_bytes + 1, pending_bytes_length);
/* Clear the state of the byte sequence, because in this case the
effect of mbstate is undefined. */
***************
*** 828,832 ****
--- 854,862 ----
xfree (string);
+ #if defined (HANDLE_MULTIBYTE)
+ return (pending_bytes_length != 0);
+ #else
return 0;
+ #endif
}
***************
*** 861,864 ****
--- 891,896 ----
incoming_length = 0;
stored_count = 0;
+
+ return (pending_bytes_length != 0);
#else /* !HANDLE_MULTIBYTE */
char str[TEXT_COUNT_MAX+1];
***************
*** 874,880 ****
count -= decreaser;
}
- #endif /* !HANDLE_MULTIBYTE */
return 0;
}
--- 906,912 ----
count -= decreaser;
}
return 0;
+ #endif /* !HANDLE_MULTIBYTE */
}
***************
*** 904,910 ****
stored_count = 0;
}
! #endif
!
return 0;
}
--- 936,944 ----
stored_count = 0;
}
!
! return (pending_bytes_length != 0);
! #else
return 0;
+ #endif
}
***************
*** 984,987 ****
--- 1018,1026 ----
}
+ /* If we didn't insert n and there are pending bytes, we need to insert
+ them if _rl_insert_char didn't do that on its own. */
+ if (r == 1 && rl_insert_mode == RL_IM_INSERT)
+ r = _rl_insert_char (0, 0); /* flush partial multibyte char */
+
if (n != (unsigned short)-2) /* -2 = sentinel value for having inserted N */
{
***************
*** 1055,1058 ****
--- 1094,1099 ----
rl_quoted_insert (int count, int key)
{
+ int r;
+
/* Let's see...should the callback interface futz with signal handling? */
#if defined (HANDLE_SIGNALS)
***************
*** 1073,1085 ****
if (count < 0)
{
- int r;
-
do
r = _rl_insert_next (1);
while (r == 0 && ++count < 0);
- return r;
}
! return _rl_insert_next (count);
}
--- 1114,1128 ----
if (count < 0)
{
do
r = _rl_insert_next (1);
while (r == 0 && ++count < 0);
}
+ else
+ r = _rl_insert_next (count);
! if (r == 1)
! _rl_insert_char (0, 0); /* insert partial multibyte character */
!
! return r;
}
*** ../readline-8.2/patchlevel 2013-11-15 08:11:11.000000000 -0500
--- patchlevel 2014-03-21 08:28:40.000000000 -0400
***************
*** 1,3 ****
# Do not edit -- exists only for use by patch
! 12
--- 1,3 ----
# Do not edit -- exists only for use by patch
! 13

BIN
readline82-013.sig Normal file

Binary file not shown.