terminfo: promote numeric parameters from short to int

POSIX mandates implementations must support upto a short but may exceed it.
When NetBSD terminfo was implemented, no terminfo description used over
a short, but because ncurses has supported ints for some time, some now do.

Infact, such a terminfo description was imported where colour pairs for
screen-256color went up to 65536 which exposed a bug in the existing
implementation where it set to zero. Because the number might mean
something more than a range, we need to be able to store it accurately.

This requires a version bump because whilst the API hasn't changed thanks
to C int promotion, the ABI has. Also the underlying database structure
has changed as well - we now store the numeric paramter inside a uint32_t
field rather than a uint16_t one.
Whilst this change can still read the old style database, the old one
cannot read the new one and thus we now maintain the database as
terminfo2.cdb, leaving the old library and database alone so old programs
still work fine.

libcurses, libfrom, libmenu and libpanel have also been bumped to
accomoate this change.
This commit is contained in:
roy 2020-03-13 15:19:24 +00:00
parent ca70afd1bf
commit aadfdb111b
14 changed files with 150 additions and 106 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: mi,v 1.1231 2020/03/04 22:09:00 christos Exp $
# $NetBSD: mi,v 1.1232 2020/03/13 15:19:25 roy Exp $
#
# Note: Don't delete entries from here - mark them as "obsolete" instead,
# unless otherwise stated below.
@ -4833,7 +4833,7 @@
./usr/share/misc/more.help base-obsolete obsolete
./usr/share/misc/nslookup.help base-obsolete obsolete
./usr/share/misc/terminfo base-terminfo-share share
./usr/share/misc/terminfo.cdb base-terminfo-share share
./usr/share/misc/terminfo2.cdb base-terminfo-share share
./usr/share/misc/units.lib base-reference-share share
./usr/share/misc/usb_hid_usages base-reference-share share
./usr/share/misc/vgrindefs.db base-groff-share share

View File

@ -1,4 +1,4 @@
# $NetBSD: shl.mi,v 1.879 2020/03/08 22:42:35 mgorny Exp $
# $NetBSD: shl.mi,v 1.880 2020/03/13 15:19:25 roy Exp $
#
# Note: Don't delete entries from here - mark them as "obsolete" instead,
# unless otherwise stated below.
@ -91,8 +91,8 @@
./lib/libtermcap.so.0 base-sys-shlib dynamicroot
./lib/libtermcap.so.0.6 base-sys-shlib dynamicroot
./lib/libterminfo.so base-sys-shlib dynamicroot
./lib/libterminfo.so.1 base-sys-shlib dynamicroot
./lib/libterminfo.so.1.0 base-sys-shlib dynamicroot
./lib/libterminfo.so.2 base-sys-shlib dynamicroot
./lib/libterminfo.so.2.0 base-sys-shlib dynamicroot
./lib/libtermlib.so base-sys-shlib dynamicroot
./lib/libtermlib.so.0 base-sys-shlib dynamicroot
./lib/libtermlib.so.0.6 base-sys-shlib dynamicroot
@ -274,8 +274,8 @@
./usr/lib/libctf.so.3 base-sys-shlib compatfile,ctf
./usr/lib/libctf.so.3.0 base-sys-shlib compatfile,ctf
./usr/lib/libcurses.so base-sys-shlib compatfile
./usr/lib/libcurses.so.8 base-sys-shlib compatfile
./usr/lib/libcurses.so.8.2 base-sys-shlib compatfile
./usr/lib/libcurses.so.9 base-sys-shlib compatfile
./usr/lib/libcurses.so.9.0 base-sys-shlib compatfile
./usr/lib/libdes.so base-crypto-shlib compatfile
./usr/lib/libdes.so.12 base-crypto-shlib compatfile,openssl=10
./usr/lib/libdes.so.12.0 base-crypto-shlib compatfile,openssl=10
@ -327,8 +327,8 @@
./usr/lib/libfido2.so.2 base-sys-shlib compatfile
./usr/lib/libfido2.so.2.0 base-sys-shlib compatfile
./usr/lib/libform.so base-sys-shlib compatfile
./usr/lib/libform.so.7 base-sys-shlib compatfile
./usr/lib/libform.so.7.0 base-sys-shlib compatfile
./usr/lib/libform.so.8 base-sys-shlib compatfile
./usr/lib/libform.so.8.0 base-sys-shlib compatfile
./usr/lib/libgcc_s.so base-sys-shlib compatfile,gcc
./usr/lib/libgcc_s.so.1 base-sys-shlib compatfile,gcc
./usr/lib/libgcc_s.so.1.0 base-sys-shlib compatfile,gcc
@ -450,8 +450,8 @@
./usr/lib/libmagic.so.6 base-sys-shlib compatfile
./usr/lib/libmagic.so.6.0 base-sys-shlib compatfile
./usr/lib/libmenu.so base-sys-shlib compatfile
./usr/lib/libmenu.so.7 base-sys-shlib compatfile
./usr/lib/libmenu.so.7.0 base-sys-shlib compatfile
./usr/lib/libmenu.so.8 base-sys-shlib compatfile
./usr/lib/libmenu.so.8.0 base-sys-shlib compatfile
./usr/lib/libmj.so base-crypto-shlib compatfile
./usr/lib/libmj.so.1 base-crypto-shlib compatfile
./usr/lib/libmj.so.1.0 base-crypto-shlib compatfile
@ -486,8 +486,8 @@
./usr/lib/libpam.so.4 base-sys-shlib compatfile,pam
./usr/lib/libpam.so.4.1 base-sys-shlib compatfile,pam
./usr/lib/libpanel.so base-sys-shlib compatfile
./usr/lib/libpanel.so.2 base-sys-shlib compatfile
./usr/lib/libpanel.so.2.0 base-sys-shlib compatfile
./usr/lib/libpanel.so.3 base-sys-shlib compatfile
./usr/lib/libpanel.so.3.0 base-sys-shlib compatfile
./usr/lib/libpcap.so base-net-shlib compatfile
./usr/lib/libpcap.so.8 base-net-shlib compatfile
./usr/lib/libpcap.so.8.0 base-net-shlib compatfile
@ -874,8 +874,8 @@
./usr/lib/libtermcap.so.0 base-sys-shlib compatfile
./usr/lib/libtermcap.so.0.6 base-sys-shlib compatfile
./usr/lib/libterminfo.so base-sys-shlib compatfile
./usr/lib/libterminfo.so.1 base-sys-shlib compatfile
./usr/lib/libterminfo.so.1.0 base-sys-shlib compatfile
./usr/lib/libterminfo.so.2 base-sys-shlib compatfile
./usr/lib/libterminfo.so.2.0 base-sys-shlib compatfile
./usr/lib/libtermlib.so base-sys-shlib compatfile
./usr/lib/libtermlib.so.0 base-sys-shlib compatfile
./usr/lib/libtermlib.so.0.6 base-sys-shlib compatfile

View File

@ -1,8 +1,8 @@
# $NetBSD: shlib_version,v 1.44 2019/06/30 22:16:20 blymn Exp $
# $NetBSD: shlib_version,v 1.45 2020/03/13 15:19:24 roy Exp $
# Remember to update distrib/sets/lists/base/shl.* when changing
# Remember to run `make fileio.h` when changing
# Remember to increment the major numbers of libform, libmenu and
# libpanel when the libcurses major number increments.
#
major=8
minor=2
major=9
minor=0

View File

@ -1,5 +1,5 @@
# $NetBSD: shlib_version,v 1.18 2019/06/30 22:17:22 blymn Exp $
# $NetBSD: shlib_version,v 1.19 2020/03/13 15:19:24 roy Exp $
# Remember to update distrib/sets/lists/base/shl.* when changing
#
major=7
major=8
minor=0

View File

@ -1,5 +1,5 @@
# $NetBSD: shlib_version,v 1.12 2019/06/30 22:17:46 blymn Exp $
# $NetBSD: shlib_version,v 1.13 2020/03/13 15:19:24 roy Exp $
# Remember to update distrib/sets/lists/base/shl.* when changing
#
major=7
major=8
minor=0

View File

@ -1,5 +1,5 @@
# $NetBSD: shlib_version,v 1.2 2019/06/30 22:18:08 blymn Exp $
# $NetBSD: shlib_version,v 1.3 2020/03/13 15:19:24 roy Exp $
# Remember to update distrib/sets/lists/base/shl.* when changing
#
major=2
major=3
minor=0

View File

@ -1,7 +1,7 @@
/* $NetBSD: compile.c,v 1.13 2020/03/12 14:52:04 roy Exp $ */
/* $NetBSD: compile.c,v 1.14 2020/03/13 15:19:25 roy Exp $ */
/*
* Copyright (c) 2009, 2010, 2011 The NetBSD Foundation, Inc.
* Copyright (c) 2009, 2010, 2011, 2020 The NetBSD Foundation, Inc.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Roy Marples.
@ -32,7 +32,7 @@
#endif
#include <sys/cdefs.h>
__RCSID("$NetBSD: compile.c,v 1.13 2020/03/12 14:52:04 roy Exp $");
__RCSID("$NetBSD: compile.c,v 1.14 2020/03/13 15:19:25 roy Exp $");
#if !HAVE_NBTOOL_CONFIG_H || HAVE_SYS_ENDIAN_H
#include <sys/endian.h>
@ -106,7 +106,7 @@ _ti_find_cap(TBUF *tbuf, char type, short ind)
cap++;
break;
case 'n':
cap += sizeof(uint16_t);
cap += sizeof(uint32_t);
break;
case 's':
num = le16dec(cap);
@ -142,7 +142,7 @@ _ti_find_extra(TBUF *tbuf, const char *code)
cap++;
break;
case 'n':
cap += sizeof(uint16_t);
cap += sizeof(uint32_t);
break;
case 's':
num = le16dec(cap);
@ -157,7 +157,7 @@ _ti_find_extra(TBUF *tbuf, const char *code)
}
size_t
_ti_store_extra(TIC *tic, int wrn, char *id, char type, char flag, short num,
_ti_store_extra(TIC *tic, int wrn, char *id, char type, char flag, int num,
char *str, size_t strl, int flags)
{
size_t l;
@ -182,7 +182,7 @@ _ti_store_extra(TIC *tic, int wrn, char *id, char type, char flag, short num,
}
if (!_ti_grow_tbuf(&tic->extras,
l + strl + (sizeof(uint16_t) * 2) + 1))
l + strl + sizeof(uint16_t) + sizeof(uint32_t) + 1))
return 0;
le16enc(tic->extras.buf + tic->extras.bufpos, (uint16_t)l);
tic->extras.bufpos += sizeof(uint16_t);
@ -194,8 +194,8 @@ _ti_store_extra(TIC *tic, int wrn, char *id, char type, char flag, short num,
tic->extras.buf[tic->extras.bufpos++] = flag;
break;
case 'n':
le16enc(tic->extras.buf + tic->extras.bufpos, (uint16_t)num);
tic->extras.bufpos += sizeof(uint16_t);
le32enc(tic->extras.buf + tic->extras.bufpos, (uint32_t)num);
tic->extras.bufpos += sizeof(uint32_t);
break;
case 's':
le16enc(tic->extras.buf + tic->extras.bufpos, (uint16_t)strl);
@ -239,7 +239,7 @@ _ti_flatten(uint8_t **buf, const TIC *tic)
return -1;
cap = *buf;
*cap++ = 1;
*cap++ = TERMINFO_RTYPE; /* Record type 3 */
le16enc(cap, (uint16_t)len);
cap += sizeof(uint16_t);
memcpy(cap, tic->name, len);
@ -457,7 +457,8 @@ _ti_compile(char *cap, int flags)
char *token, *p, *e, *name, *desc, *alias;
signed char flag;
long cnum;
short ind, num;
short ind;
int num;
size_t len;
TBUF buf;
TIC *tic;
@ -476,6 +477,19 @@ _ti_compile(char *cap, int flags)
if (alias != NULL)
*alias++ = '\0';
if (strlen(name) > UINT16_MAX - 1) {
dowarn(flags, "%s: name too long", name);
return NULL;
}
if (desc != NULL && strlen(desc) > UINT16_MAX - 1) {
dowarn(flags, "%s: description too long: %s", name, desc);
return NULL;
}
if (alias != NULL && strlen(alias) > UINT16_MAX - 1) {
dowarn(flags, "%s: alias too long: %s", name, alias);
return NULL;
}
tic = calloc(sizeof(*tic), 1);
if (tic == NULL)
return NULL;
@ -527,7 +541,7 @@ _ti_compile(char *cap, int flags)
if (encode_string(tic->name, token,
&buf, p, flags) == -1)
goto error;
if (buf.bufpos > UINT16_T_MAX) {
if (buf.bufpos > UINT16_MAX - 1) {
dowarn(flags, "%s: %s: string is too long",
tic->name, token);
continue;
@ -574,29 +588,26 @@ _ti_compile(char *cap, int flags)
tic->name, token);
continue;
}
if (!VALID_NUMERIC(cnum)) {
dowarn(flags, "%s: %s: number out of range",
tic->name, token);
if (!VALID_NUMERIC(cnum) || cnum > INT32_MAX) {
dowarn(flags, "%s: %s: number %ld out of range",
tic->name, token, cnum);
continue;
}
if (cnum > SHRT_MAX)
num = SHRT_MAX;
else
num = (short)cnum;
num = (int)cnum;
if (ind == -1)
_ti_store_extra(tic, 1, token, 'n', -1,
num, NULL, 0, flags);
else {
if (_ti_grow_tbuf(&tic->nums,
sizeof(uint16_t) * 2) == NULL)
sizeof(uint16_t) + sizeof(uint32_t))==NULL)
goto error;
le16enc(tic->nums.buf + tic->nums.bufpos,
(uint16_t)ind);
tic->nums.bufpos += sizeof(uint16_t);
le16enc(tic->nums.buf + tic->nums.bufpos,
(uint16_t)num);
tic->nums.bufpos += sizeof(uint16_t);
le32enc(tic->nums.buf + tic->nums.bufpos,
(uint32_t)num);
tic->nums.bufpos += sizeof(uint32_t);
tic->nums.entries++;
}
continue;
@ -619,9 +630,9 @@ _ti_compile(char *cap, int flags)
le16enc(tic->nums.buf + tic->nums.bufpos,
(uint16_t)ind);
tic->nums.bufpos += sizeof(uint16_t);
le16enc(tic->nums.buf + tic->nums.bufpos,
(uint16_t)CANCELLED_NUMERIC);
tic->nums.bufpos += sizeof(uint16_t);
le32enc(tic->nums.buf + tic->nums.bufpos,
(uint32_t)CANCELLED_NUMERIC);
tic->nums.bufpos += sizeof(uint32_t);
tic->nums.entries++;
continue;
} else if ((ind = (short)_ti_strindex(token)) != -1) {

View File

@ -1,5 +1,5 @@
# $NetBSD: shlib_version,v 1.1 2010/02/03 15:16:32 roy Exp $
# $NetBSD: shlib_version,v 1.2 2020/03/13 15:19:25 roy Exp $
# Remember to update distrib/sets/lists/base/shl.* when changing
#
major=1
major=2
minor=0

View File

@ -1,7 +1,7 @@
/* $NetBSD: term.c,v 1.29 2018/10/08 20:44:34 roy Exp $ */
/* $NetBSD: term.c,v 1.30 2020/03/13 15:19:25 roy Exp $ */
/*
* Copyright (c) 2009, 2010, 2011 The NetBSD Foundation, Inc.
* Copyright (c) 2009, 2010, 2011, 2020 The NetBSD Foundation, Inc.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Roy Marples.
@ -28,7 +28,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: term.c,v 1.29 2018/10/08 20:44:34 roy Exp $");
__RCSID("$NetBSD: term.c,v 1.30 2020/03/13 15:19:25 roy Exp $");
#include <sys/stat.h>
@ -44,7 +44,11 @@ __RCSID("$NetBSD: term.c,v 1.29 2018/10/08 20:44:34 roy Exp $");
#include <term_private.h>
#include <term.h>
#define _PATH_TERMINFO "/usr/share/misc/terminfo"
/*
* Although we can read v1 structure (which includes v2 alias records)
* we really want a v3 structure to get numerics of type int rather than short.
*/
#define _PATH_TERMINFO "/usr/share/misc/terminfo2:/usr/share/misc/terminfo"
static char __ti_database[PATH_MAX];
const char *_ti_database;
@ -72,17 +76,17 @@ allocset(void *pp, int init, size_t nelem, size_t elemsize)
static int
_ti_readterm(TERMINAL *term, const char *cap, size_t caplen, int flags)
{
char ver;
char rtype;
uint16_t ind, num;
size_t len;
TERMUSERDEF *ud;
if (caplen == 0)
goto out;
ver = *cap++;
rtype = *cap++;
caplen--;
/* Only read version 1 structures */
if (ver != 1)
/* Only read type 1 or 3 records */
if (rtype != TERMINFO_RTYPE && rtype != TERMINFO_RTYPE_O1)
goto out;
if (allocset(&term->flags, 0, TIFLAGMAX+1, sizeof(*term->flags)) == -1)
@ -146,10 +150,15 @@ _ti_readterm(TERMINAL *term, const char *cap, size_t caplen, int flags)
for (; num != 0; num--) {
ind = le16dec(cap);
cap += sizeof(uint16_t);
term->nums[ind] = (short)le16dec(cap);
if (rtype == TERMINFO_RTYPE_O1) {
term->nums[ind] = (int)le16dec(cap);
cap += sizeof(uint16_t);
} else {
term->nums[ind] = (int)le32dec(cap);
cap += sizeof(uint32_t);
}
if (flags == 0 && !VALID_NUMERIC(term->nums[ind]))
term->nums[ind] = ABSENT_NUMERIC;
cap += sizeof(uint16_t);
}
}
@ -204,12 +213,17 @@ _ti_readterm(TERMINAL *term, const char *cap, size_t caplen, int flags)
break;
case 'n':
ud->flag = ABSENT_BOOLEAN;
ud->num = (short)le16dec(cap);
if (rtype == TERMINFO_RTYPE_O1) {
ud->num = (int)le16dec(cap);
cap += sizeof(uint16_t);
} else {
ud->num = (int)le32dec(cap);
cap += sizeof(uint32_t);
}
if (flags == 0 &&
!VALID_NUMERIC(ud->num))
ud->num = ABSENT_NUMERIC;
ud->str = ABSENT_STRING;
cap += sizeof(uint16_t);
break;
case 's':
ud->flag = ABSENT_BOOLEAN;

View File

@ -1,7 +1,7 @@
/* $NetBSD: term.h,v 1.22 2017/03/23 00:39:06 roy Exp $ */
/* $NetBSD: term.h,v 1.23 2020/03/13 15:19:25 roy Exp $ */
/*
* Copyright (c) 2009, 2010, 2011, 2013 The NetBSD Foundation, Inc.
* Copyright (c) 2009, 2010, 2011, 2013, 2020 The NetBSD Foundation, Inc.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Roy Marples.
@ -1934,7 +1934,7 @@ typedef struct {
const char *name;
const char *desc;
signed char *flags;
short *nums;
int *nums;
const char **strs;
} TERMINAL;
#endif

View File

@ -1,7 +1,7 @@
/* $NetBSD: term_private.h,v 1.11 2013/01/24 10:41:28 roy Exp $ */
/* $NetBSD: term_private.h,v 1.12 2020/03/13 15:19:25 roy Exp $ */
/*
* Copyright (c) 2009, 2010, 2013 The NetBSD Foundation, Inc.
* Copyright (c) 2009, 2010, 2013, 2020 The NetBSD Foundation, Inc.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Roy Marples.
@ -34,16 +34,22 @@
/* The terminfo database structure is private to us,
* so it's documented here.
*
* Version 1 - types 1 and 2.
* terminfo defines the largest number as 32767 and the largest
* compiled entry as 4093 bytes long.
* compiled entry as 4093 bytes long. Negative numbers are not allowed.
* Thus, we store all numbers as uint16_t, including string length.
* We reserve negative numbers -1 and -2 to mean absent or cancelled.
* All strings are prefixed by length, including the null terminator.
* The largest string length we can handle is 65535 bytes,
* including the null terminator.
* The largest capability block we can handle is 65535 bytes.
* This means that we exceed the current terminfo defined limits.
*
* Version 1 capabilities are defined as:
* Version 2 - type 3
* Extends terminfo numbers upto 2147483647 by storing the value as a uint32_t.
* This means that we exceed the current terminfo defined limits in every way.
*
* Type 1 capabilities are defined as:
* header byte (always 1)
* name
* description,
@ -52,11 +58,14 @@
* cap length, num strings, index, string,
* cap length, num undefined caps, name, type (char), flag, number, string
*
* Version 2 entries are aliases and defined as:
* Type 2 entries are aliases and defined as:
* header byte (always 2)
* 32bit id of the corresponding terminal in the file
* name
*
* Type 3 extends Type 1 so that it can store terminfo numbers
* as uint32_t. All other numerics are still stored as uint16_t.
*
* The database itself is created using cdbw(3) and the numbers are
* always stored as little endian.
*/
@ -64,6 +73,9 @@
#include <sys/types.h>
#define _TERMINFO
#define TERMINFO_RTYPE_O1 1
#define TERMINFO_ALIAS 2
#define TERMINFO_RTYPE 3
/* We use the same ncurses tic macros so that our data is identical
* when a caller uses the long name macros to access te terminfo data
@ -82,7 +94,7 @@ typedef struct {
const char *id;
char type;
char flag;
short num;
int num;
const char *str;
} TERMUSERDEF;
@ -92,7 +104,7 @@ typedef struct {
const char *name;
const char *desc;
signed char *flags;
short *nums;
int *nums;
const char **strs;
/* Storage area for terminfo data */
char *_area;
@ -152,7 +164,7 @@ char *_ti_grow_tbuf(TBUF *, size_t);
char *_ti_get_token(char **, char);
char *_ti_find_cap(TBUF *, char, short);
char *_ti_find_extra(TBUF *, const char *);
size_t _ti_store_extra(TIC *, int, char *, char, char, short,
size_t _ti_store_extra(TIC *, int, char *, char, char, int,
char *, size_t, int);
TIC *_ti_compile(char *, int);
ssize_t _ti_flatten(uint8_t **, const TIC *);

View File

@ -1,12 +1,12 @@
# $NetBSD: Makefile,v 1.3 2012/06/03 23:19:11 joerg Exp $
# $NetBSD: Makefile,v 1.4 2020/03/13 15:19:25 roy Exp $
# from: @(#)Makefile 8.1 (Berkeley) 6/8/93
CLEANFILES= terminfo.cdb
realall: terminfo.cdb
FILES=terminfo.cdb terminfo
CLEANFILES= terminfo2.cdb
realall: terminfo2.cdb
FILES=terminfo2.cdb terminfo
FILESDIR=${BINDIR}/misc
terminfo.cdb: terminfo ${TOOL_TIC}
terminfo2.cdb: terminfo ${TOOL_TIC}
${_MKTARGET_CREATE}
${TOOL_TIC} -ax -o ${.TARGET} "${.CURDIR}/terminfo"

View File

@ -1,7 +1,7 @@
/* $NetBSD: infocmp.c,v 1.12 2017/05/16 09:21:54 roy Exp $ */
/* $NetBSD: infocmp.c,v 1.13 2020/03/13 15:19:25 roy Exp $ */
/*
* Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
* Copyright (c) 2009, 2010, 2020 The NetBSD Foundation, Inc.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Roy Marples.
@ -28,7 +28,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: infocmp.c,v 1.12 2017/05/16 09:21:54 roy Exp $");
__RCSID("$NetBSD: infocmp.c,v 1.13 2020/03/13 15:19:25 roy Exp $");
#include <sys/ioctl.h>
@ -48,7 +48,7 @@ typedef struct tient {
char type;
const char *id;
signed char flag;
short num;
int num;
const char *str;
} TIENT;
@ -441,9 +441,11 @@ load_term(const char *name)
return t;
if (_ti_database == NULL)
errx(EXIT_FAILURE, "no terminal definition found in internal database");
errx(EXIT_FAILURE,
"no terminal definition found in internal database");
else
errx(EXIT_FAILURE, "no terminal definition found in %s.db", _ti_database);
errx(EXIT_FAILURE,
"no terminal definition found in %s.db", _ti_database);
}
static void

View File

@ -1,7 +1,7 @@
/* $NetBSD: tic.c,v 1.31 2017/10/02 21:53:55 joerg Exp $ */
/* $NetBSD: tic.c,v 1.32 2020/03/13 15:19:25 roy Exp $ */
/*
* Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
* Copyright (c) 2009, 2010, 2020 The NetBSD Foundation, Inc.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Roy Marples.
@ -32,7 +32,7 @@
#endif
#include <sys/cdefs.h>
__RCSID("$NetBSD: tic.c,v 1.31 2017/10/02 21:53:55 joerg Exp $");
__RCSID("$NetBSD: tic.c,v 1.32 2020/03/13 15:19:25 roy Exp $");
#include <sys/types.h>
#include <sys/queue.h>
@ -106,7 +106,7 @@ save_term(struct cdbw *db, TERM *term)
if (term->base_term != NULL) {
len = (ssize_t)slen + 7;
buf = emalloc(len);
buf[0] = 2;
buf[0] = TERMINFO_ALIAS;
le32enc(buf + 1, term->base_term->id);
le16enc(buf + 5, slen);
memcpy(buf + 7, term->name, slen);
@ -197,6 +197,9 @@ process_entry(TBUF *buf, int flags)
e = strchr(p, '|');
if (e != NULL)
*e++ = '\0';
/* No need to lengthcheck the alias because the main
* terminfo description already stores all the aliases
* in the same length field as the alias. */
if (find_term(p) != NULL) {
dowarn("%s: has alias for already assigned"
" term %s", tic->name, p);
@ -215,7 +218,8 @@ static void
merge(TIC *rtic, TIC *utic, int flags)
{
char *cap, flag, *code, type, *str;
short ind, num;
short ind, len;
int num;
size_t n;
cap = utic->flags.buf;
@ -238,16 +242,17 @@ merge(TIC *rtic, TIC *utic, int flags)
for (n = utic->nums.entries; n > 0; n--) {
ind = le16dec(cap);
cap += sizeof(uint16_t);
num = le16dec(cap);
cap += sizeof(uint16_t);
num = le32dec(cap);
cap += sizeof(uint32_t);
if (VALID_NUMERIC(num) &&
_ti_find_cap(&rtic->nums, 'n', ind) == NULL)
{
grow_tbuf(&rtic->nums, sizeof(uint16_t) * 2);
grow_tbuf(&rtic->nums, sizeof(uint16_t) +
sizeof(uint32_t));
le16enc(rtic->nums.buf + rtic->nums.bufpos, ind);
rtic->nums.bufpos += sizeof(uint16_t);
le16enc(rtic->nums.buf + rtic->nums.bufpos, num);
rtic->nums.bufpos += sizeof(uint16_t);
le32enc(rtic->nums.buf + rtic->nums.bufpos, num);
rtic->nums.bufpos += sizeof(uint32_t);
rtic->nums.entries++;
}
}
@ -256,22 +261,22 @@ merge(TIC *rtic, TIC *utic, int flags)
for (n = utic->strs.entries; n > 0; n--) {
ind = le16dec(cap);
cap += sizeof(uint16_t);
num = le16dec(cap);
len = le16dec(cap);
cap += sizeof(uint16_t);
if (num > 0 &&
if (len > 0 &&
_ti_find_cap(&rtic->strs, 's', ind) == NULL)
{
grow_tbuf(&rtic->strs, (sizeof(uint16_t) * 2) + num);
grow_tbuf(&rtic->strs, (sizeof(uint16_t) * 2) + len);
le16enc(rtic->strs.buf + rtic->strs.bufpos, ind);
rtic->strs.bufpos += sizeof(uint16_t);
le16enc(rtic->strs.buf + rtic->strs.bufpos, num);
le16enc(rtic->strs.buf + rtic->strs.bufpos, len);
rtic->strs.bufpos += sizeof(uint16_t);
memcpy(rtic->strs.buf + rtic->strs.bufpos,
cap, num);
rtic->strs.bufpos += num;
cap, len);
rtic->strs.bufpos += len;
rtic->strs.entries++;
}
cap += num;
cap += len;
}
cap = utic->extras.buf;
@ -290,8 +295,8 @@ merge(TIC *rtic, TIC *utic, int flags)
continue;
break;
case 'n':
num = le16dec(cap);
cap += sizeof(uint16_t);
num = le32dec(cap);
cap += sizeof(uint32_t);
if (!VALID_NUMERIC(num))
continue;
break;