--001a11c27ac2dcc7420509ced83c Content-Type: text/plain; charset=UTF-8
2014-12-09 18:57 GMT+03:00 Howard Chu hyc@symas.com:
leo@yuriev.ru wrote:
Full_Name: Leonid Yuriev Version: 2.4.40 OS: RHEL7 URL: ftp://ftp.openldap.org/incoming/ Submission from: (NULL) (31.130.36.33)
In some cases (presumably when a database contains more attributes than defined in the scheme) a heap error may be detected at stop of slapd.
Below is the result of attempts to find a bug(s) with Valgrind. It is enough to corrupt a malloc's heap!
Please provide a test case. Unable to reproduce this on a local database with commented out schema. I get:
violino:~/OD/o24/tests> valgrind ../servers/slapd/slapd -Tc -f /tmp/testr/slapd.1.conf > /tmp/out ==25499== Memcheck, a memory error detector ==25499== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al. ==25499== Using Valgrind-3.10.0.SVN and LibVEX; rerun with -h for copyright info ==25499== Command: ../servers/slapd/slapd -Tc -f /tmp/testr/slapd.1.conf ==25499== 54871b4f UNKNOWN attributeDescription "HOMEPOSTALADDRESS" inserted. 54871b4f UNKNOWN attributeDescription "DRINK" inserted. 54871b4f UNKNOWN attributeDescription "HOMEPHONE" inserted. 54871b4f UNKNOWN attributeDescription "PAGER" inserted. ==25499== ==25499== HEAP SUMMARY: ==25499== in use at exit: 2,746 bytes in 78 blocks ==25499== total heap usage: 10,335 allocs, 10,257 frees, 1,649,999 bytes allocated ==25499== ==25499== LEAK SUMMARY: ==25499== definitely lost: 0 bytes in 0 blocks ==25499== indirectly lost: 0 bytes in 0 blocks ==25499== possibly lost: 0 bytes in 0 blocks ==25499== still reachable: 2,746 bytes in 78 blocks ==25499== suppressed: 0 bytes in 0 blocks ==25499== Rerun with --leak-check=full to see details of leaked memory ==25499== ==25499== For counts of detected and suppressed errors, rerun with: -v ==25499== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
-- -- Howard Chu CTO, Symas Corp. http://www.symas.com Director, Highland Sun http://highlandsun.com/hyc/ Chief Architect, OpenLDAP http://www.openldap.org/project/
(1) Unfortunately it was reproduced only in production-like environment, therefore a testcase or complete info is not available yet.
(2) But let see to lines 570-575 of mdb-back/attr.c and lines 764-772 of slapd/ad.c: - does the mdb-value include a NUL byte = https://github.com/leo-yuriev/openldap-lmdb-challenge/blob/2.4-devel/servers... - if "YES" then "+1" at slapd/ad.c:764 is wrong = https://github.com/leo-yuriev/openldap-lmdb-challenge/blob/2.4-devel/servers... - but if "NO" then "strcpy()" at slapd/ad.c:772 (and more) is wrong = https://github.com/leo-yuriev/openldap-lmdb-challenge/blob/2.4-devel/servers...
(3) Next, I had added a couple of assert-check into mdb-back/attr.c and right away got "slapcat: attr.c:573: mdb_ad_read: Assertion `bdata.bv_val[bdata.bv_len-1] == 0' failed"
diff --git a/servers/slapd/back-mdb/attr.c b/servers/slapd/back-mdb/attr.c index 07b64a6..7979b9d 100644 --- a/servers/slapd/back-mdb/attr.c +++ b/servers/slapd/back-mdb/attr.c @@ -569,6 +569,8 @@ int mdb_ad_read( struct mdb_info *mdb, MDB_txn *txn ) while ( rc == MDB_SUCCESS ) { bdata.bv_len = data.mv_size; bdata.bv_val = data.mv_data; + assert(bdata.bv_len > 0); + assert(bdata.bv_val[bdata.bv_len-1] == 0); ad = NULL; rc = slap_bv2ad( &bdata, &ad, &text ); if ( rc ) {
(4) Ok, this is a off-by-one bug. Then I looked for "sizeof(AttributeDescription)" and has found only 3 places in slapd/ad.c ... and fix a few places of str-calls to n-form.
Patch is attached, please review it.
Leonid.
---
The attached files is derived from OpenLDAP Software. All of the modifications to OpenLDAP Software represented in the following patch(es) were developed by Peter-Service LLC, Moscow, Russia. Peter-Service LLC has not assigned rights and/or interest in this work to any party. I, Leonid Yuriev am authorized by Peter-Service LLC, my employer, to release this work under the following terms.
Peter-Service LLC hereby places the following modifications to OpenLDAP Software (and only these modifications) into the public domain. Hence, these modifications may be freely used and/or redistributed for any purpose with or without attribution and/or other notice.
--001a11c27ac2dcc7420509ced83c Content-Type: text/x-patch; charset=US-ASCII; name="its7995.patch" Content-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