> From: "Theo de Raadt" <dera...@openbsd.org>
> Date: Thu, 10 Jun 2021 16:11:57 -0600
>
> I would argue for deleting that code.

Here's the diff for that.

>
> A flag for el_set which *allows it* might work for me, but I anticipate
> this is a crazy feature that programs using the library would not expect,
> and the risks of abuse are clear.

This could be done by not deleting the code and unbinding the "v" key. 
Programs won't accidentally hit it and they can add the binding back if
they want to enable it.

On the other hand, users could also bind it themselves in ~/.editrc and
trigger pledge(2) violations in programs not designed for it.  It won't
be obvious to them why their shiny feature wouldn't work.

I think it's better to make it foolproof and delete the code outright.
Who needs vi(1) editing when editline(7) already emulates it?

Index: editline.7
===================================================================
RCS file: /cvs/src/lib/libedit/editline.7,v
retrieving revision 1.2
diff -u -p -r1.2 editline.7
--- editline.7  10 May 2016 11:07:53 -0000      1.2
+++ editline.7  10 Jun 2021 22:28:39 -0000
@@ -198,7 +198,6 @@ editor commands by default:
 .It s Ta Ic vi-substitute-char
 .It t Ta Ic vi-to-next-char
 .It u Ta Ic vi-undo
-.It v Ta Ic vi-histedit
 .It w Ta Ic vi-next-word
 .It x Ta Ic ed-delete-next-char
 .It y Ta Ic vi-yank
Index: map.c
===================================================================
RCS file: /cvs/src/lib/libedit/map.c,v
retrieving revision 1.27
diff -u -p -r1.27 map.c
--- map.c       6 May 2016 13:12:52 -0000       1.27
+++ map.c       10 Jun 2021 22:28:40 -0000
@@ -747,7 +747,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.28
diff -u -p -r1.28 vi.c
--- vi.c        4 Sep 2019 00:00:49 -0000       1.28
+++ vi.c        10 Jun 2021 22:28:40 -0000
@@ -994,93 +994,6 @@ vi_to_history_line(EditLine *el, wint_t 
        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 == -1)
-               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 + 1, 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 - 1);
-               if (st > 0) {
-                       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')
-                               --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():
  *     Vi append word from previous input line
  *     [_]

Reply via email to