Eliminate large stack-allocated buffers, and set the stack size to 1.5k.

Also includes code to check the stack usage, which in my testing showed a maximum of 1025 bytes.
This commit is contained in:
Stephen Heumann 2016-01-08 19:31:20 -06:00
parent 7f21186a25
commit 494c69cf82
5 changed files with 30 additions and 16 deletions

View File

@ -80,6 +80,9 @@ extern int pty, net;
extern char line[32];
extern int SYNCHing; /* we are in TELNET SYNCH mode */
/* Buffer for miscellaneous uses in various functions */
extern char buf[BUFSIZ > 1024 ? BUFSIZ : 1024];
extern void
_termstat(void),
add_slc(char, char, cc_t),

View File

@ -1495,7 +1495,7 @@ doclientstat(void)
void
send_status(void)
{
unsigned char statusbuf[256];
static unsigned char statusbuf[256];
unsigned char *ncp;
unsigned char i;

View File

@ -1288,5 +1288,5 @@ cleanup(int sig __unused)
{
(void) shutdown(net, SHUT_RDWR);
_exit(1);
exit(1);
}

View File

@ -43,6 +43,7 @@ static const char sccsid[] = "@(#)telnetd.c 8.4 (Berkeley) 5/30/95";
#include "pathnames.h"
#ifdef __GNO__
#include <gno/gno.h>
#include "libtelnet/getaddrinfo.h"
/* GNO doesn't have struct sockaddr_storage; just use "struct sockaddr"
* (which is really struct osockaddr). */
@ -65,6 +66,10 @@ int auth_level = 0;
#endif
#include "libtelnet/misc.h"
#ifdef __ORCAC__
#pragma stacksize 1536
#endif
char remote_hostname[MAXHOSTNAMELEN];
size_t utmp_len = sizeof(remote_hostname) - 1;
int registerd_host_only = 0;
@ -145,16 +150,26 @@ main(int argc, char *argv[])
#endif
char *ep;
#ifdef __GNO__
if (getenv("TELNETD_STACKCHECK") != NULL)
_reportStack();
/* Make sure our environment is isolated from the parent process's */
if (environPush() == 0)
atexit(environPop);
else
exit(1);
environInit();
#endif
pfrontp = pbackp = ptyobuf;
netip = netibuf;
nfrontp = nbackp = netobuf;
#ifdef ENCRYPTION
nclearto = 0;
#endif /* ENCRYPTION */
#ifdef __GNO__
environInit();
#endif
/*
* This initialization causes linemode to default to a configuration
@ -579,7 +594,7 @@ getterminaltype(char *name undef2)
ttloop();
}
if (his_state_is_will(TELOPT_TTYPE)) {
char first[256], last[256];
static char first[256], last[256];
while (sequenceIs(ttypesubopt, baseline))
ttloop();
@ -647,8 +662,6 @@ _gettermname(void)
int
terminaltypeok(char *s)
{
char buf[1024];
if (terminaltype == NULL)
return(1);
@ -768,8 +781,8 @@ telnet(int f, int p, char *host)
{
int on = 1;
#define TABBUFSIZ 512
char defent[TABBUFSIZ];
char defstrs[TABBUFSIZ];
char *defent = buf;
char *defstrs = buf + TABBUFSIZ;
#undef TABBUFSIZ
char *HE;
char *HN;

View File

@ -326,8 +326,6 @@ netflush(void)
void
fatal(int f, const char *msg)
{
char buf[BUFSIZ];
(void) snprintf(buf, sizeof(buf), "telnetd: %s.\r\n", msg);
#ifdef ENCRYPTION
if (encrypt_output) {
@ -347,7 +345,7 @@ fatal(int f, const char *msg)
void
fatalperror(int f, const char *msg)
{
char buf[BUFSIZ];
static char buf[BUFSIZ];
(void) snprintf(buf, sizeof(buf), "%s: %s", msg, strerror(errno));
fatal(f, buf);
@ -722,7 +720,7 @@ printsub(char direction, unsigned char *pointer, int length)
break;
}
{
char tbuf[32];
static char tbuf[32];
sprintf(tbuf, "%s%s%s%s%s",
pointer[2]&MODE_EDIT ? "|EDIT" : "",
pointer[2]&MODE_TRAPSIG ? "|TRAPSIG" : "",
@ -1057,7 +1055,7 @@ void
printdata(const char *tag, char *ptr, int cnt)
{
int i;
char xbuf[30];
static char xbuf[30];
while (cnt) {
/* flush net output buffer if no room for new data) */