diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1996-09-03 16:04:58 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1996-09-03 16:04:58 +0000 |
commit | d6631cc24a4fcf56093ab90bdf2a08692a471d50 (patch) | |
tree | 6b7871843eea8fff2734a42f4e7eeb4a042a5d4b /lib/libterm | |
parent | e6c27ccd9af1a83d1e6b18c743f3f1a49b0af807 (diff) |
fix buf oflows better
Diffstat (limited to 'lib/libterm')
-rw-r--r-- | lib/libterm/termcap.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/lib/libterm/termcap.c b/lib/libterm/termcap.c index 8e11888836b..391963045e7 100644 --- a/lib/libterm/termcap.c +++ b/lib/libterm/termcap.c @@ -80,7 +80,7 @@ tgetent(bp, name) char **fname; char *home; int i; - char pathbuf[PBUFSIZ]; /* holds raw path of filenames */ + char pathbuf[PBUFSIZ+1]; /* holds raw path of filenames */ char *pathvec[PVECSIZ]; /* to point to names in pathbuf */ char **pvec; /* holds usable tail of path vector */ char *termpath; @@ -102,21 +102,25 @@ tgetent(bp, name) */ if (!cp || *cp != '/') { /* no TERMCAP or it holds an entry */ if ((termpath = getenv("TERMPATH")) != NULL) - strncpy(pathbuf, termpath, PBUFSIZ); + strncpy(pathbuf, termpath, sizeof(pathbuf) - 1); else { if ((home = getenv("HOME")) != NULL) { /* set up default */ - strncpy(pathbuf, home, PBUFSIZ - strlen(_PATH_DEF) - 1); /* $HOME first */ - pathbuf[PBUFSIZ - strlen(_PATH_DEF) - 1] = '\0'; + /* $HOME first */ + strncpy(pathbuf, home, sizeof(pathbuf) - 1 - + strlen(_PATH_DEF) - 1); + pathbuf[sizeof(pathbuf) - 1 - + strlen(_PATH_DEF) - 1] = '\0'; p += strlen(pathbuf); /* path, looking in */ *p++ = '/'; } /* if no $HOME look in current directory */ - strncpy(p, _PATH_DEF, PBUFSIZ - (p - pathbuf)); + strncpy(p, _PATH_DEF, sizeof(pathbuf) -1 - + (p - pathbuf)); } } else /* user-defined name in TERMCAP */ - strncpy(pathbuf, cp, PBUFSIZ); /* still can be tokenized */ - pathbuf[PBUFSIZ] = '\0'; + strncpy(pathbuf, cp, sizeof(pathbuf) - 1); /* still can be tokenized */ + pathbuf[sizeof(pathbuf) - 1] = '\0'; *fname++ = pathbuf; /* tokenize path into vector of names */ while (*++p) |