Source-Changes-HG archive

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

[src/trunk]: src/lib/libterminfo Fix some off by one issues with arraycount ....



details:   https://anonhg.NetBSD.org/src/rev/d3514251cdab
branches:  trunk
changeset: 350448:d3514251cdab
user:      roy <roy%NetBSD.org@localhost>
date:      Wed Jan 11 20:53:52 2017 +0000

description:
Fix some off by one issues with arraycount ..thanks coypu.

diffstat:

 lib/libterminfo/genhash   |   6 +++---
 lib/libterminfo/termcap.c |  16 ++++++++--------
 2 files changed, 11 insertions(+), 11 deletions(-)

diffs (100 lines):

diff -r 2f0e4feb595c -r d3514251cdab lib/libterminfo/genhash
--- a/lib/libterminfo/genhash   Wed Jan 11 20:43:03 2017 +0000
+++ b/lib/libterminfo/genhash   Wed Jan 11 20:53:52 2017 +0000
@@ -1,5 +1,5 @@
 #!/bin/sh
-# $NetBSD: genhash,v 1.8 2011/11/02 12:09:25 roy Exp $
+# $NetBSD: genhash,v 1.9 2017/01/11 20:53:52 roy Exp $
 
 # Copyright (c) 2009, 2011 The NetBSD Foundation, Inc.
 #
@@ -65,7 +65,7 @@
 _ti_${name}id(ssize_t idx)
 {
 
-       if ((size_t)idx > __arraycount(_ti_${name}ids))
+       if ((size_t)idx >= __arraycount(_ti_${name}ids))
                return NULL;
        return _ti_${name}ids[idx];
 }
@@ -76,7 +76,7 @@
        uint32_t idx;
 
        idx = _ti_${name}hash((const unsigned char *)key, strlen(key));
-       if (idx > __arraycount(_ti_${name}ids) ||
+       if (idx >= __arraycount(_ti_${name}ids) ||
            strcmp(key, _ti_${name}ids[idx]) != 0)
                return -1;
        return idx;
diff -r 2f0e4feb595c -r d3514251cdab lib/libterminfo/termcap.c
--- a/lib/libterminfo/termcap.c Wed Jan 11 20:43:03 2017 +0000
+++ b/lib/libterminfo/termcap.c Wed Jan 11 20:53:52 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: termcap.c,v 1.19 2016/04/01 19:59:08 christos Exp $ */
+/* $NetBSD: termcap.c,v 1.20 2017/01/11 20:53:52 roy Exp $ */
 
 /*
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: termcap.c,v 1.19 2016/04/01 19:59:08 christos Exp $");
+__RCSID("$NetBSD: termcap.c,v 1.20 2017/01/11 20:53:52 roy Exp $");
 
 #include <assert.h>
 #include <ctype.h>
@@ -88,7 +88,7 @@
                return 0;
 
        ind = _t_flaghash((const unsigned char *)id, strlen(id));
-       if (ind <= __arraycount(_ti_cap_flagids)) {
+       if (ind < __arraycount(_ti_cap_flagids)) {
                if (strcmp(id, _ti_cap_flagids[ind].id) == 0)
                        return cur_term->flags[_ti_cap_flagids[ind].ti];
        }
@@ -113,7 +113,7 @@
                return -1;
 
        ind = _t_numhash((const unsigned char *)id, strlen(id));
-       if (ind <= __arraycount(_ti_cap_numids)) {
+       if (ind < __arraycount(_ti_cap_numids)) {
                te = &_ti_cap_numids[ind];
                if (strcmp(id, te->id) == 0) {
                        if (!VALID_NUMERIC(cur_term->nums[te->ti]))
@@ -146,7 +146,7 @@
 
        str = NULL;
        ind = _t_strhash((const unsigned char *)id, strlen(id));
-       if (ind <= __arraycount(_ti_cap_strids)) {
+       if (ind < __arraycount(_ti_cap_strids)) {
                if (strcmp(id, _ti_cap_strids[ind].id) == 0) {
                        str = cur_term->strs[_ti_cap_strids[ind].ti];
                        if (str == NULL)
@@ -188,7 +188,7 @@
        uint32_t idx;
 
        idx = _t_flaghash((const unsigned char *)key, strlen(key));
-       if (idx <= __arraycount(_ti_cap_flagids) &&
+       if (idx < __arraycount(_ti_cap_flagids) &&
            strcmp(key, _ti_cap_flagids[idx].id) == 0)
                return _ti_flagid(_ti_cap_flagids[idx].ti);
        return key;
@@ -200,7 +200,7 @@
        uint32_t idx;
 
        idx = _t_numhash((const unsigned char *)key, strlen(key));
-       if (idx <= __arraycount(_ti_cap_numids) && 
+       if (idx < __arraycount(_ti_cap_numids) && 
            strcmp(key, _ti_cap_numids[idx].id) == 0)
                return _ti_numid(_ti_cap_numids[idx].ti);
        return key;
@@ -212,7 +212,7 @@
        uint32_t idx;
 
        idx = _t_strhash((const unsigned char *)key, strlen(key));
-       if (idx <= __arraycount(_ti_cap_strids) &&
+       if (idx < __arraycount(_ti_cap_strids) &&
            strcmp(key, _ti_cap_strids[idx].id) == 0)
                return _ti_strid(_ti_cap_strids[idx].ti);
 



Home | Main Index | Thread Index | Old Index