]> git.ipfire.org Git - thirdparty/bash.git/commitdiff
fix minor asan bug; $(<nosuchfile) is no longer a fatal error with errexit enabled...
authorChet Ramey <chet.ramey@case.edu>
Wed, 5 Apr 2023 20:07:04 +0000 (16:07 -0400)
committerChet Ramey <chet.ramey@case.edu>
Wed, 5 Apr 2023 20:07:04 +0000 (16:07 -0400)
CWRU/CWRU.chlog
CWRU/misc/open-files.c
builtins/evalstring.c
lib/readline/vi_mode.c
lib/sh/oslib.c
subst.c

index 20cd75cb8381640c5bff5dab283a445353444d17..4c1b8201917af88997725dfa40e54047d9e4d224 100644 (file)
@@ -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)
index 6a5557769f3621d3bca25a7d2dbab417a320e6c7..67440de4d408cb33cba43a4ab665fe4d5e27ef38 100644 (file)
@@ -27,6 +27,7 @@
 
 #include <stdio.h>
 
+int
 main()
 {
        register int    i;
index 554ebc48c1f85d8a4dfe626055593159cca91942..b78b53e95b37f1890969c08af8d7d627bec9e882 100644 (file)
@@ -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;
index e85fd101bd197c142b965712ae90e4afebabd2f1..7396e316aeff3c0f8a059d87c6ddc5a20cee1e8d 100644 (file)
@@ -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);
     }
index ab7924dfde607b664918e36aea845475672cce4a..85f7b4914787fc90620edd1dca5f56b127cf6494 100644 (file)
@@ -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 3c16749cb369535ac0ca6769206cc823679b055e..555d18db8eafaba83d8aa4243128f4fc9034343d 100644 (file)
--- 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)