On Wed, 20 Jun 2012, Eitan Adler wrote:
Log:
Don't close an uninitialized descriptor. [1]
Add a sanity check for the validity of the passed fd.
Library functions shouldn't use assert() or abort().
The fd is not passed, but is a static variable under syslog()'s control.
In libc, only the following use assert.h:
- stdio/xprintf*.c. Very nonstd.
- rpc/*.c (perhaps not everything)
- db/*.c (but partly under DEBUG. Not the standard use where assert() is
controlled by NDEBUG)
- nameser/ns_print.c
- ia64/gen/unwind.c (but under SANITY. The standard NDEBUG is too hard to
use here too)
- gen/getgrent.c.
- regex/grot/main.c (test program. Not part of libc)
- regex/regex/utils.h (but ifdefed, and I think turned off in production.
Spencer knows how to use NDEBUG)
- regex/regcomp.c (ifdefed)
- include/isc/list.h
- net/*.c (just 2 files)
- posix1e/acl*.c (perhaps not everything)
- inet/inet_net_pton.c
- iconv/*.c (perhaps not everything).
The list was only short enough to be described by "only" in not very old
versions of FreeBSD. posix1e and iconv doubled the number of files.
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);
Since this assert() can't fail (unless the CPU has a parity error or
or the memory behind Logfile has a parity error or another memory error
or was clobbered by a buffer overrun), this assert() doesn't break the
library but just wastes space.
+ if (LogFile != -1) {
+ (void)_close(LogFile);
+ LogFile = -1;
+ }
LogTag = NULL;
status = NOCONN;
THREAD_UNLOCK();
Bruce
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"