diff --git a/backport-fixes-for-glibc-time-gettimeofday-issue-fix-issue-wi.patch b/backport-fixes-for-glibc-time-gettimeofday-issue-fix-issue-wi.patch new file mode 100644 index 0000000000000000000000000000000000000000..6fcff1e0dbb173968ea1a02e97e0b17431fe1580 --- /dev/null +++ b/backport-fixes-for-glibc-time-gettimeofday-issue-fix-issue-wi.patch @@ -0,0 +1,148 @@ +From 64b2b7c08d427796d75411f5d3ea46e585ad2d4b Mon Sep 17 00:00:00 2001 +From: Chet Ramey +Date: Mon, 27 Mar 2023 09:28:12 -0400 +Subject: [PATCH] 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 + +--- + lib/readline/histfile.c | 36 ++++++++++++++++++++++++++++++----------- + lib/readline/misc.c | 5 +++++ + lib/readline/undo.c | 2 ++ + 3 files changed, 43 insertions(+), 11 deletions(-) + create mode 100644 tests/history7.sub + +diff --git a/lib/readline/histfile.c b/lib/readline/histfile.c +index a3c8d9bf..2af71d35 100644 +--- a/lib/readline/histfile.c ++++ b/lib/readline/histfile.c +@@ -1,6 +1,6 @@ + /* histfile.c - functions to manipulate the history file. */ + +-/* Copyright (C) 1989-2019 Free Software Foundation, Inc. ++/* Copyright (C) 1989-2019,2023 Free Software Foundation, Inc. + + This file contains the GNU History Library (History), a set of + routines for managing the text of previously typed lines. +@@ -578,6 +578,15 @@ history_truncate_file (const char *fname, int lines) + 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 +595,39 @@ history_truncate_file (const char *fname, int lines) + 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; + } + +@@ -623,15 +640,22 @@ history_truncate_file (const char *fname, int lines) + goto truncate_exit; + } + ++truncate_write: + tempname = history_tempfile (filename); + + 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; ++ { ++ rv = errno; ++ close (file); ++ } + + if (fstat (file, &nfinfo) < 0 && rv == 0) +- rv = errno; ++ { ++ rv = errno; ++ close (file); ++ } + + if (close (file) < 0 && rv == 0) + rv = errno; +diff --git a/lib/readline/misc.c b/lib/readline/misc.c +index 764482a0..e1ccecae 100644 +--- a/lib/readline/misc.c ++++ b/lib/readline/misc.c +@@ -340,6 +340,11 @@ rl_maybe_replace_line (void) + xfree (temp->line); + FREE (temp->timestamp); + xfree (temp); ++ /* What about _rl_saved_line_for_history? if the saved undo list is ++ rl_undo_list, and we just put that into a history entry, should ++ we set the saved undo list to NULL? */ ++ if (_rl_saved_line_for_history && (UNDO_LIST *)_rl_saved_line_for_history->data == rl_undo_list) ++ _rl_saved_line_for_history->data = 0; + } + return 0; + } +diff --git a/lib/readline/undo.c b/lib/readline/undo.c +index c9c2a5b2..492894c3 100644 +--- a/lib/readline/undo.c ++++ b/lib/readline/undo.c +@@ -122,6 +122,8 @@ rl_free_undo_list (void) + _rl_free_undo_list (rl_undo_list); + rl_undo_list = (UNDO_LIST *)NULL; + _hs_replace_history_data (-1, (histdata_t *)orig_list, (histdata_t *)NULL); ++ if (_rl_saved_line_for_history && (UNDO_LIST *)_rl_saved_line_for_history->data == orig_list) ++ _rl_saved_line_for_history->data = 0; + } + + UNDO_LIST * +-- +2.33.0 + diff --git a/bash.spec b/bash.spec index ec5dfa88e605181a4ac31aadd2a24280df8d80bf..fe6ce4342f4785b18056035c9cbc431bced836e0 100644 --- a/bash.spec +++ b/bash.spec @@ -2,7 +2,7 @@ Name: bash Version: 5.2.15 -Release: 17 +Release: 18 Summary: It is the Bourne Again Shell License: GPLv3 URL: https://www.gnu.org/software/bash @@ -44,6 +44,7 @@ Patch6014: backport-fix-typo-in-readline-custom-LS_COLORS-extension-fix-.patch Patch6015: backport-fourth-set-of-ANSI-C-changes-size_t-rest-globskipdot.patch Patch6016: backport-documentation-updates-fix-for-null-commands-with-red.patch Patch6017: backport-fix-for-readline-redisplay-issue-in-C-locale-fix-for.patch +Patch6018: backport-fixes-for-glibc-time-gettimeofday-issue-fix-issue-wi.patch %if %{enable_safecheck} Patch9000: only-scripts-verified-by-execveat-are-allowed-to-run.patch @@ -176,6 +177,9 @@ make check %exclude %{_infodir}/dir %changelog +* Tue Sep 16 2025 fuanan - 5.2.15-18 +- fix issue with history file containing one line too few if saving timestamps + * Mon Jun 23 2025 Linux_zhang - 5.2.15-17 - sync patches from bash community