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 char line[32];
extern int SYNCHing; /* we are in TELNET SYNCH mode */ 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 extern void
_termstat(void), _termstat(void),
add_slc(char, char, cc_t), add_slc(char, char, cc_t),

View File

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

View File

@ -1288,5 +1288,5 @@ cleanup(int sig __unused)
{ {
(void) shutdown(net, SHUT_RDWR); (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" #include "pathnames.h"
#ifdef __GNO__ #ifdef __GNO__
#include <gno/gno.h>
#include "libtelnet/getaddrinfo.h" #include "libtelnet/getaddrinfo.h"
/* GNO doesn't have struct sockaddr_storage; just use "struct sockaddr" /* GNO doesn't have struct sockaddr_storage; just use "struct sockaddr"
* (which is really struct osockaddr). */ * (which is really struct osockaddr). */
@ -65,6 +66,10 @@ int auth_level = 0;
#endif #endif
#include "libtelnet/misc.h" #include "libtelnet/misc.h"
#ifdef __ORCAC__
#pragma stacksize 1536
#endif
char remote_hostname[MAXHOSTNAMELEN]; char remote_hostname[MAXHOSTNAMELEN];
size_t utmp_len = sizeof(remote_hostname) - 1; size_t utmp_len = sizeof(remote_hostname) - 1;
int registerd_host_only = 0; int registerd_host_only = 0;
@ -145,16 +150,26 @@ main(int argc, char *argv[])
#endif #endif
char *ep; 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; pfrontp = pbackp = ptyobuf;
netip = netibuf; netip = netibuf;
nfrontp = nbackp = netobuf; nfrontp = nbackp = netobuf;
#ifdef ENCRYPTION #ifdef ENCRYPTION
nclearto = 0; nclearto = 0;
#endif /* ENCRYPTION */ #endif /* ENCRYPTION */
#ifdef __GNO__
environInit();
#endif
/* /*
* This initialization causes linemode to default to a configuration * This initialization causes linemode to default to a configuration
@ -579,7 +594,7 @@ getterminaltype(char *name undef2)
ttloop(); ttloop();
} }
if (his_state_is_will(TELOPT_TTYPE)) { if (his_state_is_will(TELOPT_TTYPE)) {
char first[256], last[256]; static char first[256], last[256];
while (sequenceIs(ttypesubopt, baseline)) while (sequenceIs(ttypesubopt, baseline))
ttloop(); ttloop();
@ -647,8 +662,6 @@ _gettermname(void)
int int
terminaltypeok(char *s) terminaltypeok(char *s)
{ {
char buf[1024];
if (terminaltype == NULL) if (terminaltype == NULL)
return(1); return(1);
@ -768,8 +781,8 @@ telnet(int f, int p, char *host)
{ {
int on = 1; int on = 1;
#define TABBUFSIZ 512 #define TABBUFSIZ 512
char defent[TABBUFSIZ]; char *defent = buf;
char defstrs[TABBUFSIZ]; char *defstrs = buf + TABBUFSIZ;
#undef TABBUFSIZ #undef TABBUFSIZ
char *HE; char *HE;
char *HN; char *HN;

View File

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