Source-Changes-HG archive

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

[src/trunk]: src/lib/libterminfo Do our best to process invalid terminfo stri...



details:   https://anonhg.NetBSD.org/src/rev/367408c139bd
branches:  trunk
changeset: 763113:367408c139bd
user:      roy <roy%NetBSD.org@localhost>
date:      Thu Mar 10 13:39:26 2011 +0000

description:
Do our best to process invalid terminfo strings instead of just
returning NULL.

diffstat:

 lib/libterminfo/tparm.c |  44 +++++++++++++++++++-------------------------
 1 files changed, 19 insertions(+), 25 deletions(-)

diffs (129 lines):

diff -r 44224e1c0035 -r 367408c139bd lib/libterminfo/tparm.c
--- a/lib/libterminfo/tparm.c   Thu Mar 10 13:27:03 2011 +0000
+++ b/lib/libterminfo/tparm.c   Thu Mar 10 13:39:26 2011 +0000
@@ -1,7 +1,7 @@
-/* $NetBSD: tparm.c,v 1.4 2011/03/10 10:46:33 roy Exp $ */
+/* $NetBSD: tparm.c,v 1.5 2011/03/10 13:39:26 roy Exp $ */
 
 /*
- * Copyright (c) 2009 The NetBSD Foundation, Inc.
+ * Copyright (c) 2009, 2011 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: tparm.c,v 1.4 2011/03/10 10:46:33 roy Exp $");
+__RCSID("$NetBSD: tparm.c,v 1.5 2011/03/10 13:39:26 roy Exp $");
 
 #include <assert.h>
 #include <ctype.h>
@@ -70,6 +70,10 @@
 pop(long *num, char **string, TPSTACK *stack)
 {
        if (stack->offset == 0) {
+               if (num)
+                       *num = 0;
+               if (string)
+                       *string = NULL;
                errno = E2BIG;
                return -1;
        }
@@ -184,7 +188,7 @@
                c = *sp++;
                if (c < '1' || c > '9') {
                        errno = EINVAL;
-                       return NULL;
+                       continue;
                }
                l = c - '0';
                if (l > max)
@@ -288,14 +292,12 @@
                /* Handle commands */
                switch (c) {
                case 'c':
-                       if (pop(&val, NULL, &stack))
-                           return NULL;
+                       pop(&val, NULL, &stack);
                        if (ochar(term, (unsigned char)val) == 0)
                                return NULL;
                        break;
                case 's':
-                       if (pop(NULL, &ostr, &stack))
-                               return NULL;
+                       pop(NULL, &ostr, &stack);
                        if (ostr != NULL) {
                                l = strlen(ostr);
                                if (l < (size_t)olen)
@@ -308,8 +310,7 @@
                        }
                        break;
                case 'l':
-                       if (pop(NULL, &ostr, &stack))
-                               return NULL;
+                       pop(NULL, &ostr, &stack);
                        if (ostr == NULL)
                                l = 0;
                        else
@@ -321,23 +322,19 @@
                case 'o': /* FALLTHROUGH */
                case 'x': /* FALLTHROUGH */
                case 'X':
-                       if (pop(&val, NULL, &stack))
-                               return NULL;
+                       pop(&val, NULL, &stack);
                        if (onum(term, fmt, val, olen) == 0)
                                return NULL;
                        break;
                case 'p':
-                       if (*str < '1' || *str > '9') {
-                               errno = EINVAL;
-                               return NULL;
-                       }
+                       if (*str < '1' || *str > '9')
+                               break;
                        l = *str++ - '1';
                        if (push(params[l].num, params[l].string, &stack))
                                return NULL;
                        break;
                case 'P':
-                       if (pop(&val, NULL, &stack))
-                               return NULL;
+                       pop(&val, NULL, &stack);
                        if (*str >= 'a' && *str <= 'z')
                                dnums[*str - 'a'] = val;
                        else if (*str >= 'A' && *str <= 'Z')
@@ -391,9 +388,8 @@
                case '=': /* FALLTHROUGH */
                case '<': /* FALLTHROUGH */
                case '>':
-                       if (pop(&val, NULL, &stack) ||
-                           pop(&val2, NULL, &stack))
-                               return NULL;
+                       pop(&val, NULL, &stack);
+                       pop(&val2, NULL, &stack);
                        switch (c) {
                        case '+':
                                val = val + val2;
@@ -440,8 +436,7 @@
                        break;
                case '!':
                case '~':
-                       if (pop(&val, NULL, &stack))
-                               return NULL;
+                       pop(&val, NULL, &stack);
                        switch (*str) {
                        case '!':
                                val = !val;
@@ -456,8 +451,7 @@
                case '?': /* if */
                        break;
                case 't': /* then */
-                       if (pop(&val, NULL, &stack))
-                               return NULL;
+                       pop(&val, NULL, &stack);
                        if (val != 0) {
                                l = 0;
                                for (; *str != '\0'; str++) {



Home | Main Index | Thread Index | Old Index