X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=blobdiff_plain;f=errlog.c;h=559069daec28c4f6a1cc848de661c77231b4a987;hp=f493ac6ec9af26ee19f88dfa3b6e364456f00c6e;hb=b214b7e9487464b29ac6ec6c8c3ce12cdc4b5264;hpb=abcc2b0c1d0b912c66fc4241f943b602e30ce9b0 diff --git a/errlog.c b/errlog.c index f493ac6e..559069da 100644 --- a/errlog.c +++ b/errlog.c @@ -1,4 +1,4 @@ -const char errlog_rcs[] = "$Id: errlog.c,v 1.121 2014/06/03 10:24:00 fabiankeil Exp $"; +const char errlog_rcs[] = "$Id: errlog.c,v 1.129 2017/05/29 10:06:57 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/errlog.c,v $ @@ -245,6 +245,17 @@ void init_log_module(void) *********************************************************************/ void set_debug_level(int debug_level) { +#ifdef FUZZ + if (LOG_LEVEL_STFU == debug_level) + { + debug = LOG_LEVEL_STFU; + } + if (LOG_LEVEL_STFU == debug) + { + return; + } +#endif + debug = debug_level | LOG_LEVEL_MINIMUM; } @@ -421,12 +432,11 @@ static long get_thread_id(void) this_thread = (long)pthread_self(); #ifdef __MACH__ /* - * Mac OSX (and perhaps other Mach instances) doesn't have a debuggable - * value at the first 4 bytes of pthread_self()'s return value, a pthread_t. - * pthread_t is supposed to be opaque... but it's fairly random, though, so - * we make it mostly presentable. + * Mac OSX (and perhaps other Mach instances) doesn't have a unique + * value at the lowest order 4 bytes of pthread_self()'s return value, a pthread_t, + * so trim the three lowest-order bytes from the value (16^3). */ - this_thread = abs(this_thread % 1000); + this_thread = this_thread / 4096; #endif /* def __MACH__ */ #elif defined(_WIN32) this_thread = GetCurrentThreadId(); @@ -664,19 +674,13 @@ static inline const char *get_log_level_string(int loglevel) void log_error(int loglevel, const char *fmt, ...) { va_list ap; - char *outbuf = NULL; - static char *outbuf_save = NULL; + char outbuf[LOG_BUFFER_SIZE+1]; char tempbuf[LOG_BUFFER_SIZE]; size_t length = 0; const char * src = fmt; long thread_id; char timestamp[30]; - /* - * XXX: Make this a config option, - * why else do we allocate instead of using - * an array? - */ - size_t log_buffer_size = LOG_BUFFER_SIZE; + const size_t log_buffer_size = LOG_BUFFER_SIZE; #if defined(_WIN32) && !defined(_WIN_CONSOLE) /* @@ -701,6 +705,12 @@ void log_error(int loglevel, const char *fmt, ...) #endif ) { +#ifdef FUZZ + if (debug == LOG_LEVEL_STFU) + { + return; + } +#endif if (loglevel == LOG_LEVEL_FATAL) { fatal_error("Fatal error. You're not supposed to" @@ -712,28 +722,11 @@ void log_error(int loglevel, const char *fmt, ...) thread_id = get_thread_id(); get_log_timestamp(timestamp, sizeof(timestamp)); - /* protect the whole function because of the static buffer (outbuf) */ - lock_logfile(); - - if (NULL == outbuf_save) - { - outbuf_save = (char*)zalloc(log_buffer_size + 1); /* +1 for paranoia */ - if (NULL == outbuf_save) - { - snprintf(tempbuf, sizeof(tempbuf), - "%s %08lx Fatal error: Out of memory in log_error().", - timestamp, thread_id); - fatal_error(tempbuf); /* Exit */ - return; - } - } - outbuf = outbuf_save; - /* * Memsetting the whole buffer to zero (in theory) * makes things easier later on. */ - memset(outbuf, 0, log_buffer_size); + memset(outbuf, 0, sizeof(outbuf)); /* Add prefix for everything but Common Log Format messages */ if (loglevel != LOG_LEVEL_CLF) @@ -947,19 +940,21 @@ void log_error(int loglevel, const char *fmt, ...) assert(NULL != logfp); #endif + lock_logfile(); + if (loglevel == LOG_LEVEL_FATAL) { - fatal_error(outbuf_save); + fatal_error(outbuf); /* Never get here */ } if (logfp != NULL) { - fputs(outbuf_save, logfp); + fputs(outbuf, logfp); } #if defined(_WIN32) && !defined(_WIN_CONSOLE) /* Write to display */ - LogPutString(outbuf_save); + LogPutString(outbuf); #endif /* defined(_WIN32) && !defined(_WIN_CONSOLE) */ unlock_logfile();