Sophie

Sophie

distrib > Mageia > 6 > armv7hl > media > core-updates-src > by-pkgid > d24ffec3cfdeebd5a98cb7f97f617355 > files > 10

389-ds-base-1.3.5.17-1.6.mga6.src.rpm

From 8ff8cb850be8a93f75aa3007ee2131c026f4962b Mon Sep 17 00:00:00 2001
From: Mark Reynolds <mreynolds@redhat.com>
Date: Sep 05 2018 18:10:42 +0000
Subject: Ticket 49937 - Log buffer exceeded emergency logging msg is not thread-safe


Bug Description:  Multiple operations making modificatiosn on a DN
                  that is very large can crash the server, because
                  when we do emergency logging, we close and reopen
                  the errors log withgout hold the error log write
                  lock.  This causes the FD pointer to be become
                  invalid and triggers a crash.

Fix description:  Hold the errors log write lock while closing and
                  reopening the log

https://pagure.io/389-ds-base/issue/49937

Reviewed by: vashirov(Thanks!)

---

diff --git a/ldap/servers/slapd/log.c b/ldap/servers/slapd/log.c
index 2e4ee03..7dd7154 100644
--- a/ldap/servers/slapd/log.c
+++ b/ldap/servers/slapd/log.c
@@ -2191,11 +2191,11 @@
     if (logging_hr_timestamps_enabled == 1) {
         struct timespec tsnow;
         if (clock_gettime(CLOCK_REALTIME, &tsnow) != 0) {
-            syslog(LOG_CRIT, "CRITICAL: vslapd_log_emergency_error, Unable to determine system time for message :: %s", msg);
+            syslog(LOG_CRIT, "CRITICAL: vslapd_log_emergency_error, Unable to determine system time for message :: %s\n", msg);
             return;
         }
         if (format_localTime_hr_log(tsnow.tv_sec, tsnow.tv_nsec, sizeof(tbuf), tbuf, &size) != 0) {
-            syslog(LOG_CRIT, "CRITICAL: vslapd_log_emergency_error, Unable to format system time for message :: %s", msg);
+            syslog(LOG_CRIT, "CRITICAL: vslapd_log_emergency_error, Unable to format system time for message :: %s\n", msg);
             return;
         }
     } else {
@@ -2203,14 +2203,14 @@
         time_t    tnl;
         tnl = current_time();
         if (format_localTime_log(tnl, sizeof(tbuf), tbuf, &size) != 0) {
-            syslog(LOG_CRIT, "CRITICAL: vslapd_log_emergency_error, Unable to format system time for message :: %s", msg);
+            syslog(LOG_CRIT, "CRITICAL: vslapd_log_emergency_error, Unable to format system time for message :: %s\n", msg);
             return;
         }
 #ifdef HAVE_CLOCK_GETTIME
     }
 #endif
 
-    PR_snprintf( buffer, sizeof(buffer), "%s - %s", tbuf, msg);
+    PR_snprintf( buffer, sizeof(buffer), "%s - %s\n", tbuf, msg);
     size = strlen(buffer);
 
     if(!locked) {
@@ -2456,7 +2456,7 @@
 
     if (SLAPI_LOG_BUFSIZ - blen < vlen) {
         /* We won't be able to fit the message in! Uh-oh! */
-        /* Should we actually just do the snprintf, and warn that message was trunced? */
+        /* Should we actually just do the snprintf, and warn that message was truncated? */
         log__error_emergency("Insufficent buffer capacity to fit timestamp and message!", 1 ,0);
         return -1;
     }
@@ -4363,6 +4363,13 @@
 	if (!reopen) {
 		return;
 	}
+	if (!locked) {
+	    /*
+	     * Take the lock because we are closing and reopening the error log (fd),
+	     * and we don't want any other threads trying to use this fd
+	     */
+	    LOG_ERROR_LOCK_WRITE();
+	}
 	if (NULL != loginfo.log_error_fdes) {
 		LOG_CLOSE(loginfo.log_error_fdes);
 	}
@@ -4371,7 +4378,10 @@
 		PRErrorCode prerr = PR_GetError();
 		syslog(LOG_ERR, "Failed to reopen errors log file, " SLAPI_COMPONENT_NAME_NSPR " error %d (%s)\n", prerr, slapd_pr_strerror(prerr));
 	} else {
-		vslapd_log_emergency_error(loginfo.log_error_fdes, errstr, locked);
+		vslapd_log_emergency_error(loginfo.log_error_fdes, errstr, 1 /* locked */);
+	}
+	if (!locked) {
+	    LOG_ERROR_UNLOCK_WRITE();
 	}
 	return;
 }