Source-Changes-HG archive

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

[src/trunk]: src terminfo: promote numeric parameters from short to int



details:   https://anonhg.NetBSD.org/src/rev/92eb9fb4f71d
branches:  trunk
changeset: 745824:92eb9fb4f71d
user:      roy <roy%NetBSD.org@localhost>
date:      Fri Mar 13 15:19:24 2020 +0000

description:
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.

diffstat:

 distrib/sets/lists/base/mi     |   4 +-
 distrib/sets/lists/base/shl.mi |  26 ++++++++--------
 lib/libcurses/shlib_version    |   6 ++--
 lib/libform/shlib_version      |   4 +-
 lib/libmenu/shlib_version      |   4 +-
 lib/libpanel/shlib_version     |   4 +-
 lib/libterminfo/compile.c      |  63 ++++++++++++++++++++++++-----------------
 lib/libterminfo/shlib_version  |   4 +-
 lib/libterminfo/term.c         |  38 +++++++++++++++++--------
 lib/libterminfo/term.h         |   6 ++--
 lib/libterminfo/term_private.h |  30 ++++++++++++++------
 share/terminfo/Makefile        |  10 +++---
 usr.bin/infocmp/infocmp.c      |  14 +++++----
 usr.bin/tic/tic.c              |  43 ++++++++++++++++------------
 14 files changed, 150 insertions(+), 106 deletions(-)

diffs (truncated from 710 to 300 lines):

diff -r fefcfe9644dc -r 92eb9fb4f71d distrib/sets/lists/base/mi
--- a/distrib/sets/lists/base/mi        Fri Mar 13 10:01:07 2020 +0000
+++ b/distrib/sets/lists/base/mi        Fri Mar 13 15:19:24 2020 +0000
@@ -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
diff -r fefcfe9644dc -r 92eb9fb4f71d distrib/sets/lists/base/shl.mi
--- a/distrib/sets/lists/base/shl.mi    Fri Mar 13 10:01:07 2020 +0000
+++ b/distrib/sets/lists/base/shl.mi    Fri Mar 13 15:19:24 2020 +0000
@@ -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
diff -r fefcfe9644dc -r 92eb9fb4f71d lib/libcurses/shlib_version
--- a/lib/libcurses/shlib_version       Fri Mar 13 10:01:07 2020 +0000
+++ b/lib/libcurses/shlib_version       Fri Mar 13 15:19:24 2020 +0000
@@ -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
diff -r fefcfe9644dc -r 92eb9fb4f71d lib/libform/shlib_version
--- a/lib/libform/shlib_version Fri Mar 13 10:01:07 2020 +0000
+++ b/lib/libform/shlib_version Fri Mar 13 15:19:24 2020 +0000
@@ -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
diff -r fefcfe9644dc -r 92eb9fb4f71d lib/libmenu/shlib_version
--- a/lib/libmenu/shlib_version Fri Mar 13 10:01:07 2020 +0000
+++ b/lib/libmenu/shlib_version Fri Mar 13 15:19:24 2020 +0000
@@ -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
diff -r fefcfe9644dc -r 92eb9fb4f71d lib/libpanel/shlib_version
--- a/lib/libpanel/shlib_version        Fri Mar 13 10:01:07 2020 +0000
+++ b/lib/libpanel/shlib_version        Fri Mar 13 15:19:24 2020 +0000
@@ -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
diff -r fefcfe9644dc -r 92eb9fb4f71d lib/libterminfo/compile.c
--- a/lib/libterminfo/compile.c Fri Mar 13 10:01:07 2020 +0000
+++ b/lib/libterminfo/compile.c Fri Mar 13 15:19:24 2020 +0000
@@ -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 @@
                        cap++;
                        break;
                case 'n':
-                       cap += sizeof(uint16_t);
+                       cap += sizeof(uint32_t);
                        break;
                case 's':
                        num = le16dec(cap);
@@ -142,7 +142,7 @@
                        cap++;
                        break;
                case 'n':
-                       cap += sizeof(uint16_t);
+                       cap += sizeof(uint32_t);
                        break;
                case 's':
                        num = le16dec(cap);
@@ -157,7 +157,7 @@
 }
 
 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 @@
        }
 
        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 @@
                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 @@
                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 @@
        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 @@
        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 @@
                        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 @@
                                    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 @@
                                le16enc(tic->nums.buf + tic->nums.bufpos,
                                    (uint16_t)ind);
                                tic->nums.bufpos += sizeof(uint16_t);



Home | Main Index | Thread Index | Old Index