Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 2 Mar 2014 03:34:07 +0000 (UTC)
From:      Marcel Moolenaar <marcel@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r262679 - head/contrib/telnet/telnetd
Message-ID:  <201403020334.s223Y7lG024966@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: marcel
Date: Sun Mar  2 03:34:06 2014
New Revision: 262679
URL: http://svnweb.freebsd.org/changeset/base/262679

Log:
  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@

Modified:
  head/contrib/telnet/telnetd/telnetd.c

Modified: head/contrib/telnet/telnetd/telnetd.c
==============================================================================
--- head/contrib/telnet/telnetd/telnetd.c	Sun Mar  2 02:52:34 2014	(r262678)
+++ head/contrib/telnet/telnetd/telnetd.c	Sun Mar  2 03:34:06 2014	(r262679)
@@ -926,14 +926,15 @@ telnet(int f, int p, char *host)
 	if (hostinfo && *IM)
 		putf(IM, ptyibuf2);
 	if (IF && if_fd != -1) {
-	    if(fstat (if_fd, &statbuf)!=-1) {
-		if (statbuf.st_size > 0) {
-		    if_buf = (char *) mmap (0, statbuf.st_size, PROT_READ, 0, if_fd, 0);
-		    putf(if_buf, ptyibuf2);
-		    munmap (if_buf, statbuf.st_size);
+		if (fstat(if_fd, &statbuf) != -1 && statbuf.st_size > 0) {
+			if_buf = (char *) mmap (0, statbuf.st_size,
+			    PROT_READ, 0, if_fd, 0);
+			if (if_buf != MAP_FAILED) {
+				putf(if_buf, ptyibuf2);
+				munmap(if_buf, statbuf.st_size);
+			}
 		}
 		close (if_fd);
-	    }
 	}
 
 	if (pcc)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201403020334.s223Y7lG024966>