summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/common/attrib_handlers.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2008-08-22 17:36:56 +1000
committerAndrew Tridgell <tridge@samba.org>2008-08-22 17:36:56 +1000
commitcc43037f19056ed24d7fffa54456d597c63ad105 (patch)
treee2ae68e4cd85eab35e9a55fa44726e1cb78895b0 /source4/lib/ldb/common/attrib_handlers.c
parenta83bb07016032bd29e36c8de5a3205bbe318167e (diff)
downloadsamba-cc43037f19056ed24d7fffa54456d597c63ad105.tar.gz
samba-cc43037f19056ed24d7fffa54456d597c63ad105.tar.bz2
samba-cc43037f19056ed24d7fffa54456d597c63ad105.zip
fixed a problem with length limited ldap values
The core ldb code for string matching assumed NULL terminated strings, whereas the anr module used data_blob_const() to effectively truncate a ldb_val by changing its length. The ldb code is supposed to be based around length limited blobs, not NULL terminated strings, so the correct fix was to change the string comparison functions to be length limited (This used to be commit 26c6aa5a80ffaf06fc33f30a6533f8f16ef538bc)
Diffstat (limited to 'source4/lib/ldb/common/attrib_handlers.c')
-rw-r--r--source4/lib/ldb/common/attrib_handlers.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/source4/lib/ldb/common/attrib_handlers.c b/source4/lib/ldb/common/attrib_handlers.c
index 8ed2763d4d..fb57e2dadc 100644
--- a/source4/lib/ldb/common/attrib_handlers.c
+++ b/source4/lib/ldb/common/attrib_handlers.c
@@ -55,11 +55,12 @@ int ldb_handler_fold(struct ldb_context *ldb, void *mem_ctx,
{
char *s, *t;
int l;
+
if (!in || !out || !(in->data)) {
return -1;
}
- out->data = (uint8_t *)ldb_casefold(ldb, mem_ctx, (const char *)(in->data));
+ out->data = (uint8_t *)ldb_casefold(ldb, mem_ctx, (const char *)(in->data), in->length);
if (out->data == NULL) {
ldb_debug(ldb, LDB_DEBUG_ERROR, "ldb_handler_fold: unable to casefold string [%s]", in->data);
return -1;
@@ -153,13 +154,14 @@ int ldb_comparison_fold(struct ldb_context *ldb, void *mem_ctx,
const struct ldb_val *v1, const struct ldb_val *v2)
{
const char *s1=(const char *)v1->data, *s2=(const char *)v2->data;
+ size_t n1 = v1->length, n2 = v2->length;
const char *u1, *u2;
char *b1, *b2;
int ret;
- while (*s1 == ' ') s1++;
- while (*s2 == ' ') s2++;
+ while (*s1 == ' ' && n1) { s1++; n1--; };
+ while (*s2 == ' ' && n2) { s2++; n2--; };
/* TODO: make utf8 safe, possibly with helper function from application */
- while (*s1 && *s2) {
+ while (*s1 && *s2 && n1 && n2) {
/* the first 127 (0x7F) chars are ascii and utf8 guarantes they
* never appear in multibyte sequences */
if (((unsigned char)s1[0]) & 0x80) goto utf8str;
@@ -167,10 +169,11 @@ int ldb_comparison_fold(struct ldb_context *ldb, void *mem_ctx,
if (toupper((unsigned char)*s1) != toupper((unsigned char)*s2))
break;
if (*s1 == ' ') {
- while (s1[0] == s1[1]) s1++;
- while (s2[0] == s2[1]) s2++;
+ while (s1[0] == s1[1] && n1) { s1++; n1--; }
+ while (s2[0] == s2[1] && n2) { s2++; n2--; }
}
s1++; s2++;
+ n1--; n2--;
}
if (! (*s1 && *s2)) {
/* check for trailing spaces only if one of the pointers
@@ -178,15 +181,18 @@ int ldb_comparison_fold(struct ldb_context *ldb, void *mem_ctx,
* can mistakenly match.
* ex. "domain users" <-> "domainUpdates"
*/
- while (*s1 == ' ') s1++;
- while (*s2 == ' ') s2++;
+ while (*s1 == ' ') { s1++; n1--; }
+ while (*s2 == ' ') { s2++; n2--; }
+ }
+ if (n1 != n2) {
+ return n1 - n2;
}
return (int)(toupper(*s1)) - (int)(toupper(*s2));
utf8str:
/* no need to recheck from the start, just from the first utf8 char found */
- b1 = ldb_casefold(ldb, mem_ctx, s1);
- b2 = ldb_casefold(ldb, mem_ctx, s2);
+ b1 = ldb_casefold(ldb, mem_ctx, s1, n1);
+ b2 = ldb_casefold(ldb, mem_ctx, s2, n2);
if (b1 && b2) {
/* Both strings converted correctly */
@@ -221,6 +227,7 @@ utf8str:
return ret;
}
+
/*
canonicalise a attribute in DN format
*/