This commit is contained in:
joborun linux 2024-08-27 12:22:15 +03:00
parent 9003671037
commit faeaea0f2e
11 changed files with 520 additions and 8 deletions

View file

@ -9,7 +9,7 @@ pkgname=bash
_basever=5.2 _basever=5.2
_patchlevel=032 _patchlevel=032
pkgver=${_basever}.${_patchlevel} pkgver=${_basever}.${_patchlevel}
pkgrel=01 pkgrel=02
pkgdesc='The GNU Bourne Again shell' pkgdesc='The GNU Bourne Again shell'
_url='https://www.gnu.org/software/bash/bash.html' _url='https://www.gnu.org/software/bash/bash.html'
url="https://ftp.gnu.org/gnu" url="https://ftp.gnu.org/gnu"
@ -23,6 +23,7 @@ source=($url/$pkgname/bash-$_basever.tar.gz{,.sig}
bash-5.2_p21-configure-strtold.patch bash-5.2_p21-configure-strtold.patch
bash-5.2_p21-wpointer-to-int.patch bash-5.2_p21-wpointer-to-int.patch
bash-5.2_p32-memory-leaks.patch bash-5.2_p32-memory-leaks.patch
bash-5.2_p32-read-delimiter-in-invalid-mbchar.patch
dot.bashrc dot.bashrc
dot.bash_profile dot.bash_profile
dot.bash_logout dot.bash_logout
@ -52,7 +53,7 @@ prepare() {
patch -Np0 -i ../bash-5.2_p21-configure-strtold.patch patch -Np0 -i ../bash-5.2_p21-configure-strtold.patch
patch -Np0 -i ../bash-5.2_p21-wpointer-to-int.patch patch -Np0 -i ../bash-5.2_p21-wpointer-to-int.patch
patch -Np0 -i ../bash-5.2_p32-memory-leaks.patch patch -Np0 -i ../bash-5.2_p32-memory-leaks.patch
patch -Np0 -i ../bash-5.2_p32-read-delimiter-in-invalid-mbchar.patch
} }
build() { build() {
@ -109,6 +110,7 @@ sha256sums=(a139c166df7ff4471c5e0733051642ee5556c1cc8a4a78f145583c5c81ab32fb #
9038e9942e0d3b234e14bc082672b79875a7fc57a31f862f3194186aef32598c # bash-5.2_p21-configure-strtold.patch 9038e9942e0d3b234e14bc082672b79875a7fc57a31f862f3194186aef32598c # bash-5.2_p21-configure-strtold.patch
77b1796ec4d70de4e838751004ee0b206e1edc719a45b692c6d5a1623ede64b9 # bash-5.2_p21-wpointer-to-int.patch 77b1796ec4d70de4e838751004ee0b206e1edc719a45b692c6d5a1623ede64b9 # bash-5.2_p21-wpointer-to-int.patch
8bfa20770ffb0fc408e5b7db96baf8db857aed3e1eb943e41df5ccf2925c5cf0 # bash-5.2_p32-memory-leaks.patch 8bfa20770ffb0fc408e5b7db96baf8db857aed3e1eb943e41df5ccf2925c5cf0 # bash-5.2_p32-memory-leaks.patch
9d0653eff47ebf46e7fd97bf7db8f1b76dbf51c3ffb99b57346ed40500256467 # bash-5.2_p32-read-delimiter-in-invalid-mbchar.patch
3e22bf86ae6708df7a6bceb88c67a00118275f9c0b5268f453dd388af7c43b53 # dot.bashrc 3e22bf86ae6708df7a6bceb88c67a00118275f9c0b5268f453dd388af7c43b53 # dot.bashrc
e149407c2bee17779caec70a7edd3d0000d172e7e4347429b80cb4d55bcec9c2 # dot.bash_profile e149407c2bee17779caec70a7edd3d0000d172e7e4347429b80cb4d55bcec9c2 # dot.bash_profile
4330edf340394d0dae50afb04ac2a621f106fe67fb634ec81c4bfb98be2a1eb5 # dot.bash_logout 4330edf340394d0dae50afb04ac2a621f106fe67fb634ec81c4bfb98be2a1eb5 # dot.bash_logout
@ -179,5 +181,5 @@ sha256sums=(a139c166df7ff4471c5e0733051642ee5556c1cc8a4a78f145583c5c81ab32fb #
7b9c77daeca93ff711781d7537234166e83ed9835ce1ee7dcd5742319c372a16 # bash52-032 7b9c77daeca93ff711781d7537234166e83ed9835ce1ee7dcd5742319c372a16 # bash52-032
0b03903dd38b4ea76bb5d59fd241b41a89fa16449f8b365350093398bcb52738) # bash52-032.sig 0b03903dd38b4ea76bb5d59fd241b41a89fa16449f8b365350093398bcb52738) # bash52-032.sig
## ff3b3265fcf15683d139ab0d2b6bae6f0230360ac2fef42e71116088ef022fef bash-5.2.032-01-x86_64.pkg.tar.lz ## 9170eadcf288cbfff6e24a2de484a5c33e7a69b61b55c51b1bc0d07a801d19f2 bash-5.2.032-02-x86_64.pkg.tar.lz

View file

@ -8,7 +8,7 @@ pkgname=bash
_basever=5.2 _basever=5.2
_patchlevel=032 _patchlevel=032
pkgver=${_basever}.${_patchlevel} pkgver=${_basever}.${_patchlevel}
pkgrel=1 pkgrel=2
pkgdesc='The GNU Bourne Again shell' pkgdesc='The GNU Bourne Again shell'
arch=(x86_64) arch=(x86_64)
license=('GPL-3.0-or-later') license=('GPL-3.0-or-later')
@ -24,6 +24,7 @@ source=(https://ftp.gnu.org/gnu/bash/bash-$_basever.tar.gz{,.sig}
bash-5.2_p21-configure-strtold.patch bash-5.2_p21-configure-strtold.patch
bash-5.2_p21-wpointer-to-int.patch bash-5.2_p21-wpointer-to-int.patch
bash-5.2_p32-memory-leaks.patch bash-5.2_p32-memory-leaks.patch
bash-5.2_p32-read-delimiter-in-invalid-mbchar.patch
dot.bashrc dot.bashrc
dot.bash_profile dot.bash_profile
dot.bash_logout dot.bash_logout
@ -43,6 +44,7 @@ b2sums=('51b196e710794ebad8eac28c31c93eb99ac1a7db30919a13271e39e1cb66a0672f242df
'83ec6ff756543ee44c18902f2d30dd662a84237b9594a7e0cfc21a1c16fce49e37cf67729b3a17d59cc978cb6675e04457e3b6b0909d94cb234a1dde96f7c9ea' '83ec6ff756543ee44c18902f2d30dd662a84237b9594a7e0cfc21a1c16fce49e37cf67729b3a17d59cc978cb6675e04457e3b6b0909d94cb234a1dde96f7c9ea'
'0c7f5eb5b697abf15c1d17888a973e44d0ead1f095778b41841a6a1937a5b9e7ce5fa6a05e4404504990b0a244fdecfc12ce7c33ee7d67b4c837435e9bfe2b57' '0c7f5eb5b697abf15c1d17888a973e44d0ead1f095778b41841a6a1937a5b9e7ce5fa6a05e4404504990b0a244fdecfc12ce7c33ee7d67b4c837435e9bfe2b57'
'373aa3be1f0a6bc65403cde63cbc4dcd612336e86b1cae918670a99e8ca639c665ac7efb467ec8823a62cec0a71c485bd3fda4bbf058d759498377f5cfe90f51' '373aa3be1f0a6bc65403cde63cbc4dcd612336e86b1cae918670a99e8ca639c665ac7efb467ec8823a62cec0a71c485bd3fda4bbf058d759498377f5cfe90f51'
'ab7fe139630be59b26a72f92f22e4a2b556594d341d82b0f15f99880724f5ea5cfd912a8de6b6e1db902c14d65395c74a03379e3e01ce69bb4512c681518301d'
'61cc3b7c9e85ae29b48518a2579896cb037153184a233cb5636d8dce4c2a2fded88624c9d5a986d86fdd4b0d521828b510c7a0d16b3c8b95cfca8d4c0a74da17' '61cc3b7c9e85ae29b48518a2579896cb037153184a233cb5636d8dce4c2a2fded88624c9d5a986d86fdd4b0d521828b510c7a0d16b3c8b95cfca8d4c0a74da17'
'2d53f99e485218ed47f2e40907023645594ac8ffcf00d0569050d54a8f4dabe0a2bdcab515a45b663283c2e6299d805b923ea7b7b789c6a4150c37a98a5b117c' '2d53f99e485218ed47f2e40907023645594ac8ffcf00d0569050d54a8f4dabe0a2bdcab515a45b663283c2e6299d805b923ea7b7b789c6a4150c37a98a5b117c'
'dbfe5c1aaea94419305c1f8c9b54b94eab515260910f2309360ff702a27032faa34514e70b31adbb1e41bd912d4e43a610939cb07565f43e05dd19813a81752e' 'dbfe5c1aaea94419305c1f8c9b54b94eab515260910f2309360ff702a27032faa34514e70b31adbb1e41bd912d4e43a610939cb07565f43e05dd19813a81752e'
@ -126,6 +128,7 @@ prepare() {
patch -Np0 -i ../bash-5.2_p21-configure-strtold.patch patch -Np0 -i ../bash-5.2_p21-configure-strtold.patch
patch -Np0 -i ../bash-5.2_p21-wpointer-to-int.patch patch -Np0 -i ../bash-5.2_p21-wpointer-to-int.patch
patch -Np0 -i ../bash-5.2_p32-memory-leaks.patch patch -Np0 -i ../bash-5.2_p32-memory-leaks.patch
patch -Np0 -i ../bash-5.2_p32-read-delimiter-in-invalid-mbchar.patch
} }
build() { build() {

View file

@ -0,0 +1,37 @@
https://lists.gnu.org/archive/html/bug-bash/2023-02/msg00000.html)
From 2cdf8b42885189b3cf7c47096b01f104e520546a Mon Sep 17 00:00:00 2001
From: Sam James <sam@gentoo.org>
Date: Thu, 2 Feb 2023 05:43:37 +0000
Subject: [PATCH] aclocal.m4: fix -Wimplicit-function-declaration in dup2 check
dup2 requires a <unistd.h> include. Fixes the following when diffing config.log
when testing with a stricter compiler:
```
-warning: call to undeclared function 'dup2'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
+error: call to undeclared function 'dup2'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
```
--- aclocal.m4
+++ aclocal.m4
@@ -238,6 +238,9 @@ AC_CACHE_VAL(bash_cv_dup2_broken,
#include <sys/types.h>
#include <fcntl.h>
#include <stdlib.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
int
main()
{
--- configure
+++ configure
@@ -18121,6 +18121,9 @@ else $as_nop
#include <sys/types.h>
#include <fcntl.h>
#include <stdlib.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
int
main()
{

View file

@ -0,0 +1,13 @@
https://lists.gnu.org/archive/html/bug-bash/2023-01/msg00016.html
https://git.savannah.gnu.org/cgit/bash.git/commit/?h=devel&id=0647e53bd15c8982d89a03c2db1643aedd7cd649
--- lib/sh/random.c
+++ lib/sh/random.c
@@ -75,7 +75,7 @@ u_bits32_t last;
/* Can't seed with 0. */
ret = (last == 0) ? 123459876 : last;
h = ret / 127773;
- l = ret - (127773 * h);
+ l = ret % 127773;
t = 16807 * l - 2836 * h;
ret = (t < 0) ? t + 0x7fffffff : t;

View file

@ -0,0 +1,32 @@
https://src.fedoraproject.org/rpms/bash/blob/bd5ac20b134f2936c54245fc83a8e70207d3e07e/f/bash-configure-c99-2.patch
Another C compatibility issue: char ** and char * are distinct types,
and strtold expects the former for its second argument.
Submitted upstream:
<https://lists.gnu.org/archive/html/bug-bash/2023-11/msg00104.html>
--- configure.ac
+++ configure.ac
@@ -885,7 +885,7 @@ AC_CHECK_DECLS([strtold], [
[AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[[#include <stdlib.h>]],
- [[long double r; char *foo, bar; r = strtold(foo, &bar);]]
+ [[long double r; char *foo, *bar; r = strtold(foo, &bar);]]
)],
[bash_cv_strtold_broken=no],[bash_cv_strtold_broken=yes])
]
--- configure
+++ configure
@@ -15676,7 +15676,7 @@ else $as_nop
int
main (void)
{
-long double r; char *foo, bar; r = strtold(foo, &bar);
+long double r; char *foo, *bar; r = strtold(foo, &bar);
;
return 0;

View file

@ -0,0 +1,13 @@
https://lists.gnu.org/archive/html/bug-bash/2023-03/msg00116.html
https://git.savannah.gnu.org/cgit/bash.git/commit/?h=devel&id=57d4dc15ff35895a1c1248f948f59739ffb99fde
--- lib/sh/random.c
+++ lib/sh/random.c
@@ -90,7 +90,7 @@ genseed ()
u_bits32_t iv;
gettimeofday (&tv, NULL);
- iv = (u_bits32_t)seedrand; /* let the compiler truncate */
+ iv = (uintptr_t)seedrand; /* let the compiler truncate */
iv = tv.tv_sec ^ tv.tv_usec ^ getpid () ^ getppid () ^ current_user.uid ^ iv;
return (iv);
}

View file

@ -0,0 +1,114 @@
https://lists.gnu.org/archive/html/bug-bash/2024-01/msg00036.html
https://lists.gnu.org/archive/html/bug-bash/2024-01/txtm8yNNPR9RQ.txt
For evalstring.c:
* https://lists.gnu.org/archive/html/bug-bash/2024-01/msg00011.html
* https://git.savannah.gnu.org/cgit/bash.git/diff/builtins/evalstring.c?h=devel&id=81f7b44564cd1510788035cea7c59631865a7db2&dt=1#n766
From 711ab85262884f2b91f09eceb9aefd0e2426ce67 Mon Sep 17 00:00:00 2001
From: Grisha Levit <grishalevit@gmail.com>
Date: Sat, 3 Jun 2023 16:51:26 -0400
Subject: [PATCH] various leaks
Found mostly by normal usage running a no-bash-malloc build with clang's
LeakSanitizer enabled. So far seems to provide very accurate results.
* arrayfunc.c
- quote_compound_array_word: make sure to free VALUE
- bind_assoc_var_internal: if assigning to a dynamic variable, make sure
to free the key (usually assoc_insert would do it)
* bashline.c
- bash_command_name_stat_hook: free original *NAME if we are going to
change what it points to (what the callers seem to expect)
* builtins/evalstring.c
- parse_and_execute: make sure to dispose of the parsed command
resulting from a failed function import attempt
- open_redir_file: if we did not get a pointer to pass back the expanded
filename, make sure to free the name
* examples/loadables/stat.c
- loadstat: bind_assoc_variable does not free its VALUE argument so make
sure to do it
* subst.c
- param_expand: free temp1 value for codepaths that don't do it
---
arrayfunc.c | 6 +++++-
bashline.c | 1 +
builtins/evalstring.c | 4 ++++
examples/loadables/stat.c | 1 +
subst.c | 2 ++
5 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/arrayfunc.c b/arrayfunc.c
index 2c05d15b..8ba64084 100644
--- arrayfunc.c
+++ arrayfunc.c
@@ -208,7 +208,10 @@ bind_assoc_var_internal (entry, hash, key, value, flags)
newval = make_array_variable_value (entry, 0, key, value, flags);
if (entry->assign_func)
- (*entry->assign_func) (entry, newval, 0, key);
+ {
+ (*entry->assign_func) (entry, newval, 0, key);
+ FREE (key);
+ }
else
assoc_insert (hash, key, newval);
@@ -985,6 +988,7 @@ quote_compound_array_word (w, type)
if (t != w+ind)
free (t);
strcpy (nword + i, value);
+ free (value);
return nword;
}
diff --git a/bashline.c b/bashline.c
index c85b05b6..bd7548cc 100644
--- bashline.c
+++ bashline.c
@@ -1928,6 +1928,7 @@ bash_command_name_stat_hook (name)
result = search_for_command (cname, 0);
if (result)
{
+ FREE (*name);
*name = result;
return 1;
}
diff --git a/examples/loadables/stat.c b/examples/loadables/stat.c
index 1e60e7b6..ed5c9764 100644
--- examples/loadables/stat.c
+++ examples/loadables/stat.c
@@ -349,6 +349,7 @@ loadstat (vname, var, fname, flags, fmt, sp)
key = savestring (arraysubs[i]);
value = statval (i, fname, flags, fmt, sp);
v = bind_assoc_variable (var, vname, key, value, ASS_FORCE);
+ free (value);
}
return 0;
}
diff --git a/subst.c b/subst.c
index 1ac6eb2d..ff0602da 100644
--- subst.c
+++ subst.c
@@ -10727,6 +10727,7 @@ comsub:
{
chk_atstar (temp, quoted, pflags, quoted_dollar_at_p, contains_dollar_at);
tdesc = parameter_brace_expand_word (temp, SPECIAL_VAR (temp, 0), quoted, pflags, 0);
+ free (temp1);
if (tdesc == &expand_wdesc_error || tdesc == &expand_wdesc_fatal)
return (tdesc);
ret = tdesc;
@@ -10739,6 +10740,7 @@ comsub:
{
set_exit_status (EXECUTION_FAILURE);
report_error (_("%s: invalid variable name for name reference"), temp);
+ free (temp1);
return (&expand_wdesc_error); /* XXX */
}
else
--
2.43.0

View file

@ -0,0 +1,297 @@
From 0432ec33408ac124b620c44416c9c58f0c10b63b Mon Sep 17 00:00:00 2001
From: Kerin Millar <kfm@plushkava.net>
Date: Fri, 23 Aug 2024 04:14:36 +0100
Subject: [PATCH] Backport fix for issue with read delimiter in invalid
mutibyte char
This addresses a regression introduced by 5.0. Consider the following
test case.
for i in {194..245}; do printf -v o %o "$i"; printf "\\$o\\n"; done |
while read -r; do declare -p REPLY; done
BEFORE
declare -- REPLY=$'\302\n\303\n\304\n\305\n\306\n\307\n\310\n\311\n\312\
n\313\n\314\n\315\n\316\n\317\n\320\n\321\n\322\n\323\n\324\n\325\n\326\
n\327\n\330\n\331\n\332\n\333\n\334\n\335\n\336\n\337\n\340\n\341\n\342\
n\343\n\344\n\345\n\346\n\347\n\350\n\351\n\352\n\353\n\354\n\355\n\356\
n\357\n\360\n\361\n\362\n\363\n\364\n\365'
AFTER
declare -- REPLY=$'\302'
declare -- REPLY=$'\303'
declare -- REPLY=$'\304'
declare -- REPLY=$'\305'
declare -- REPLY=$'\306'
declare -- REPLY=$'\307'
declare -- REPLY=$'\310'
declare -- REPLY=$'\311'
declare -- REPLY=$'\312'
declare -- REPLY=$'\313'
declare -- REPLY=$'\314'
declare -- REPLY=$'\315'
declare -- REPLY=$'\316'
declare -- REPLY=$'\317'
declare -- REPLY=$'\320'
declare -- REPLY=$'\321'
declare -- REPLY=$'\322'
declare -- REPLY=$'\323'
declare -- REPLY=$'\324'
declare -- REPLY=$'\325'
declare -- REPLY=$'\326'
declare -- REPLY=$'\327'
declare -- REPLY=$'\330'
declare -- REPLY=$'\331'
declare -- REPLY=$'\332'
declare -- REPLY=$'\333'
declare -- REPLY=$'\334'
declare -- REPLY=$'\335'
declare -- REPLY=$'\336'
declare -- REPLY=$'\337'
declare -- REPLY=$'\340'
declare -- REPLY=$'\341'
declare -- REPLY=$'\342'
declare -- REPLY=$'\343'
declare -- REPLY=$'\344'
declare -- REPLY=$'\345'
declare -- REPLY=$'\346'
declare -- REPLY=$'\347'
declare -- REPLY=$'\350'
declare -- REPLY=$'\351'
declare -- REPLY=$'\352'
declare -- REPLY=$'\353'
declare -- REPLY=$'\354'
declare -- REPLY=$'\355'
declare -- REPLY=$'\356'
declare -- REPLY=$'\357'
declare -- REPLY=$'\360'
declare -- REPLY=$'\361'
declare -- REPLY=$'\362'
declare -- REPLY=$'\363'
declare -- REPLY=$'\364'
declare -- REPLY=$'\365'
Signed-off-by: Kerin Millar <kfm@plushkava.net>
---
builtins/read.def | 25 ++++++++++++----
externs.h | 1 +
lib/sh/zread.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 94 insertions(+), 6 deletions(-)
diff --git builtins/read.def builtins/read.def
index ddd91d32..53b4bd81 100644
--- builtins/read.def
+++ builtins/read.def
@@ -130,7 +130,7 @@ static void set_readline_timeout PARAMS((sh_timer *t, time_t, long));
#endif
static SHELL_VAR *bind_read_variable PARAMS((char *, char *, int));
#if defined (HANDLE_MULTIBYTE)
-static int read_mbchar PARAMS((int, char *, int, int, int));
+static int read_mbchar PARAMS((int, char *, int, int, int, int));
#endif
static void ttyrestore PARAMS((struct ttsave *));
@@ -806,7 +806,7 @@ add_char:
else
# endif
if (locale_utf8locale == 0 || ((c & 0x80) != 0))
- i += read_mbchar (fd, input_string, i, c, unbuffered_read);
+ i += read_mbchar (fd, input_string, i, c, delim, unbuffered_read);
}
#endif
@@ -1064,10 +1064,10 @@ bind_read_variable (name, value, flags)
#if defined (HANDLE_MULTIBYTE)
static int
-read_mbchar (fd, string, ind, ch, unbuffered)
+read_mbchar (fd, string, ind, ch, delim, unbuffered)
int fd;
char *string;
- int ind, ch, unbuffered;
+ int ind, ch, delim, unbuffered;
{
char mbchar[MB_LEN_MAX + 1];
int i, n, r;
@@ -1101,8 +1101,21 @@ read_mbchar (fd, string, ind, ch, unbuffered)
mbchar[i++] = c;
continue;
}
- else if (ret == (size_t)-1 || ret == (size_t)0 || ret > (size_t)0)
- break;
+ else if (ret == (size_t)-1)
+ {
+ /* If we read a delimiter character that makes this an invalid
+ multibyte character, we can't just add it to the input string
+ and treat it as a byte. We need to push it back so a subsequent
+ zread will pick it up. */
+ if (c == delim)
+ {
+ zungetc (c);
+ mbchar[--i] = '\0'; /* unget the delimiter */
+ }
+ break; /* invalid multibyte character */
+ }
+ else if (ret == (size_t)0 || ret > (size_t)0)
+ break; /* valid multibyte character */
}
mbchar_return:
diff --git externs.h externs.h
index 931dba9c..1b70a13b 100644
--- externs.h
+++ externs.h
@@ -536,6 +536,7 @@ extern ssize_t zreadintr PARAMS((int, char *, size_t));
extern ssize_t zreadc PARAMS((int, char *));
extern ssize_t zreadcintr PARAMS((int, char *));
extern ssize_t zreadn PARAMS((int, char *, size_t));
+extern int zungetc PARAMS((int));
extern void zreset PARAMS((void));
extern void zsyncfd PARAMS((int));
diff --git lib/sh/zread.c lib/sh/zread.c
index dafb7f60..7cfbb288 100644
--- lib/sh/zread.c
+++ lib/sh/zread.c
@@ -41,6 +41,10 @@ extern int errno;
# define ZBUFSIZ 4096
#endif
+#ifndef EOF
+# define EOF -1
+#endif
+
extern int executing_builtin;
extern void check_signals_and_traps (void);
@@ -48,6 +52,11 @@ extern void check_signals (void);
extern int signal_is_trapped (int);
extern int read_builtin_timeout (int);
+int zungetc (int);
+
+/* Provide one character of pushback whether we are using read or zread. */
+static int zpushedchar = -1;
+
/* Read LEN bytes from FD into BUF. Retry the read on EINTR. Any other
error causes the loop to break. */
ssize_t
@@ -59,6 +68,15 @@ zread (fd, buf, len)
ssize_t r;
check_signals (); /* check for signals before a blocking read */
+
+ /* If we pushed a char back, return it immediately */
+ if (zpushedchar != -1)
+ {
+ *buf = (unsigned char)zpushedchar;
+ zpushedchar = -1;
+ return 1;
+ }
+
/* should generalize into a mechanism where different parts of the shell can
`register' timeouts and have them checked here. */
while (((r = read_builtin_timeout (fd)) < 0 || (r = read (fd, buf, len)) < 0) &&
@@ -95,6 +113,14 @@ zreadretry (fd, buf, len)
ssize_t r;
int nintr;
+ /* If we pushed a char back, return it immediately */
+ if (zpushedchar != -1)
+ {
+ *buf = (unsigned char)zpushedchar;
+ zpushedchar = -1;
+ return 1;
+ }
+
for (nintr = 0; ; )
{
r = read (fd, buf, len);
@@ -118,6 +144,15 @@ zreadintr (fd, buf, len)
size_t len;
{
check_signals ();
+
+ /* If we pushed a char back, return it immediately */
+ if (zpushedchar != -1)
+ {
+ *buf = (unsigned char)zpushedchar;
+ zpushedchar = -1;
+ return 1;
+ }
+
return (read (fd, buf, len));
}
@@ -135,6 +170,14 @@ zreadc (fd, cp)
{
ssize_t nr;
+ /* If we pushed a char back, return it immediately */
+ if (zpushedchar != -1 && cp)
+ {
+ *cp = (unsigned char)zpushedchar;
+ zpushedchar = -1;
+ return 1;
+ }
+
if (lind == lused || lused == 0)
{
nr = zread (fd, lbuf, sizeof (lbuf));
@@ -160,6 +203,14 @@ zreadcintr (fd, cp)
{
ssize_t nr;
+ /* If we pushed a char back, return it immediately */
+ if (zpushedchar != -1 && cp)
+ {
+ *cp = (unsigned char)zpushedchar;
+ zpushedchar = -1;
+ return 1;
+ }
+
if (lind == lused || lused == 0)
{
nr = zreadintr (fd, lbuf, sizeof (lbuf));
@@ -186,6 +237,13 @@ zreadn (fd, cp, len)
{
ssize_t nr;
+ if (zpushedchar != -1 && cp)
+ {
+ *cp = zpushedchar;
+ zpushedchar = -1;
+ return 1;
+ }
+
if (lind == lused || lused == 0)
{
if (len > sizeof (lbuf))
@@ -204,6 +262,22 @@ zreadn (fd, cp, len)
return 1;
}
+int
+zungetc (c)
+ int c;
+{
+ if (zpushedchar == -1)
+ {
+ zpushedchar = c;
+ return c;
+ }
+
+ if (c == EOF || lind == 0)
+ return (EOF);
+ lbuf[--lind] = c; /* XXX */
+ return c;
+}
+
void
zreset ()
{
--
2.45.2

View file

@ -1,2 +1,2 @@
rm -rf {src,pkg,bash*tar.gz*,bash-5.2_*.patch,bash} rm -rf {src,pkg,bash*tar.gz*,bash52-0*,bash,bash*.tar.xz,easybash*.tar.xz,bash}

View file

@ -1 +1,2 @@

View file

@ -1,6 +1,6 @@
real 2m57.384s real 3m25.982s
user 1m5.368s user 1m37.174s
sys 0m10.453s sys 0m12.064s