diff options
| author | roy <roy@NetBSD.org> | 2017-05-16 10:25:40 +0000 |
|---|---|---|
| committer | roy <roy@NetBSD.org> | 2017-05-16 10:25:40 +0000 |
| commit | 25bfef9214e46d7520c77d63831d93fda289903c (patch) | |
| tree | 9bf4ee8ffdbdc683e1044f60da9b7ee9970efe52 /lib/libterminfo | |
| parent | 00150270f5a33543110f8d1846c271fcd3b1d50a (diff) | |
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 (limited to 'lib/libterminfo')
| -rw-r--r-- | lib/libterminfo/term.c | 67 |
1 files changed, 43 insertions, 24 deletions
diff --git a/lib/libterminfo/term.c b/lib/libterminfo/term.c index 410e4e41788..f2eb570d6c8 100644 --- a/lib/libterminfo/term.c +++ b/lib/libterminfo/term.c @@ -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 @@ out: } 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 @@ _ti_dbgetterm(TERMINAL *term, const char *path, const char *name, int flags) 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); - cdbr_close(db); - return r; + /* 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; -fail: +out: cdbr_close(db); - return 0; + return r; } static int |
