Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/infocmp infocmp: don't crash when a terminfo descrip...



details:   https://anonhg.NetBSD.org/src/rev/7721402e2453
branches:  trunk
changeset: 1008690:7721402e2453
user:      roy <roy%NetBSD.org@localhost>
date:      Tue Mar 31 12:44:15 2020 +0000

description:
infocmp: don't crash when a terminfo description does not have an alias

diffstat:

 usr.bin/infocmp/infocmp.c |  42 ++++++++++++++++++++++--------------------
 1 files changed, 22 insertions(+), 20 deletions(-)

diffs (72 lines):

diff -r d5f03ed889c7 -r 7721402e2453 usr.bin/infocmp/infocmp.c
--- a/usr.bin/infocmp/infocmp.c Tue Mar 31 12:23:17 2020 +0000
+++ b/usr.bin/infocmp/infocmp.c Tue Mar 31 12:44:15 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: infocmp.c,v 1.16 2020/03/30 00:22:18 roy Exp $ */
+/* $NetBSD: infocmp.c,v 1.17 2020/03/31 12:44:15 roy Exp $ */
 
 /*
  * Copyright (c) 2009, 2010, 2020 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: infocmp.c,v 1.16 2020/03/30 00:22:18 roy Exp $");
+__RCSID("$NetBSD: infocmp.c,v 1.17 2020/03/31 12:44:15 roy Exp $");
 
 #include <sys/ioctl.h>
 
@@ -715,8 +715,6 @@
                use_terms(t, argc - optind, argv + optind);
 
        if ((optind + 1 != argc && nflag == 0) || uflag != 0) {
-               char *alias, *aliascpy, *delim;
-
                if (uflag == 0)
                        printf("# Reconstructed from %s\n",
                             _ti_database == NULL ?
@@ -726,24 +724,28 @@
                if (term != NULL)
                        *term = '\0';
                printf("%s", t->name);
-               alias = aliascpy = estrdup(t->_alias);
-               while (alias != NULL && *alias != '\0') {
-                       putchar('|');
-                       delim = strchr(alias, TERMINFO_VDELIM);
-                       if (delim != NULL)
-                               *delim++ = '\0';
-                       printf("%s", alias);
-                       if (delim != NULL) {
-                               while (*delim != '\0' && *delim != '|')
-                                       delim++;
-                               if (*delim == '\0')
+               if (t->_alias != NULL) {
+                       char *alias, *aliascpy, *delim;
+
+                       alias = aliascpy = estrdup(t->_alias);
+                       while (alias != NULL && *alias != '\0') {
+                               putchar('|');
+                               delim = strchr(alias, TERMINFO_VDELIM);
+                               if (delim != NULL)
+                                       *delim++ = '\0';
+                               printf("%s", alias);
+                               if (delim != NULL) {
+                                       while (*delim != '\0' && *delim != '|')
+                                               delim++;
+                                       if (*delim == '\0')
+                                               alias = NULL;
+                                       else
+                                               alias = delim + 1;
+                               } else
                                        alias = NULL;
-                               else
-                                       alias = delim + 1;
-                       } else
-                               alias = NULL;
+                       }
+                       free(aliascpy);
                }
-               free(aliascpy);
                if (t->desc != NULL && *t->desc != '\0')
                        printf("|%s", t->desc);
                printf(",\n");



Home | Main Index | Thread Index | Old Index