Hi,

in vi command mode, libedit provides the editor command
vi-histedit (bound to the 'v' key by default) to fork and
exec vi(1) on the line being edited.  That is pretty much
pointless in the first place because the line can just as
well be edited with libedit itself, without any fork and exec.
Built-in libedit editing capabilities is already much more
bloated than we could reasonably wish for.

In a pledge(2)d world, such excessive functionality is harmful.
Nobody pledging a program will expect that it might need "proc exec"
just because it uses libedit, and then kittens^Wusers get killed
when hitting the "v" key at the wrong time.  Yikes.

OK to delete the misfeature?

Yours,
  Ingo


P.S.
For testing, don't forget to

  cd /usr/src/lib/libedit/
  make clean
  make depend
  make
  doas make install

to be sure that all generated files are properly regenerated.


Index: editrc.5
===================================================================
RCS file: /cvs/src/lib/libedit/editrc.5,v
retrieving revision 1.29
diff -u -p -r1.29 editrc.5
--- editrc.5    8 Jan 2016 20:26:54 -0000       1.29
+++ editrc.5    16 Apr 2016 23:20:04 -0000
@@ -388,8 +388,6 @@ Vi comment out current command.
 Vi include shell alias.
 .It Ic vi-to-history-line
 Vi go to specified history file line..
-.It Ic vi-histedit
-Vi edit history line with vi.
 .It Ic vi-history-word
 Vi append word from previous input line.
 .It Ic vi-redo
Index: map.c
===================================================================
RCS file: /cvs/src/lib/libedit/map.c,v
retrieving revision 1.24
diff -u -p -r1.24 map.c
--- map.c       12 Apr 2016 09:04:02 -0000      1.24
+++ map.c       16 Apr 2016 23:20:04 -0000
@@ -742,7 +742,7 @@ static const el_action_t el_map_vi_comma
        /* 115 */       VI_SUBSTITUTE_CHAR,     /* s */
        /* 116 */       VI_TO_NEXT_CHAR,        /* t */
        /* 117 */       VI_UNDO,                /* u */
-       /* 118 */       VI_HISTEDIT,            /* v */
+       /* 118 */       ED_UNASSIGNED,          /* v */
        /* 119 */       VI_NEXT_WORD,           /* w */
        /* 120 */       ED_DELETE_NEXT_CHAR,    /* x */
        /* 121 */       VI_YANK,                /* y */
Index: vi.c
===================================================================
RCS file: /cvs/src/lib/libedit/vi.c,v
retrieving revision 1.24
diff -u -p -r1.24 vi.c
--- vi.c        11 Apr 2016 21:17:29 -0000      1.24
+++ vi.c        16 Apr 2016 23:20:04 -0000
@@ -38,12 +38,10 @@
 /*
  * vi.c: Vi mode commands.
  */
-#include <sys/wait.h>
 #include <ctype.h>
 #include <limits.h>
 #include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
 
 #include "el.h"
 #include "common.h"
@@ -991,93 +989,6 @@ vi_to_history_line(EditLine *el, wint_t 
        if (rval == CC_ERROR)
                el->el_history.eventno = sv_event_no;
        return rval;
-}
-
-/* vi_histedit():
- *     Vi edit history line with vi
- *     [v]
- */
-protected el_action_t
-/*ARGSUSED*/
-vi_histedit(EditLine *el, wint_t c __attribute__((__unused__)))
-{
-       int fd;
-       pid_t pid;
-       ssize_t st;
-       int status;
-       char tempfile[] = "/tmp/histedit.XXXXXXXXXX";
-       char *cp;
-       size_t len;
-       wchar_t *line;
-
-       if (el->el_state.doingarg) {
-               if (vi_to_history_line(el, 0) == CC_ERROR)
-                       return CC_ERROR;
-       }
-
-       fd = mkstemp(tempfile);
-       if (fd < 0)
-               return CC_ERROR;
-       len = (size_t)(el->el_line.lastchar - el->el_line.buffer);
-#define TMP_BUFSIZ (EL_BUFSIZ * MB_LEN_MAX)
-       cp = malloc(TMP_BUFSIZ);
-       if (cp == NULL) {
-               close(fd);
-               unlink(tempfile);
-               return CC_ERROR;
-       }
-       line = reallocarray(NULL, len, sizeof(*line));
-       if (line == NULL) {
-               close(fd);
-               unlink(tempfile);
-               free(cp);
-               return CC_ERROR;
-       }
-       wcsncpy(line, el->el_line.buffer, len);
-       line[len] = '\0';
-       wcstombs(cp, line, TMP_BUFSIZ - 1);
-       cp[TMP_BUFSIZ - 1] = '\0';
-       len = strlen(cp);
-       write(fd, cp, len);
-       write(fd, "\n", 1);
-       pid = fork();
-       switch (pid) {
-       case -1:
-               close(fd);
-               unlink(tempfile);
-               free(cp);
-                free(line);
-               return CC_ERROR;
-       case 0:
-               close(fd);
-               execlp("vi", "vi", tempfile, (char *)NULL);
-               exit(0);
-               /*NOTREACHED*/
-       default:
-               while (waitpid(pid, &status, 0) != pid)
-                       continue;
-               lseek(fd, (off_t)0, SEEK_SET);
-               st = read(fd, cp, TMP_BUFSIZ);
-               if (st > 0) {
-                       len = (size_t)(el->el_line.lastchar -
-                           el->el_line.buffer);
-                       len = mbstowcs(el->el_line.buffer, cp, len);
-                       if (len > 0 && el->el_line.buffer[len -1] == '\n')
-                               --len;
-               }
-               else
-                       len = 0;
-                el->el_line.cursor = el->el_line.buffer;
-                el->el_line.lastchar = el->el_line.buffer + len;
-               free(cp);
-                free(line);
-               break;
-       }
-
-       close(fd);
-       unlink(tempfile);
-       /* return CC_REFRESH; */
-       return ed_newline(el, 0);
 }
 
 /* vi_history_word():

Reply via email to