summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChet Ramey <chet.ramey@case.edu>2023-04-05 16:07:04 -0400
committerChet Ramey <chet.ramey@case.edu>2023-04-05 16:07:04 -0400
commitec9447ce9392a0f93d96789c3741285fede8a150 (patch)
treed049cee3fc1905b07f1a3425980105d4126e321f
parent877ff7267584b40c082ddcc49ce6c539f05f16f4 (diff)
downloadbash-ec9447ce9392a0f93d96789c3741285fede8a150.tar.gz
fix minor asan bug; $(<nosuchfile) is no longer a fatal error with errexit enabled; fixes for vi t/T motion commandsdevel
-rw-r--r--CWRU/CWRU.chlog25
-rw-r--r--CWRU/misc/open-files.c1
-rw-r--r--builtins/evalstring.c2
-rw-r--r--lib/readline/vi_mode.c27
-rw-r--r--lib/sh/oslib.c2
-rw-r--r--subst.c4
6 files changed, 56 insertions, 5 deletions
diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog
index 20cd75c..4c1b820 100644
--- a/CWRU/CWRU.chlog
+++ b/CWRU/CWRU.chlog
@@ -5944,3 +5944,28 @@ builtins/times.h
- add prototypes for functions taking clock_t and timeval, make their
declaration in externs.h conditional on NEED_CLOCK_FUNCS_DECL and
NEED_TIMEVAL_FUNCS_DECL, respectively
+
+ 3/31
+ ----
+subst.c
+ - expand_string_dollar_quote: check for zero-length return from
+ string_extract_{single,double}_quoted and avoid size_t underflow
+ Fixes asan error reported by Grisha Levit <grishalevit@gmail.com>
+
+ 4/3
+ ---
+builtins/evalstring.c
+ - open_redir_file: treat the case of failing to open the file as a
+ non-fatal expansion error instead of a (fatal) redirection error.
+ Report from Zev Weiss <zev@bewilderbeest.net>
+
+ 4/4
+ ---
+lib/readline/vi_mode.c
+ - _rl_domove_motion_cleanup: d/D require the same special case as c/C
+ so that a motion command that doesn't move the cursor consumes/deletes
+ at least one character.
+ From Emanuele Torre <torreemanuele6@gmail.com>
+ - _rl_domove_motion_cleanup: ditto for y/Y
+ - rl_domove_motion_callback: if t/T/;/, fail (return non-zero without
+ moving point), flag the motion command as having failed (MOVE_FAILED)
diff --git a/CWRU/misc/open-files.c b/CWRU/misc/open-files.c
index 6a55577..67440de 100644
--- a/CWRU/misc/open-files.c
+++ b/CWRU/misc/open-files.c
@@ -27,6 +27,7 @@
#include <stdio.h>
+int
main()
{
register int i;
diff --git a/builtins/evalstring.c b/builtins/evalstring.c
index 554ebc4..b78b53e 100644
--- a/builtins/evalstring.c
+++ b/builtins/evalstring.c
@@ -756,7 +756,7 @@ open_redir_file (REDIRECT *r, char **fnp)
fd = open(fn, O_RDONLY);
if (fd < 0)
{
- file_error (fn);
+ internal_error ("%s: %s", fn, strerror (errno));
free (fn);
if (fnp)
*fnp = 0;
diff --git a/lib/readline/vi_mode.c b/lib/readline/vi_mode.c
index e85fd10..7396e31 100644
--- a/lib/readline/vi_mode.c
+++ b/lib/readline/vi_mode.c
@@ -1153,6 +1153,23 @@ _rl_mvcxt_dispose (_rl_vimotion_cxt *m)
xfree (m);
}
+static inline int
+vi_charsearch_command (int c)
+{
+ switch (c)
+ {
+ case 'f':
+ case 'F':
+ case 't':
+ case 'T':
+ case ';':
+ case ',':
+ return 1;
+ default:
+ return 0;
+ }
+}
+
static int
rl_domove_motion_callback (_rl_vimotion_cxt *m)
{
@@ -1173,7 +1190,7 @@ rl_domove_motion_callback (_rl_vimotion_cxt *m)
/* Note in the context that the motion command failed. Right now we only do
this for unsuccessful searches (ones where _rl_dispatch returns non-zero
and point doesn't move). */
- if (r != 0 && rl_point == opoint && (c == 'f' || c == 'F'))
+ if (r != 0 && rl_point == opoint && vi_charsearch_command (c))
m->flags |= MOVE_FAILED;
#if defined (READLINE_CALLBACKS)
@@ -1211,6 +1228,14 @@ _rl_vi_domove_motion_cleanup (int c, _rl_vimotion_cxt *m)
didn't delete anything, as long as the motion command is valid. */
if (_rl_to_upper (m->key) == 'C' && _rl_vi_motion_command (c) && (m->flags & MOVE_FAILED) == 0)
return (vidomove_dispatch (m));
+ /* 'd' and 'D' must delete at least one character even if the motion
+ command doesn't move the cursor. */
+ if (_rl_to_upper (m->key) == 'D' && _rl_vi_motion_command (c) && (m->flags & MOVE_FAILED) == 0)
+ return (vidomove_dispatch (m));
+ /* 'y' and 'Y' must yank at least one character even if the motion
+ command doean't move the cursor. */
+ if (_rl_to_upper (m->key) == 'Y' && _rl_vi_motion_command (c) && (m->flags & MOVE_FAILED) == 0)
+ return (vidomove_dispatch (m));
RL_UNSETSTATE (RL_STATE_VIMOTION);
return (-1);
}
diff --git a/lib/sh/oslib.c b/lib/sh/oslib.c
index ab7924d..85f7b49 100644
--- a/lib/sh/oslib.c
+++ b/lib/sh/oslib.c
@@ -161,7 +161,7 @@ getdtablesize (void)
# undef bcopy
# endif
void
-bcopy (void *s, *d, size_t n)
+bcopy (void *s, void *d, size_t n)
{
FASTCOPY (s, d, n);
}
diff --git a/subst.c b/subst.c
index 3c16749..555d18d 100644
--- a/subst.c
+++ b/subst.c
@@ -4063,7 +4063,7 @@ char *
expand_string_dollar_quote (const char *string, int flags)
{
size_t slen, retind, retsize;
- int sindex, c, peekc, news;
+ int sindex, c, peekc, news, tlen;
char *ret, *trans, *t;
size_t translen;
const char *send;
@@ -4100,7 +4100,7 @@ expand_string_dollar_quote (const char *string, int flags)
news = skip_single_quoted (string, slen, ++sindex, SX_COMPLETE);
else
news = skip_double_quoted (string, slen, ++sindex, SX_COMPLETE);
- translen = news - sindex - 1;
+ translen = (news > sindex) ? news - sindex - 1 : 0;
RESIZE_MALLOCED_BUFFER (ret, retind, translen + 3, retsize, 64);
ret[retind++] = c;
if (translen > 0)