From 558058eeda08eb663675cf704d3cb281dfd2f2bc Mon Sep 17 00:00:00 2001 From: eadler Date: Wed, 20 Jun 2012 06:38:41 +0000 Subject: 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 [1] Reviewed by: pjd (briefly) Approved by: cperciva MFC after: 1 week --- lib/libc/gen/syslog.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lib/libc/gen/syslog.c') 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 #include +#include #include #include #include @@ -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(); -- cgit v1.1