On Thu, 21 Apr 2022 09:35:44 -0700, Jeremy Mates wrote:

> The cause is an unguarded use of the NULL output pointer. I am pretty
> sure an .exrc cannot cause this condition (map rhs requires
> something, not nothing) only recompiling with a NULL output string
> for some command.
>
> One fix is to guard the "init_nomap = !e_memcmp(qp->output," line in
> common/key.c with something like
>
>   if (qp->output)
>     init_nomap = !e_memcmp(qp->output, &gp->i_event[gp->i_next], qp->ilen);

That seems reasonable to me since the other users of qp->output do
check for NULL.  We don't need to worry about init_nomap being unset
due to the "goto retry" that happens a few lines down.

 - todd

Index: usr.bin/vi/common/key.c
===================================================================
RCS file: /cvs/src/usr.bin/vi/common/key.c,v
retrieving revision 1.19
diff -u -p -u -r1.19 key.c
--- usr.bin/vi/common/key.c     18 Apr 2017 01:45:35 -0000      1.19
+++ usr.bin/vi/common/key.c     21 Apr 2022 17:03:26 -0000
@@ -650,7 +650,10 @@ not_digit: argp->e_c = CH_NOT_DIGIT;
        }
 
        /* Find out if the initial segments are identical. */
-       init_nomap = !e_memcmp(qp->output, &gp->i_event[gp->i_next], qp->ilen);
+       if (qp->output != NULL) {
+               init_nomap =
+                   !e_memcmp(qp->output, &gp->i_event[gp->i_next], qp->ilen);
+       }
 
        /* Delete the mapped characters from the queue. */
        QREM(qp->ilen);

Reply via email to