Module Name:    src
Committed By:   roy
Date:           Tue Oct  4 12:23:14 UTC 2011

Modified Files:
        src/usr.bin/tput: tput.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/usr.bin/tput/tput.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/tput/tput.c
diff -u src/usr.bin/tput/tput.c:1.21 src/usr.bin/tput/tput.c:1.22
--- src/usr.bin/tput/tput.c:1.21	Tue Oct  4 11:02:32 2011
+++ src/usr.bin/tput/tput.c	Tue Oct  4 12:23:14 2011
@@ -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 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19
 #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 @@ main(int argc, char **argv)
 	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 @@ main(int argc, char **argv)
 			}
 			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;
 		}
 

Reply via email to