unsigned indx_len = 0;
unsigned frmt_len = 0;
+ if (max_key_length < 4) {
+ ldb_asprintf_errstring(
+ ldb,
+ __location__ ": max_key_length of (%u) < 4",
+ max_key_length);
+ return NULL;
+ }
+ /*
+ * ltdb_key_dn() makes something 4 bytes longer, it adds a leading
+ * "DN=" and a trailing string terninator
+ */
+ max_key_length -= 4;
+
if (attr[0] == '@') {
attr_for_dn = attr;
v = *value;
if (should_b64_encode) {
unsigned vstr_len = 0;
char *vstr = ldb_base64_encode(ldb, (char *)v.data, v.length);
+ unsigned num_separators = 3;
if (!vstr) {
talloc_free(attr_folded);
return NULL;
}
vstr_len = strlen(vstr);
- key_len = 3 + indx_len + attr_len + vstr_len;
+ key_len = num_separators + indx_len + attr_len + vstr_len;
if (key_len > max_key_length) {
unsigned excess = key_len - max_key_length;
frmt_len = vstr_len - excess;
}
talloc_free(vstr);
} else {
- key_len = 2 + indx_len + attr_len + (int)v.length;
+ unsigned num_separators = 2;
+ key_len = num_separators + indx_len + attr_len + (int)v.length;
if (key_len > max_key_length) {
unsigned excess = key_len - max_key_length;
frmt_len = v.length - excess;
super(MaxIndexKeyLengthTests, self).setUp()
self.testdir = tempdir()
self.filename = os.path.join(self.testdir, "key_len_test.ldb")
- # Note that the maximum key length is set to 50
+ # Note that the maximum key length is set to 54
+ # This accounts for the 4 bytes added by the dn formatting
+ # a leading dn=, and a trailing zero terminator
+ #
self.l = ldb.Ldb(self.url(),
options=[
"modules:rdn_name",
- "max_key_len_for_self_test:50"])
+ "max_key_len_for_self_test:54"])
self.l.add({"dn": "@ATTRIBUTES",
"uniqueThing": "UNIQUE_INDEX"})
self.l.add({"dn": "@INDEXLIST",