Check tkp->output != NULL before taking strlen for both command mappings
authortb <tb@openbsd.org>
Fri, 22 Apr 2022 15:50:07 +0000 (15:50 +0000)
committertb <tb@openbsd.org>
Fri, 22 Apr 2022 15:50:07 +0000 (15:50 +0000)
and input mappings. This adds a missing check for command mappings and
simplifies the input mappings.

ok millert

usr.bin/vi/cl/cl_term.c

index c8b13f7..a4c3968 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: cl_term.c,v 1.28 2017/07/20 08:37:48 anton Exp $      */
+/*     $OpenBSD: cl_term.c,v 1.29 2022/04/22 15:50:07 tb Exp $ */
 
 /*-
  * Copyright (c) 1993, 1994
@@ -78,14 +78,18 @@ cl_term_init(SCR *sp)
 {
        SEQ *qp;
        TKLIST const *tkp;
+       size_t output_len;
        char *t;
 
        /* Command mappings. */
        for (tkp = c_tklist; tkp->name != NULL; ++tkp) {
                if ((t = tigetstr(tkp->ts)) == NULL || t == (char *)-1)
                        continue;
+               output_len = 0;
+               if (tkp->output != NULL)
+                       output_len = strlen(tkp->output);
                if (seq_set(sp, tkp->name, strlen(tkp->name), t, strlen(t),
-                   tkp->output, strlen(tkp->output), SEQ_COMMAND,
+                   tkp->output, output_len, SEQ_COMMAND,
                    SEQ_NOOVERWRITE | SEQ_SCREEN))
                        return (1);
        }
@@ -103,16 +107,13 @@ cl_term_init(SCR *sp)
                 */
                if (!strcmp(t, "\b"))
                        continue;
-               if (tkp->output == NULL) {
-                       if (seq_set(sp, tkp->name, strlen(tkp->name),
-                           t, strlen(t), NULL, 0,
-                           SEQ_INPUT, SEQ_NOOVERWRITE | SEQ_SCREEN))
-                               return (1);
-               } else
-                       if (seq_set(sp, tkp->name, strlen(tkp->name),
-                           t, strlen(t), tkp->output, strlen(tkp->output),
-                           SEQ_INPUT, SEQ_NOOVERWRITE | SEQ_SCREEN))
-                               return (1);
+               output_len = 0;
+               if (tkp->output != NULL)
+                       output_len = strlen(tkp->output);
+               if (seq_set(sp, tkp->name, strlen(tkp->name), t, strlen(t),
+                   tkp->output, output_len, SEQ_INPUT,
+                   SEQ_NOOVERWRITE | SEQ_SCREEN))
+                       return (1);
        }
 
        /*