From 26bd22ac440a9ddd20e5874954b89add01ab5963 Mon Sep 17 00:00:00 2001 From: roy Date: Tue, 4 Oct 2011 12:23:14 +0000 Subject: [PATCH] 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. --- usr.bin/tput/tput.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/usr.bin/tput/tput.c b/usr.bin/tput/tput.c index 8589ff4e434f..ab222f73254e 100644 --- a/usr.bin/tput/tput.c +++ b/usr.bin/tput/tput.c @@ -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, 1988, 1993\ #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 @@ -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; }