Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 20 Jun 2012 06:38:42 +0000 (UTC)
From:      Eitan Adler <eadler@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r237286 - head/lib/libc/gen
Message-ID:  <201206200638.q5K6cg7u024024@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: eadler
Date: Wed Jun 20 06:38:41 2012
New Revision: 237286
URL: http://svn.freebsd.org/changeset/base/237286

Log:
  Don't close an uninitialized descriptor. [1]
  Add a sanity check for the validity of the passed fd.
  
  PR:		kern/139080 [1]
  Submitted by:	Andrey Simonenko <simon@comsys.ntu-kpi.kiev.ua> [1]
  Reviewed by:	pjd (briefly)
  Approved by:	cperciva
  MFC after:	1 week

Modified:
  head/lib/libc/gen/syslog.c

Modified: head/lib/libc/gen/syslog.c
==============================================================================
--- head/lib/libc/gen/syslog.c	Wed Jun 20 04:11:34 2012	(r237285)
+++ head/lib/libc/gen/syslog.c	Wed Jun 20 06:38:41 2012	(r237286)
@@ -41,6 +41,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/un.h>
 #include <netdb.h>
 
+#include <assert.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <paths.h>
@@ -413,8 +414,11 @@ void
 closelog(void)
 {
 	THREAD_LOCK();
-	(void)_close(LogFile);
-	LogFile = -1;
+	assert(LogFile >= -1);
+	if (LogFile != -1) {
+		(void)_close(LogFile);
+		LogFile = -1;
+	}
 	LogTag = NULL;
 	status = NOCONN;
 	THREAD_UNLOCK();



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