Improve upon previous commit:

1.  Check return of mmap(2) (*)
2.  Avoid FD leak when fstat fails.
3.  Fix style(9).

(*) Pointed out by jmg@


git-svn-id: http://svn0.us-east.freebsd.org/base/head/contrib/telnet@262679 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
This commit is contained in:
marcel 2014-03-02 03:34:06 +00:00
parent 2c30da6c4a
commit 2d43ae29e1

View File

@ -926,14 +926,15 @@ telnet(int f, int p, char *host)
if (hostinfo && *IM) if (hostinfo && *IM)
putf(IM, ptyibuf2); putf(IM, ptyibuf2);
if (IF && if_fd != -1) { if (IF && if_fd != -1) {
if(fstat (if_fd, &statbuf)!=-1) { if (fstat(if_fd, &statbuf) != -1 && statbuf.st_size > 0) {
if (statbuf.st_size > 0) { if_buf = (char *) mmap (0, statbuf.st_size,
if_buf = (char *) mmap (0, statbuf.st_size, PROT_READ, 0, if_fd, 0); PROT_READ, 0, if_fd, 0);
if (if_buf != MAP_FAILED) {
putf(if_buf, ptyibuf2); putf(if_buf, ptyibuf2);
munmap(if_buf, statbuf.st_size); munmap(if_buf, statbuf.st_size);
} }
close (if_fd);
} }
close (if_fd);
} }
if (pcc) if (pcc)