diff options
author | Amadeusz Sławiński <amade@asmblr.net> | 2015-12-06 12:50:40 +0100 |
---|---|---|
committer | Amadeusz Sławiński <amade@asmblr.net> | 2016-06-18 12:58:19 +0200 |
commit | bfae454059ee3108d753be90f1679a6b692d73c8 (patch) | |
tree | 3abfa810f45311ac4de045a4967ab08bab5b1fc8 | |
parent | 5ecd2b39581286b53d28b291d14554989116990d (diff) | |
download | screen-bfae454059ee3108d753be90f1679a6b692d73c8.tar.gz |
Fix more hardcoded termlen
cherry-pick from master branch
bumped struct msg version
-rw-r--r-- | src/attacher.c | 4 | ||||
-rw-r--r-- | src/display.c | 8 | ||||
-rw-r--r-- | src/process.c | 5 | ||||
-rw-r--r-- | src/screen.c | 12 | ||||
-rw-r--r-- | src/screen.h | 5 | ||||
-rw-r--r-- | src/socket.c | 4 | ||||
-rw-r--r-- | src/termcap.c | 5 | ||||
-rw-r--r-- | src/window.c | 2 |
8 files changed, 25 insertions, 20 deletions
diff --git a/src/attacher.c b/src/attacher.c index c996c10..1052549 100644 --- a/src/attacher.c +++ b/src/attacher.c @@ -364,8 +364,8 @@ int how; } #endif ASSERT(how == MSG_ATTACH || how == MSG_CONT); - strncpy(m.m.attach.envterm, attach_term, sizeof(m.m.attach.envterm) - 1); - m.m.attach.envterm[sizeof(m.m.attach.envterm) - 1] = 0; + strncpy(m.m.attach.envterm, attach_term, MAXTERMLEN); + m.m.attach.envterm[MAXTERMLEN] = 0; debug1("attach: sending %d bytes... ", (int)sizeof(m)); strncpy(m.m.attach.auser, LoginName, sizeof(m.m.attach.auser) - 1); diff --git a/src/display.c b/src/display.c index 05bbe64..b11b18b 100644 --- a/src/display.c +++ b/src/display.c @@ -309,8 +309,8 @@ struct mode *Mode; strncpy(D_usertty, utty, sizeof(D_usertty) - 1); D_usertty[sizeof(D_usertty) - 1] = 0; - strncpy(D_termname, term, sizeof(D_termname) - 1); - D_termname[sizeof(D_termname) - 1] = 0; + strncpy(D_termname, term, MAXTERMLEN); + D_termname[MAXTERMLEN] = 0; D_user = *u; D_processinput = ProcessInput; D_mousetrack = defmousetrack; @@ -3725,14 +3725,14 @@ char **cmdv; char *m; int pid; int slave = -1; - char termname[30]; + char termname[MAXTERMLEN + 6]; #ifndef TIOCSWINSZ char libuf[20], cobuf[20]; #endif char **np; strcpy(termname, "TERM="); - strncpy(termname + 5, D_termname, sizeof(termname) - 6); + strncpy(termname + 5, D_termname, MAXTERMLEN - 6); termname[sizeof(termname) - 1] = 0; KillBlanker(); D_blankerpid = -1; diff --git a/src/process.c b/src/process.c index 77b2d94..4faae47 100644 --- a/src/process.c +++ b/src/process.c @@ -2678,13 +2678,14 @@ int key; s = NULL; if (ParseSaveStr(act, &s)) break; - if (strlen(s) >= MAXTERMLEN) + if (strlen(s) > MAXTERMLEN) { OutputMsg(0, "%s: term: argument too long ( < %d)", rc_name, MAXTERMLEN); free(s); break; } - strcpy(screenterm, s); + strncpy(screenterm, s, MAXTERMLEN); + screenterm[MAXTERMLEN] = '\0'; free(s); debug1("screenterm set to %s\n", screenterm); MakeTermcap((display == 0)); diff --git a/src/screen.c b/src/screen.c index 2792aa2..f84016e 100644 --- a/src/screen.c +++ b/src/screen.c @@ -507,7 +507,8 @@ char **av; #endif nwin = nwin_undef; nwin_options = nwin_undef; - strcpy(screenterm, "screen"); + strncpy(screenterm, "screen", MAXTERMLEN); + screenterm[MAXTERMLEN] = '\0'; #ifdef BUILTIN_TELNET af = AF_UNSPEC; #endif @@ -689,9 +690,10 @@ char **av; case 'T': if (--ac == 0) exit_with_usage(myname, "Specify terminal-type with -T", NULL); - if (strlen(*++av) < 20) - strcpy(screenterm, *av); - else + if (strlen(*++av) < MAXTERMLEN) { + strncpy(screenterm, *av, MAXTERMLEN); + screenterm[MAXTERMLEN] = '\0'; + } else Panic(0, "-T: terminal name too long. (max. 20 char)"); nwin_options.term = screenterm; break; @@ -1034,7 +1036,7 @@ char **av; if ((attach_term = getenv("TERM")) == 0 || *attach_term == 0) Panic(0, "Please set a terminal type."); - if (strlen(attach_term) > sizeof(D_termname) - 1) + if (strlen(attach_term) > MAXTERMLEN) Panic(0, "$TERM too long - sorry."); GetTTY(0, &attach_Mode); #ifdef DEBUGGGGGGGGGGGGGGG diff --git a/src/screen.h b/src/screen.h index 603ca3f..d39b7ea 100644 --- a/src/screen.h +++ b/src/screen.h @@ -184,8 +184,9 @@ struct mode * 2: screen version 4.1.0devel (revisions 8b46d8a upto YYYYYYY) * 3: screen version 4.2.0 (was incorrectly originally. Patched here) * 4: screen version 4.2.1 (bumped once again due to changed terminal and login length) + * 5: screen version 4.4.0 (fix screenterm size) */ -#define MSG_VERSION 4 +#define MSG_VERSION 5 #define MSG_REVISION (('m'<<24) | ('s'<<16) | ('g'<<8) | MSG_VERSION) struct msg @@ -204,7 +205,7 @@ struct msg int nargs; char line[MAXPATHLEN]; char dir[MAXPATHLEN]; - char screenterm[MAXTERMLEN]; /* is screen really "screen" ? */ + char screenterm[MAXTERMLEN + 1]; /* is screen really "screen" ? */ } create; struct diff --git a/src/socket.c b/src/socket.c index 9a3f782..69b53ab 100644 --- a/src/socket.c +++ b/src/socket.c @@ -702,8 +702,8 @@ struct NewWindow *nwin; return; } if (nwin->term != nwin_undef.term) - strncpy(m.m.create.screenterm, nwin->term, 19); - m.m.create.screenterm[19] = '\0'; + strncpy(m.m.create.screenterm, nwin->term, MAXTERMLEN); + m.m.create.screenterm[MAXTERMLEN] = '\0'; m.protocol_revision = MSG_REVISION; debug1("SendCreateMsg writing '%s'\n", m.m.create.line); if (write(s, (char *) &m, sizeof m) != sizeof m) diff --git a/src/termcap.c b/src/termcap.c index 9e72b29..ae89d17 100644 --- a/src/termcap.c +++ b/src/termcap.c @@ -72,7 +72,7 @@ char Termcap[TERMCAP_BUFSIZE + 8]; /* new termcap +8:"TERMCAP=" */ static int Termcaplen; static int tcLineLen; char Term[MAXSTR+5]; /* +5: "TERM=" */ -char screenterm[20]; /* new $TERM, usually "screen" */ +char screenterm[MAXTERMLEN + 1]; /* new $TERM, usually "screen" */ char *extra_incap, *extra_outcap; @@ -883,7 +883,8 @@ int aflag; if (*screenterm == '\0' || strlen(screenterm) > MAXSTR - 3) { debug("MakeTermcap sets screenterm=screen\n"); - strcpy(screenterm, "screen"); + strncpy(screenterm, "screen", MAXTERMLEN); + screenterm[MAXTERMLEN] = '\0'; } #if 0 found = 1; diff --git a/src/window.c b/src/window.c index c68a8d5..b3733b4 100644 --- a/src/window.c +++ b/src/window.c @@ -1438,7 +1438,7 @@ char **args, *ttyn; NewEnv[4] = shellbuf; debug1("ForkWindow: NewEnv[4] = '%s'\n", shellbuf); if (win->w_term && *win->w_term && strcmp(screenterm, win->w_term) && - (strlen(win->w_term) < 20)) + (strlen(win->w_term) < MAXTERMLEN)) { char *s1, *s2, tl; |