Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/tput Ensure we only pass cap names of one or two cha...



details:   https://anonhg.NetBSD.org/src/rev/205222e4903c
branches:  trunk
changeset: 770123:205222e4903c
user:      roy <roy%NetBSD.org@localhost>
date:      Tue Oct 04 12:23:14 2011 +0000

description:
Ensure we only pass cap names of one or two characters to tgetstr
and friends so we don't mistakenly try and convert a terminfo code to a
termcap code.

diffstat:

 usr.bin/tput/tput.c |  21 +++++++++++++--------
 1 files changed, 13 insertions(+), 8 deletions(-)

diffs (54 lines):

diff -r 27e4ca195f3a -r 205222e4903c usr.bin/tput/tput.c
--- a/usr.bin/tput/tput.c       Tue Oct 04 12:01:21 2011 +0000
+++ b/usr.bin/tput/tput.c       Tue Oct 04 12:23:14 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tput.c,v 1.21 2011/10/04 11:02:32 roy Exp $    */
+/*     $NetBSD: tput.c,v 1.22 2011/10/04 12:23:14 roy Exp $    */
 
 /*-
  * Copyright (c) 1980, 1988, 1993
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)tput.c     8.3 (Berkeley) 4/28/95";
 #endif
-__RCSID("$NetBSD: tput.c,v 1.21 2011/10/04 11:02:32 roy Exp $");
+__RCSID("$NetBSD: tput.c,v 1.22 2011/10/04 12:23:14 roy Exp $");
 #endif /* not lint */
 
 #include <termios.h>
@@ -62,6 +62,7 @@
        int ch, exitval, n;
        char *term;
        const char *p, *s;
+       size_t pl;
 
        term = NULL;
        while ((ch = getopt(argc, argv, "T:")) != -1)
@@ -109,17 +110,21 @@
                        }
                        break;
                }
+               pl = strlen(p);
                if (((s = tigetstr(p)) != NULL && s != (char *)-1) ||
-                   ((s = tgetstr(p, NULL)) != NULL))
+                   (pl <= 2 && (s = tgetstr(p, NULL)) != NULL))
                        argv = process(p, s, argv);
-               else if ((((n = tigetnum(p)) != -1 && n != -2 )||
-                          (n = tgetnum(p)) != -1))
+               else if ((((n = tigetnum(p)) != -1 && n != -2 ) ||
+                          (pl <= 2 && (n = tgetnum(p)) != -1)))
                        (void)printf("%d\n", n);
                else {
                        exitval = tigetflag(p);
-                       if (exitval == -1)
-                               exitval = !tgetflag(p);
-                       else
+                       if (exitval == -1) {
+                               if (pl <= 2)
+                                       exitval = !tgetflag(p);
+                               else
+                                       exitval = 1;
+                       } else
                                exitval = !exitval;
                }
 



Home | Main Index | Thread Index | Old Index