From adb98feec9c62183cbb3fb596106951de6e9108a Mon Sep 17 00:00:00 2001 From: bad Date: Mon, 2 Mar 2009 22:46:21 +0000 Subject: [PATCH] Only add the ZZ capability for termcap entries that are larger than 1023 bytes. This fixes the problem that enabling the titeInhibit Xresource of xterm has no effect, because xterm exports a TERMCAP string without ti/te sequences but doesn't remove the ZZ capability because it doesn't know about it and termcap(3) ignores the stringe because of the ZZ. Discussed with and OK'ed by blymn@. --- lib/libterm/termcap.3 | 5 +++-- lib/libterm/termcap.c | 43 +++++++++++++++++++++++-------------------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/lib/libterm/termcap.3 b/lib/libterm/termcap.3 index 002294e7127b..15122493e6f8 100644 --- a/lib/libterm/termcap.3 +++ b/lib/libterm/termcap.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: termcap.3,v 1.32 2006/12/18 13:27:25 kleink Exp $ +.\" $NetBSD: termcap.3,v 1.33 2009/03/02 22:46:21 bad Exp $ .\" .\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -468,7 +468,8 @@ The format of the string .Fa entry is assumed to be a valid termcap entry. .Pp -NOTE: A special capability of +NOTE: For termcap entries that are larger than 1023 bytes a special +capability of .Fa ZZ is added to the end of the termcap entry retrieved. The number that follows this entry is the address of the buffer allocated diff --git a/lib/libterm/termcap.c b/lib/libterm/termcap.c index e8eb9235d4e7..32d6ad0954e5 100644 --- a/lib/libterm/termcap.c +++ b/lib/libterm/termcap.c @@ -1,4 +1,4 @@ -/* $NetBSD: termcap.c,v 1.54 2006/12/19 02:02:03 uwe Exp $ */ +/* $NetBSD: termcap.c,v 1.55 2009/03/02 22:46:21 bad Exp $ */ /* * Copyright (c) 1980, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)termcap.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: termcap.c,v 1.54 2006/12/19 02:02:03 uwe Exp $"); +__RCSID("$NetBSD: termcap.c,v 1.55 2009/03/02 22:46:21 bad Exp $"); #endif #endif /* not lint */ @@ -281,29 +281,32 @@ tgetent(char *bp, const char *name) if (i == 1) { /* + * if the termcap entry is larger than 1023 bytes, * stash the full buffer pointer as the ZZ capability * in the termcap buffer passed. */ - plen = asprintf(&ptrbuf, ":ZZ=%p", fbuf->info); - (void)strlcpy(bp, fbuf->info, 1024); - elen = strlen(bp); - /* - * backup over the entry if the addition of the full - * buffer pointer will overflow the buffer passed. We - * want to truncate the termcap entry on a capability - * boundary. - */ - if ((elen + plen) > 1023) { - bp[1023 - plen] = '\0'; - for (c = (elen - plen); c > 0; c--) { - if (bp[c] == ':') { - bp[c] = '\0'; - break; + if (strlcpy(bp, fbuf->info, 1024) >= 1024) { + plen = asprintf(&ptrbuf, ":ZZ=%p", fbuf->info); + (void)strlcpy(bp, fbuf->info, 1024); + elen = strlen(bp); + /* + * backup over the entry if the addition of the full + * buffer pointer will overflow the buffer passed. We + * want to truncate the termcap entry on a capability + * boundary. + */ + if ((elen + plen) > 1023) { + bp[1023 - plen] = '\0'; + for (c = (elen - plen); c > 0; c--) { + if (bp[c] == ':') { + bp[c] = '\0'; + break; + } } - } - } - strcat(bp, ptrbuf); + } + strcat(bp, ptrbuf); + } tbuf = bp; }