Source-Changes-HG archive

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

[src/trunk]: src/lib/libterminfo Instead of poking in the binary blob to work...



details:   https://anonhg.NetBSD.org/src/rev/7f6f93851385
branches:  trunk
changeset: 823959:7f6f93851385
user:      roy <roy%NetBSD.org@localhost>
date:      Tue May 16 10:25:40 2017 +0000

description:
Instead of poking in the binary blob to work out if this is our terminal,
assume it is and load it.
Once loaded then check it's really for us.
This allows us to work out if the indexed alias entry is correct we
this was not checked previously.

diffstat:

 lib/libterminfo/term.c |  67 ++++++++++++++++++++++++++++++++-----------------
 1 files changed, 43 insertions(+), 24 deletions(-)

diffs (106 lines):

diff -r 59d6e72685b0 -r 7f6f93851385 lib/libterminfo/term.c
--- a/lib/libterminfo/term.c    Tue May 16 10:11:24 2017 +0000
+++ b/lib/libterminfo/term.c    Tue May 16 10:25:40 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: term.c,v 1.24 2017/05/16 09:19:48 roy Exp $ */
+/* $NetBSD: term.c,v 1.25 2017/05/16 10:25:40 roy Exp $ */
 
 /*
  * Copyright (c) 2009, 2010, 2011 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: term.c,v 1.24 2017/05/16 09:19:48 roy Exp $");
+__RCSID("$NetBSD: term.c,v 1.25 2017/05/16 10:25:40 roy Exp $");
 
 #include <sys/stat.h>
 
@@ -243,6 +243,32 @@
 }
 
 static int
+_ti_checkname(const TERMINAL *term, const char *name)
+{
+       const char *a, *p;
+       size_t name_len;
+
+       /* Check terminal name matches. */
+       if (strcmp(name, term->name) == 0)
+               return 1;
+
+       /* Check terminal aliases match. */
+       name_len = strlen(name);
+       for (a = term->_alias; a != NULL && *a != '\0'; a = p) {
+               for (p = a; *p != '\0'; p++) {
+                       if (*p == '|')
+                               break;
+               }
+               if ((size_t)(p - a) == name_len &&
+                   memcmp(name, a, name_len) == 0)
+                       return 1;
+       }
+
+       /* No match. */
+       return 0;
+}
+
+static int
 _ti_dbgetterm(TERMINAL *term, const char *path, const char *name, int flags)
 {
        struct cdbr *db;
@@ -257,39 +283,32 @@
        if (db == NULL)
                return -1;
 
+       r = 0;
        klen = strlen(name) + 1;
        if (cdbr_find(db, name, klen, &data, &len) == -1)
-               goto fail;
+               goto out;
        data8 = data;
        if (len == 0)
-               goto fail;
-       /* Check for alias first, fall through to processing normal entries. */
+               goto out;
+
+       /* If the entry is an alias, load the indexed terminfo description. */
        if (data8[0] == 2) {
-               if (klen + 7 > len || le16dec(data8 + 5) != klen)
-                       goto fail;
-               if (memcmp(data8 + 7, name, klen))
-                       goto fail;
                if (cdbr_get(db, le32dec(data8 + 1), &data, &len))
-                       goto fail;
+                       goto out;
                data8 = data;
-               if (data8[0] != 1)
-                       goto fail;
-       } else if (data8[0] != 1)
-               goto fail;
-       else if (klen + 3 >= len || le16dec(data8 + 1) != klen)
-               goto fail;
-       else if (memcmp(data8 + 3, name, klen))
-               goto fail;
-
-       _ti_database = __ti_database;
+       }
 
        r = _ti_readterm(term, data, len, flags);
+       /* Ensure that this is the right terminfo description. */
+        if (r == 1)
+                r = _ti_checkname(term, name);
+       /* Remember the database we read. */
+        if (r == 1)
+                _ti_database = __ti_database;
+
+out:
        cdbr_close(db);
        return r;
-
-fail:
-       cdbr_close(db);
-       return 0;
 }
 
 static int



Home | Main Index | Thread Index | Old Index