Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin Convert telnet and top to the new termcap interface....
details: https://anonhg.NetBSD.org/src/rev/3f946b196e15
branches: trunk
changeset: 486548:3f946b196e15
user: blymn <blymn%NetBSD.org@localhost>
date: Thu May 25 12:25:14 2000 +0000
description:
Convert telnet and top to the new termcap interface. This stops some
buffer overflows in top from ever happening.
diffstat:
usr.bin/telnet/commands.c | 10 +++++++-
usr.bin/telnet/telnet.c | 29 +++++++++++++++++++++++---
usr.bin/top/screen.c | 51 +++++++++++++++++++++++++++-------------------
usr.bin/top/screen.h | 4 +-
4 files changed, 65 insertions(+), 29 deletions(-)
diffs (243 lines):
diff -r 8f7a1e21d043 -r 3f946b196e15 usr.bin/telnet/commands.c
--- a/usr.bin/telnet/commands.c Thu May 25 11:41:05 2000 +0000
+++ b/usr.bin/telnet/commands.c Thu May 25 12:25:14 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: commands.c,v 1.40 2000/05/13 03:13:59 itojun Exp $ */
+/* $NetBSD: commands.c,v 1.41 2000/05/25 12:25:14 blymn Exp $ */
/*
* Copyright (C) 1997 and 1998 WIDE Project.
@@ -67,7 +67,7 @@
#if 0
static char sccsid[] = "@(#)commands.c 8.4 (Berkeley) 5/30/95";
#else
-__RCSID("$NetBSD: commands.c,v 1.40 2000/05/13 03:13:59 itojun Exp $");
+__RCSID("$NetBSD: commands.c,v 1.41 2000/05/25 12:25:14 blymn Exp $");
#endif
#endif /* not lint */
@@ -2819,6 +2819,12 @@
cp = arg;
*cpp = NULL;
+
+ /* init these just in case.... */
+ lsrp = NULL;
+ lsrep = NULL;
+ cmsg = NULL;
+
switch (ai->ai_family) {
case AF_INET:
lsrp = lsr;
diff -r 8f7a1e21d043 -r 3f946b196e15 usr.bin/telnet/telnet.c
--- a/usr.bin/telnet/telnet.c Thu May 25 11:41:05 2000 +0000
+++ b/usr.bin/telnet/telnet.c Thu May 25 12:25:14 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: telnet.c,v 1.14 1999/12/30 09:52:03 itojun Exp $ */
+/* $NetBSD: telnet.c,v 1.15 2000/05/25 12:25:15 blymn Exp $ */
/*
* Copyright (c) 1988, 1990, 1993
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)telnet.c 8.4 (Berkeley) 5/30/95";
#else
-__RCSID("$NetBSD: telnet.c,v 1.14 1999/12/30 09:52:03 itojun Exp $");
+__RCSID("$NetBSD: telnet.c,v 1.15 2000/05/25 12:25:15 blymn Exp $");
#endif
#endif /* not lint */
@@ -748,7 +748,7 @@
}
#ifdef TERMCAP
-char termbuf[1024];
+char *termbuf;
/*ARGSUSED*/
int
@@ -756,12 +756,33 @@
char *tname;
int fd, *errp;
{
+ char zz[1024], *zz_ptr;
+ char *ext_tc, *newptr;
+
+ if ((termbuf = (char *) malloc(1024)) == NULL)
+ goto error;
+
if (tgetent(termbuf, tname) == 1) {
- termbuf[1023] = '\0';
+ /* check for ZZ capability, which indicates termcap truncated */
+ zz_ptr = zz;
+ if (tgetstr("ZZ", &zz_ptr) != NULL) {
+ /* it was, fish back the full termcap */
+ sscanf(zz, "%p", &ext_tc);
+ if ((newptr = (char *) realloc(termbuf,
+ strlen(ext_tc) + 1))
+ == NULL) {
+ goto error;
+ }
+
+ strcpy(newptr, ext_tc);
+ termbuf = newptr;
+ }
+
if (errp)
*errp = 1;
return(0);
}
+ error:
if (errp)
*errp = 0;
return(-1);
diff -r 8f7a1e21d043 -r 3f946b196e15 usr.bin/top/screen.c
--- a/usr.bin/top/screen.c Thu May 25 11:41:05 2000 +0000
+++ b/usr.bin/top/screen.c Thu May 25 12:25:14 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: screen.c,v 1.4 1999/10/04 23:33:45 lukem Exp $ */
+/* $NetBSD: screen.c,v 1.5 2000/05/25 12:25:16 blymn Exp $ */
/*
* Top users/processes display for Unix
@@ -57,8 +57,8 @@
char ch_kill;
char smart_terminal;
char PC;
-char termcap_buf[1024];
-char string_buffer[1024];
+struct tinfo *info;
+char *string_buffer;
char home[15];
char lower_left[15];
char *clear_line;
@@ -130,7 +130,7 @@
}
/* now get the termcap entry */
- if ((status = tgetent(termcap_buf, term_name)) != 1)
+ if ((status = t_getent(&info, term_name)) != 1)
{
if (status == -1)
{
@@ -148,21 +148,21 @@
}
/* "hardcopy" immediately indicates a very stupid terminal */
- if (tgetflag("hc"))
+ if (t_getflag(info, "hc"))
{
smart_terminal = No;
return;
}
/* set up common terminal capabilities */
- if ((screen_length = tgetnum("li")) <= 0)
+ if ((screen_length = t_getnum(info, "li")) <= 0)
{
screen_length = smart_terminal = 0;
return;
}
/* screen_width is a little different */
- if ((screen_width = tgetnum("co")) == -1)
+ if ((screen_width = t_getnum(info, "co")) == -1)
{
screen_width = 79;
}
@@ -172,37 +172,38 @@
}
/* terminals that overstrike need special attention */
- overstrike = tgetflag("os");
+ overstrike = t_getflag(info, "os");
/* initialize the pointer into the termcap string buffer */
- bufptr = string_buffer;
+ string_buffer = NULL;
/* get "ce", clear to end */
if (!overstrike)
{
- clear_line = tgetstr("ce", &bufptr);
+ clear_line = t_agetstr(info, "ce", &string_buffer, &bufptr);
}
/* get necessary capabilities */
- if ((clear_screen = tgetstr("cl", &bufptr)) == NULL ||
- (cursor_motion = tgetstr("cm", &bufptr)) == NULL)
+ if ((clear_screen = t_agetstr(info, "cl", &string_buffer, &bufptr)) == NULL ||
+ (cursor_motion = t_agetstr(info, "cm", &string_buffer, &bufptr)) == NULL)
{
smart_terminal = No;
return;
}
/* get some more sophisticated stuff -- these are optional */
- clear_to_end = tgetstr("cd", &bufptr);
- terminal_init = tgetstr("ti", &bufptr);
- terminal_end = tgetstr("te", &bufptr);
- start_standout = tgetstr("so", &bufptr);
- end_standout = tgetstr("se", &bufptr);
+ clear_to_end = t_agetstr(info, "cd", &string_buffer, &bufptr);
+ terminal_init = t_agetstr(info, "ti", &string_buffer, &bufptr);
+ terminal_end = t_agetstr(info, "te", &string_buffer, &bufptr);
+ start_standout = t_agetstr(info, "so", &string_buffer, &bufptr);
+ end_standout = t_agetstr(info, "se", &string_buffer, &bufptr);
/* pad character */
- PC = (PCptr = tgetstr("pc", &bufptr)) ? *PCptr : 0;
+ PC = (PCptr = t_agetstr(info, "pc", &string_buffer, &bufptr)) ? *PCptr : 0;
/* set convenience strings */
- (void) strcpy(home, tgoto(cursor_motion, 0, 0));
+ home[0] = '\0';
+ t_goto(info, cursor_motion, 0, 0, home, 14);
/* (lower_left is set in get_screensize) */
/* get the actual screen size with an ioctl, if needed */
@@ -421,8 +422,8 @@
#endif /* TIOCGSIZE */
#endif /* TIOCGWINSZ */
-
- (void) strcpy(lower_left, tgoto(cursor_motion, 0, screen_length - 1));
+ lower_left[0] = '\0';
+ t_goto(info, cursor_motion, 0, screen_length - 1, lower_left, 14);
}
void
@@ -499,3 +500,11 @@
return (putchar(ch));
}
+void
+Move_to(int x, int y)
+{
+ char buf[256];
+
+ if(t_goto(info, cursor_motion, x, y, buf, 255) == 0)
+ TCputs(buf);
+}
diff -r 8f7a1e21d043 -r 3f946b196e15 usr.bin/top/screen.h
--- a/usr.bin/top/screen.h Thu May 25 11:41:05 2000 +0000
+++ b/usr.bin/top/screen.h Thu May 25 12:25:14 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: screen.h,v 1.4 1999/10/04 23:33:45 lukem Exp $ */
+/* $NetBSD: screen.h,v 1.5 2000/05/25 12:25:17 blymn Exp $ */
/*
* top - a top users display for Unix 4.2
@@ -9,7 +9,6 @@
#define TCputs(str) tputs(str, 1, putstdout)
#define putcap(str) (void)((str) != NULL ? TCputs(str) : 0)
-#define Move_to(x, y) TCputs(tgoto(cursor_motion, x, y))
/* declare return values for termcap functions */
#ifdef __NetBSD__
@@ -43,3 +42,4 @@
int clear_eol __P((int));
void go_home __P((void));
int putstdout __P((int));
+void Move_to(int x, int y);
Home |
Main Index |
Thread Index |
Old Index