Module Name: src Committed By: roy Date: Tue May 16 10:25:40 UTC 2017
Modified Files: src/lib/libterminfo: term.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.24 -r1.25 src/lib/libterminfo/term.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/libterminfo/term.c diff -u src/lib/libterminfo/term.c:1.24 src/lib/libterminfo/term.c:1.25 --- src/lib/libterminfo/term.c:1.24 Tue May 16 09:19:48 2017 +++ src/lib/libterminfo/term.c Tue May 16 10:25:40 2017 @@ -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 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