[icinga-checkins] icinga.org: icinga-core/tdressler/ido: idoutils: replace direct write with vfprintf with gnu vasprint/fprintf, which take care about null pointer arguments causing SEGV in Solaris #2271

git at icinga.org git at icinga.org
Fri Feb 3 21:00:57 CET 2012


Module: icinga-core
Branch: tdressler/ido
Commit: 2256b95874b5eead76b7aef2a68d9f7b90858a68
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=2256b95874b5eead76b7aef2a68d9f7b90858a68

Author: Thomas Dressler <tdressler at tdressler.net>
Date:   Fri Feb  3 20:32:51 2012 +0100

idoutils: replace direct write with vfprintf with gnu vasprint/fprintf, which take care about null pointer arguments causing SEGV in Solaris #2271
refs #2271

---

 module/idoutils/src/logging.c |   16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/module/idoutils/src/logging.c b/module/idoutils/src/logging.c
index 0ce3bdc..4d8e747 100644
--- a/module/idoutils/src/logging.c
+++ b/module/idoutils/src/logging.c
@@ -68,11 +68,13 @@ int ido2db_close_debug_log(void) {
 int ido2db_log_debug_info(int level, int verbosity, const char *fmt, ...) {
         va_list ap;
         char *temp_path = NULL;
+		char *buf=NULL;
         time_t t;
         struct tm *tm;
         char temp_time[80];
         struct timeval current_time;
         unsigned long tid;
+        unsigned long pid;
 
         if (!(ido2db_debug_level == IDO2DB_DEBUGL_ALL || (level & ido2db_debug_level)))
                 return IDO_OK;
@@ -89,16 +91,22 @@ int ido2db_log_debug_info(int level, int verbosity, const char *fmt, ...) {
         time(&t);
         tm=localtime(&t);
         strftime(temp_time, 80, "%c", tm);
-        tid=(unsigned long)pthread_self();
+        tid=pthread_self();
+        pid=getpid();
 	if (ido2db_debug_readable_timestamp)
-	        fprintf(ido2db_debug_file_fp, "%s .%06lu [%03d.%d] [pid=%lu] [tid=%lu] ", temp_time, current_time.tv_usec, level, verbosity, (unsigned long)getpid(), tid);
+	        fprintf(ido2db_debug_file_fp, "%s .%06lu [%03d.%d] [pid=%lu] [tid=%lu] ", temp_time, current_time.tv_usec, level, verbosity, pid, tid);
 	else
-        	fprintf(ido2db_debug_file_fp, "[%lu.%06lu] [%03d.%d] [pid=%lu] [tid=%lu] ", current_time.tv_sec, current_time.tv_usec, level, verbosity, (unsigned long)getpid(), tid);
+        	fprintf(ido2db_debug_file_fp, "[%lu.%06lu] [%03d.%d] [pid=%lu] [tid=%lu] ", current_time.tv_sec, current_time.tv_usec, level, verbosity, pid, tid);
 
         /* write the data */
         va_start(ap, fmt);
-        vfprintf(ido2db_debug_file_fp, fmt, ap);
+		/* use gnu asprintf to take care about null pointer data*/
+        vasprintf(&buf, fmt, ap);
         va_end(ap);
+		if (buf) {
+        	fprintf(ido2db_debug_file_fp, "%s", buf);
+			my_free(buf);
+		}
 
         /* flush, so we don't have problems tailing or when fork()ing */
         fflush(ido2db_debug_file_fp);





More information about the icinga-checkins mailing list