libedit: Does not run input command in vi mode

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

libedit: Does not run input command in vi mode

Masato Asou
Does not run input command by vi editor with vi mode.

I do the following:

1. set vi mode.
   $ echo "bind -v" > ~/.editrc

2. launch /usr/bin/ftp command.
   $ ftp

3. launch vi editor with ESC + v.
   ftp> ESC + v

4. input "help" in vi editor.
   i + help + ESC + :wq

5. then 'help' command does not run.

I fix this problem with following patch. This fix is come from NetBSD
lib/libedit/vi.c 1.46 and 1.47.

ok?

Index: vi.c
===================================================================
RCS file: /cvs/src/lib/libedit/vi.c,v
retrieving revision 1.27
diff -u -p -r1.27 vi.c
--- vi.c 3 Sep 2019 02:28:25 -0000 1.27
+++ vi.c 3 Sep 2019 05:34:31 -0000
@@ -1058,12 +1058,12 @@ vi_histedit(EditLine *el, wint_t c __att
  while (waitpid(pid, &status, 0) != pid)
  continue;
  lseek(fd, (off_t)0, SEEK_SET);
- st = read(fd, cp, TMP_BUFSIZ);
+ st = read(fd, cp, TMP_BUFSIZ - 1);
  if (st > 0) {
- len = (size_t)(el->el_line.lastchar -
-    el->el_line.buffer);
+ cp[st] = '\0';
+ len = (size_t)(el->el_line.limit - el->el_line.buffer);
  len = mbstowcs(el->el_line.buffer, cp, len);
- if (len > 0 && el->el_line.buffer[len -1] == '\n')
+ if (len > 0 && el->el_line.buffer[len - 1] == '\n')
  --len;
  }
  else

--
ASOU Masato

Reply | Threaded
Open this post in threaded view
|

Re: libedit: Does not run input command in vi mode

Ingo Schwarze
Hello Masato-san,

Masato Asou wrote on Tue, Sep 03, 2019 at 02:39:11PM +0900:

> Does not run input command by vi editor with vi mode.
>
> I do the following:
>
> 1. set vi mode.
>    $ echo "bind -v" > ~/.editrc
>
> 2. launch /usr/bin/ftp command.
>    $ ftp
>
> 3. launch vi editor with ESC + v.
>    ftp> ESC + v
>
> 4. input "help" in vi editor.
>    i + help + ESC + :wq
>
> 5. then 'help' command does not run.
>
> I fix this problem with following patch. This fix is come from NetBSD
> lib/libedit/vi.c 1.46 and 1.47.
>
> ok?

Indeed, limiting the length of the command created with vi(1) to
the length of the string the command line contained when vi(1) was
started is wrong.

Both code inspection and testing confirm that this is a bug
and that your patch is the correct fix.

IK schwarze@; please commit.

Thank you,
  Ingo


> Index: vi.c
> ===================================================================
> RCS file: /cvs/src/lib/libedit/vi.c,v
> retrieving revision 1.27
> diff -u -p -r1.27 vi.c
> --- vi.c 3 Sep 2019 02:28:25 -0000 1.27
> +++ vi.c 3 Sep 2019 05:34:31 -0000
> @@ -1058,12 +1058,12 @@ vi_histedit(EditLine *el, wint_t c __att
>   while (waitpid(pid, &status, 0) != pid)
>   continue;
>   lseek(fd, (off_t)0, SEEK_SET);
> - st = read(fd, cp, TMP_BUFSIZ);
> + st = read(fd, cp, TMP_BUFSIZ - 1);
>   if (st > 0) {
> - len = (size_t)(el->el_line.lastchar -
> -    el->el_line.buffer);
> + cp[st] = '\0';
> + len = (size_t)(el->el_line.limit - el->el_line.buffer);
>   len = mbstowcs(el->el_line.buffer, cp, len);
> - if (len > 0 && el->el_line.buffer[len -1] == '\n')
> + if (len > 0 && el->el_line.buffer[len - 1] == '\n')
>   --len;
>   }
>   else