summaryrefslogtreecommitdiffstats
path: root/lib/libc
diff options
context:
space:
mode:
authoreadler <eadler@FreeBSD.org>2012-06-20 06:38:41 +0000
committereadler <eadler@FreeBSD.org>2012-06-20 06:38:41 +0000
commit558058eeda08eb663675cf704d3cb281dfd2f2bc (patch)
tree4f5562293191429097e8c125377ca5e798f6e29a /lib/libc
parent8cc89048d427827afa803b515443badf6afd5387 (diff)
downloadFreeBSD-src-558058eeda08eb663675cf704d3cb281dfd2f2bc.zip
FreeBSD-src-558058eeda08eb663675cf704d3cb281dfd2f2bc.tar.gz
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
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/gen/syslog.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/libc/gen/syslog.c b/lib/libc/gen/syslog.c
index de438c4..52a0782 100644
--- a/lib/libc/gen/syslog.c
+++ b/lib/libc/gen/syslog.c
@@ -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();
OpenPOWER on IntegriCloud