Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libcurses Converted all termcap library calls to the "ne...
details: https://anonhg.NetBSD.org/src/rev/6ffe27430941
branches: trunk
changeset: 485119:6ffe27430941
user: blymn <blymn%NetBSD.org@localhost>
date: Wed Apr 19 13:52:39 2000 +0000
description:
Converted all termcap library calls to the "new" interface, this fixes
a problem with curses crashing when the CM capability was larger than
64 bytes and eliminates some possible buffer overflow problems.
diffstat:
lib/libcurses/cr_put.c | 11 +++-
lib/libcurses/refresh.c | 16 ++++--
lib/libcurses/setterm.c | 112 +++++++++++++++++++++++++++++++++++------------
3 files changed, 99 insertions(+), 40 deletions(-)
diffs (truncated from 339 to 300 lines):
diff -r 3844690c8fa2 -r 6ffe27430941 lib/libcurses/cr_put.c
--- a/lib/libcurses/cr_put.c Wed Apr 19 13:45:24 2000 +0000
+++ b/lib/libcurses/cr_put.c Wed Apr 19 13:52:39 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cr_put.c,v 1.16 2000/04/15 13:17:03 blymn Exp $ */
+/* $NetBSD: cr_put.c,v 1.17 2000/04/19 13:52:39 blymn Exp $ */
/*
* Copyright (c) 1981, 1993, 1994
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)cr_put.c 8.3 (Berkeley) 5/4/94";
#else
-__RCSID("$NetBSD: cr_put.c,v 1.16 2000/04/15 13:17:03 blymn Exp $");
+__RCSID("$NetBSD: cr_put.c,v 1.17 2000/04/19 13:52:39 blymn Exp $");
#endif
#endif /* not lint */
@@ -47,6 +47,9 @@
#include "curses.h"
#include "curses_private.h"
+/* the following is defined and set up in setterm.c */
+extern struct tinfo *_cursesi_genbuf;
+
#define HARDTABS 8
/*
@@ -94,7 +97,7 @@
int in_refresh;
{
int c, l;
- char *cgp;
+ char cgp[1024];
if (destcol >= COLS) {
destline += destcol / COLS;
@@ -164,7 +167,7 @@
if (destline < outline && !(CA || UP))
destline = outline;
if (CA) {
- cgp = tgoto(CM, destcol, destline);
+ t_goto(_cursesi_genbuf, CM, destcol, destline, cgp, 1023);
/*
* Need this condition due to inconsistent behavior
diff -r 3844690c8fa2 -r 6ffe27430941 lib/libcurses/refresh.c
--- a/lib/libcurses/refresh.c Wed Apr 19 13:45:24 2000 +0000
+++ b/lib/libcurses/refresh.c Wed Apr 19 13:52:39 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: refresh.c,v 1.20 2000/04/18 22:47:01 jdc Exp $ */
+/* $NetBSD: refresh.c,v 1.21 2000/04/19 13:52:39 blymn Exp $ */
/*
* Copyright (c) 1981, 1993, 1994
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)refresh.c 8.7 (Berkeley) 8/13/94";
#else
-__RCSID("$NetBSD: refresh.c,v 1.20 2000/04/18 22:47:01 jdc Exp $");
+__RCSID("$NetBSD: refresh.c,v 1.21 2000/04/19 13:52:39 blymn Exp $");
#endif
#endif /* not lint */
@@ -47,6 +47,9 @@
#include "curses.h"
#include "curses_private.h"
+/* the following is defined and set up in setterm.c */
+extern struct tinfo *_cursesi_genbuf;
+
static int curwin;
static short ly, lx;
@@ -298,7 +301,7 @@
u_int force;
int clsp, nlsp; /* Last space in lines. */
int lch, wx, y;
- char *ce;
+ char *ce, cm_buff[1024];
attr_t lspb; /* Last space background colour */
#ifdef __GNUC__
@@ -350,9 +353,10 @@
ce = NULL;
if (force) {
- if (CM)
- tputs(tgoto(CM, lx, ly), 0, __cputchar);
- else {
+ if (CM) {
+ t_goto(_cursesi_genbuf, CM, lx, ly, cm_buff, 1023);
+ tputs(cm_buff, 0, __cputchar);
+ } else {
tputs(HO, 0, __cputchar);
__mvcur(0, 0, ly, lx, 1);
}
diff -r 3844690c8fa2 -r 6ffe27430941 lib/libcurses/setterm.c
--- a/lib/libcurses/setterm.c Wed Apr 19 13:45:24 2000 +0000
+++ b/lib/libcurses/setterm.c Wed Apr 19 13:52:39 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: setterm.c,v 1.17 2000/04/17 12:25:46 blymn Exp $ */
+/* $NetBSD: setterm.c,v 1.18 2000/04/19 13:52:39 blymn Exp $ */
/*
* Copyright (c) 1981, 1993, 1994
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)setterm.c 8.8 (Berkeley) 10/25/94";
#else
-__RCSID("$NetBSD: setterm.c,v 1.17 2000/04/17 12:25:46 blymn Exp $");
+__RCSID("$NetBSD: setterm.c,v 1.18 2000/04/19 13:52:39 blymn Exp $");
#endif
#endif /* not lint */
@@ -52,7 +52,9 @@
#include "curses.h"
#include "curses_private.h"
-static void zap __P((void));
+static int zap(struct tinfo *tinfo);
+
+struct tinfo *_cursesi_genbuf;
static char *sflags[] = {
/* am be bs cc da eo hc hl */
@@ -94,16 +96,17 @@
};
static char *aoftspace; /* Address of _tspace for relocation */
-static char tspace[4096]; /* Space for capability strings */
+static char *tspace; /* Space for capability strings */
+static size_t tspace_size; /* size of tspace */
char *ttytype;
int
setterm(char *type)
{
- static char genbuf[2048];
- static char __ttytype[128];
+ static char __ttytype[128], cm_buff[1024], tc[1024], *tcptr;
int unknown;
+ size_t limit;
struct winsize win;
char *p;
@@ -114,9 +117,8 @@
if (type[0] == '\0')
type = "xx";
unknown = 0;
- if (tgetent(genbuf, type) != 1) {
+ if (t_getent(&_cursesi_genbuf, type) != 1) {
unknown++;
- (void)strncpy(genbuf, "xx|dumb:", sizeof(genbuf) - 1);
}
#ifdef DEBUG
__CTRACE("setterm: tty = %s\n", type);
@@ -128,8 +130,14 @@
LINES = win.ws_row;
COLS = win.ws_col;
} else {
- LINES = tgetnum("li");
- COLS = tgetnum("co");
+ if (unknown) {
+ LINES = -1;
+ COLS = -1;
+ } else {
+ LINES = t_getnum(_cursesi_genbuf, "li");
+ COLS = t_getnum(_cursesi_genbuf, "co");
+ }
+
}
/* POSIX 1003.2 requires that the environment override. */
@@ -147,22 +155,20 @@
#ifdef DEBUG
__CTRACE("setterm: LINES = %d, COLS = %d\n", LINES, COLS);
#endif
- aoftspace = tspace;
- zap(); /* Get terminal description. */
-
+ if (!unknown) {
+ if (zap(_cursesi_genbuf) == ERR) /* Get terminal description.*/
+ return ERR;
+ }
+
/* If we can't tab, we can't backtab, either. */
if (!GT)
BT = NULL;
/*
- * Test for cursor motion capbility.
+ * Test for cursor motion capability.
*
- * XXX
- * This is truly stupid -- historically, tgoto returns "OOPS" if it
- * can't do cursor motions. Some systems have been fixed to return
- * a NULL pointer.
*/
- if ((p = tgoto(CM, 0, 0)) == NULL || *p == 'O') {
+ if (t_goto(_cursesi_genbuf, CM, 0, 0, cm_buff, 1023) < 0) {
CA = 0;
CM = 0;
} else
@@ -170,11 +176,19 @@
PC = _PC ? _PC[0] : 0;
aoftspace = tspace;
- ttytype = __longname(genbuf, __ttytype);
-
+ if (unknown) {
+ strcpy(ttytype, "dumb");
+ } else {
+ tcptr = tc;
+ limit = 1023;
+ if (t_getterm(_cursesi_genbuf, &tcptr, &limit) < 0)
+ return ERR;
+ ttytype = __longname(tc, __ttytype);
+ }
+
/* If no scrolling commands, no quick change. */
__noqch =
- (CS == NULL || HO == NULL ||
+ (CS == NULL || HO == NULL ||
(SF == NULL && sf == NULL) || (SR == NULL && sr == NULL)) &&
((AL == NULL && al == NULL) || (DL == NULL && dl == NULL));
@@ -185,14 +199,15 @@
* zap --
* Gets all the terminal flags from the termcap database.
*/
-static void
-zap()
+static int
+zap(struct tinfo *tinfo)
{
const char *namp;
char ***sp;
int **vp;
char **fp;
char tmp[3];
+ size_t i;
#ifdef DEBUG
char *cp;
#endif
@@ -203,7 +218,7 @@
do {
*tmp = *namp;
*(tmp + 1) = *(namp + 1);
- *(*fp++) = tgetflag(tmp);
+ *(*fp++) = t_getflag(tinfo, tmp);
#ifdef DEBUG
__CTRACE("%2.2s = %s\n", namp, *fp[-1] ? "TRUE" : "FALSE");
#endif
@@ -215,19 +230,39 @@
do {
*tmp = *namp;
*(tmp + 1) = *(namp + 1);
- *(*vp++) = tgetnum(tmp);
+ *(*vp++) = t_getnum(tinfo, tmp);
#ifdef DEBUG
__CTRACE("%2.2s = %d\n", namp, *vp[-1]);
#endif
namp += 2;
} while (*namp);
+
+ /* calculate the size of tspace.... */
+ namp = "acaeALasbcblbtcdceclcmcrcsdcDLdmdoeAedeik0k1k2k3k4k5k6k7k8k9hoicimipkdkekhklkrkskullmambmdmemhmkmpmrndnlocoppcprscseSFsospSRtatetiucueupusvbvsveABAFaldlIcIpSbSfsfsrALDLUPDOLERI";
+ tspace_size = 0;
+ do {
+ *tmp = *namp;
+ *(tmp + 1) = *(namp + 1);
+ t_getstr(tinfo, tmp, NULL, &i);
+ tspace_size += i;
+ namp += 2;
+ } while (*namp);
+
+ if ((tspace = (char *) malloc(tspace_size)) == NULL)
+ return ERR;
+#ifdef DEBUG
+ __CTRACE("Allocated %d (0x%x) size buffer for tspace\n", tspace_size,
+ tspace_size);
+#endif
+ aoftspace = tspace;
+
namp = "acaeALasbcblbtcdceclcmcrcsdcDLdmdoeAedeik0k1k2k3k4k5k6k7k8k9hoicimipkdkekhklkrkskullmambmdmemhmkmpmrndnlocoppcprscseSFsospSRtatetiucueupusvbvsveABAFaldlIcIpSbSfsfsrALDLUPDOLERI";
sp = sstrs;
do {
*tmp = *namp;
*(tmp + 1) = *(namp + 1);
- *(*sp++) = tgetstr(tmp, &aoftspace);
+ *(*sp++) = t_getstr(tinfo, tmp, &aoftspace, NULL);
#ifdef DEBUG
__CTRACE("%2.2s = %s", namp, *sp[-1] == NULL ? "NULL\n" : "\"");
if (*sp[-1] != NULL) {
@@ -241,15 +276,17 @@
if (XS)
SO = SE = NULL;
Home |
Main Index |
Thread Index |
Old Index