|
|
6f51e1 |
From df5000efced2d00aa0fc6546fcf6fc7b02e27256 Mon Sep 17 00:00:00 2001
|
|
|
6f51e1 |
From: Mark Reynolds <mreynolds@redhat.com>
|
|
|
6f51e1 |
Date: Mon, 6 Nov 2017 22:30:55 -0500
|
|
|
6f51e1 |
Subject: [PATCH] Ticket 49441 - Import crashes with large indexed binary
|
|
|
6f51e1 |
attributes
|
|
|
6f51e1 |
|
|
|
6f51e1 |
Bug Description: Importing an ldif file that contains entries with large
|
|
|
6f51e1 |
binary attributes that are indexed crashes the server.
|
|
|
6f51e1 |
The crash occurs when "encoding" the binary value to a
|
|
|
6f51e1 |
string for debug logging, where we "underflow" the buffer
|
|
|
6f51e1 |
space index which then allows the string buffer to overflow.
|
|
|
6f51e1 |
|
|
|
6f51e1 |
Fix Description: While filling the string buffer with the encoded binary
|
|
|
6f51e1 |
value we need to make sure if the buffer space is greater
|
|
|
6f51e1 |
than zero before decrementing it.
|
|
|
6f51e1 |
|
|
|
6f51e1 |
Also check if trace logging is being used before we actually
|
|
|
6f51e1 |
call the logging function which calls the "encoded" function
|
|
|
6f51e1 |
first. This way we avoid this costly "encoding" on every
|
|
|
6f51e1 |
index call we make.
|
|
|
6f51e1 |
|
|
|
6f51e1 |
https://pagure.io/389-ds-base/issue/49441
|
|
|
6f51e1 |
|
|
|
6f51e1 |
Reviewed by: firstyear(Thanks!)
|
|
|
6f51e1 |
---
|
|
|
6f51e1 |
ldap/servers/slapd/back-ldbm/index.c | 21 ++++++++++-----------
|
|
|
6f51e1 |
1 file changed, 10 insertions(+), 11 deletions(-)
|
|
|
6f51e1 |
|
|
|
6f51e1 |
diff --git a/ldap/servers/slapd/back-ldbm/index.c b/ldap/servers/slapd/back-ldbm/index.c
|
|
|
6f51e1 |
index d4de28ca3..d62052a22 100644
|
|
|
6f51e1 |
--- a/ldap/servers/slapd/back-ldbm/index.c
|
|
|
6f51e1 |
+++ b/ldap/servers/slapd/back-ldbm/index.c
|
|
|
6f51e1 |
@@ -808,7 +808,10 @@ encode (const struct berval* data, char buf[BUFSIZ])
|
|
|
6f51e1 |
bufSpace -= (s - first);
|
|
|
6f51e1 |
}
|
|
|
6f51e1 |
do {
|
|
|
6f51e1 |
- *bufNext++ = '\\'; --bufSpace;
|
|
|
6f51e1 |
+ if (bufSpace) {
|
|
|
6f51e1 |
+ *bufNext++ = '\\';
|
|
|
6f51e1 |
+ --bufSpace;
|
|
|
6f51e1 |
+ }
|
|
|
6f51e1 |
if (bufSpace < 2) {
|
|
|
6f51e1 |
memcpy (bufNext, "..", 2);
|
|
|
6f51e1 |
bufNext += 2;
|
|
|
6f51e1 |
@@ -903,8 +906,10 @@ index_read_ext_allids(
|
|
|
6f51e1 |
slapi_log_err(SLAPI_LOG_ERR, "index_read_ext_allids", "NULL prefix\n");
|
|
|
6f51e1 |
return NULL;
|
|
|
6f51e1 |
}
|
|
|
6f51e1 |
- slapi_log_err(SLAPI_LOG_TRACE, "index_read_ext_allids", "=> ( \"%s\" %s \"%s\" )\n",
|
|
|
6f51e1 |
- type, prefix, encode (val, buf));
|
|
|
6f51e1 |
+ if (slapi_is_loglevel_set(LDAP_DEBUG_TRACE)) {
|
|
|
6f51e1 |
+ slapi_log_err(SLAPI_LOG_TRACE, "index_read_ext_allids", "=> ( \"%s\" %s \"%s\" )\n",
|
|
|
6f51e1 |
+ type, prefix, encode (val, buf));
|
|
|
6f51e1 |
+ }
|
|
|
6f51e1 |
|
|
|
6f51e1 |
basetype = typebuf;
|
|
|
6f51e1 |
if ( (basetmp = slapi_attr_basetype( type, typebuf, sizeof(typebuf) ))
|
|
|
6f51e1 |
@@ -1737,16 +1742,13 @@ addordel_values(
|
|
|
6f51e1 |
*/
|
|
|
6f51e1 |
key.flags = DB_DBT_USERMEM;
|
|
|
6f51e1 |
key.ulen = tmpbuflen;
|
|
|
6f51e1 |
-#ifdef LDAP_ERROR_LOGGING
|
|
|
6f51e1 |
- /* XXX if ( slapd_ldap_debug & LDAP_DEBUG_TRACE ) XXX */
|
|
|
6f51e1 |
- {
|
|
|
6f51e1 |
+ if (slapi_is_loglevel_set(LDAP_DEBUG_TRACE)) {
|
|
|
6f51e1 |
char encbuf[BUFSIZ];
|
|
|
6f51e1 |
|
|
|
6f51e1 |
slapi_log_err(SLAPI_LOG_TRACE, "addordel_values", "%s_value(\"%s\")\n",
|
|
|
6f51e1 |
(flags & BE_INDEX_ADD) ? "add" : "del",
|
|
|
6f51e1 |
encoded (&key, encbuf));
|
|
|
6f51e1 |
}
|
|
|
6f51e1 |
-#endif
|
|
|
6f51e1 |
|
|
|
6f51e1 |
if (NULL != txn) {
|
|
|
6f51e1 |
db_txn = txn->back_txn_txn;
|
|
|
6f51e1 |
@@ -1907,16 +1909,13 @@ addordel_values_sv(
|
|
|
6f51e1 |
*/
|
|
|
6f51e1 |
key.flags = DB_DBT_USERMEM;
|
|
|
6f51e1 |
key.ulen = tmpbuflen;
|
|
|
6f51e1 |
-#ifdef LDAP_ERROR_LOGGING
|
|
|
6f51e1 |
- /* XXX if ( slapd_ldap_debug & LDAP_DEBUG_TRACE ) XXX */
|
|
|
6f51e1 |
- {
|
|
|
6f51e1 |
+ if (slapi_is_loglevel_set(LDAP_DEBUG_TRACE)) {
|
|
|
6f51e1 |
char encbuf[BUFSIZ];
|
|
|
6f51e1 |
|
|
|
6f51e1 |
slapi_log_err(SLAPI_LOG_TRACE, "addordel_values_sv", "%s_value(\"%s\")\n",
|
|
|
6f51e1 |
(flags & BE_INDEX_ADD) ? "add" : "del",
|
|
|
6f51e1 |
encoded (&key, encbuf));
|
|
|
6f51e1 |
}
|
|
|
6f51e1 |
-#endif
|
|
|
6f51e1 |
|
|
|
6f51e1 |
if (NULL != txn) {
|
|
|
6f51e1 |
db_txn = txn->back_txn_txn;
|
|
|
6f51e1 |
--
|
|
|
6f51e1 |
2.13.6
|
|
|
6f51e1 |
|