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> | 2015-12-06 13:44:53 +0100 |
| commit | 37ca949e462a7608572f653848b5a7554964fd53 (patch) | |
| tree | a0daa9cd74ed580f95662dfb6f9b8df5b642d816 | |
| parent | 81b21e090a68f36a7b4542200c034da5c4309d91 (diff) | |
| download | screen-37ca949e462a7608572f653848b5a7554964fd53.tar.gz | |
Fix more hardcoded termlen
| -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 | 10 | ||||
| -rw-r--r-- | src/screen.h | 2 | ||||
| -rw-r--r-- | src/socket.c | 4 | ||||
| -rw-r--r-- | src/termcap.c | 5 | ||||
| -rw-r--r-- | src/window.c | 2 |
8 files changed, 22 insertions, 18 deletions
diff --git a/src/attacher.c b/src/attacher.c index 5fbf444..2abb388 100644 --- a/src/attacher.c +++ b/src/attacher.c @@ -237,8 +237,8 @@ int Attach(int how) Panic(0, "Cannot contact screen again. Sigh."); m.type = how; } - 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; strncpy(m.m.attach.auser, LoginName, sizeof(m.m.attach.auser) - 1); m.m.attach.auser[sizeof(m.m.attach.auser) - 1] = 0; diff --git a/src/display.c b/src/display.c index f455eda..4c371ec 100644 --- a/src/display.c +++ b/src/display.c @@ -233,8 +233,8 @@ Display *MakeDisplay(char *uname, char *utty, char *term, int fd, int pid, struc 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; @@ -2807,11 +2807,11 @@ void RunBlanker(char **cmdv) char *m; int pid; int slave = -1; - char termname[FILENAME_MAX + 1]; + char termname[MAXTERMLEN + 6]; char **np; strncpy(termname, "TERM=", 6); - 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 5827e77..6f0e086 100644 --- a/src/process.c +++ b/src/process.c @@ -2153,12 +2153,13 @@ void DoAction(struct action *act, 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; } - strncpy(screenterm, s, 20); + strncpy(screenterm, s, MAXTERMLEN); + screenterm[MAXTERMLEN] = '\0'; free(s); MakeTermcap((display == 0)); break; diff --git a/src/screen.c b/src/screen.c index 70f3295..e419bc5 100644 --- a/src/screen.c +++ b/src/screen.c @@ -266,7 +266,8 @@ int main(int argc, char **argv) cjkwidth = 0; nwin = nwin_undef; nwin_options = nwin_undef; - strncpy(screenterm, "screen", 20); + strncpy(screenterm, "screen", MAXTERMLEN); + screenterm[MAXTERMLEN] = '\0'; #ifdef BUILTIN_TELNET af = AF_UNSPEC; #endif @@ -428,9 +429,10 @@ int main(int argc, char **argv) case 'T': if (--argc == 0) exit_with_usage(myname, "Specify terminal-type with -T", NULL); - if (strlen(*++argv) < MAXTERMLEN) + if (strlen(*++argv) < MAXTERMLEN) { strncpy(screenterm, *argv, MAXTERMLEN); - else + screenterm[MAXTERMLEN] = '\0'; + } else Panic(0, "-T: terminal name too long. (max. %d char)", MAXTERMLEN); nwin_options.term = screenterm; break; @@ -678,7 +680,7 @@ int main(int argc, char **argv) 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); } diff --git a/src/screen.h b/src/screen.h index b043e5c..d5869e8 100644 --- a/src/screen.h +++ b/src/screen.h @@ -127,7 +127,7 @@ struct Message { 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 { char auser[MAXLOGINLEN + 1]; /* username */ diff --git a/src/socket.c b/src/socket.c index 4e8e078..80e92c0 100644 --- a/src/socket.c +++ b/src/socket.c @@ -454,8 +454,8 @@ void SendCreateMsg(char *sty, 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; if (write(s, (char *)&m, sizeof m) != sizeof m) Msg(errno, "write"); diff --git a/src/termcap.c b/src/termcap.c index c333075..0edb776 100644 --- a/src/termcap.c +++ b/src/termcap.c @@ -56,7 +56,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; @@ -673,7 +673,8 @@ char *MakeTermcap(int aflag) } Termcaplen = 0; if (*screenterm == '\0' || strlen(screenterm) > MAXSTR - 3) { - strncpy(screenterm, "screen", 20); + strncpy(screenterm, "screen", MAXTERMLEN); + screenterm[MAXTERMLEN] = '\0'; } do { strcpy(Term, "TERM="); diff --git a/src/window.c b/src/window.c index 42dddc5..aa5d405 100644 --- a/src/window.c +++ b/src/window.c @@ -1048,7 +1048,7 @@ static int ForkWindow(Window *win, char **args, char *ttyn) strncpy(shellbuf + 6, ShellProg + (*ShellProg == '-'), sizeof(shellbuf) - 7); shellbuf[sizeof(shellbuf) - 1] = 0; NewEnv[4] = shellbuf; - if (win->w_term && *win->w_term && strcmp(screenterm, win->w_term) && (strlen(win->w_term) < 20)) { + if (win->w_term && *win->w_term && strcmp(screenterm, win->w_term) && (strlen(win->w_term) < MAXTERMLEN)) { char *s1, *s2, tl; sprintf(tebuf, "TERM=%s", win->w_term); |
