ldb_compre_base - can you clarify this test?

simo idra at samba.org
Wed Oct 29 12:20:45 GMT 2008


On Wed, 2008-10-29 at 23:14 +1100, Andrew Bartlett wrote:
> On Wed, 2008-10-29 at 07:57 -0400, simo wrote:
> > On Wed, 2008-10-29 at 13:46 +1100, Andrew Bartlett wrote:
> > > In this function, from ldb_dn.c, I'm concerned about the use of strlen():
> > > 
> > > int ldb_dn_compare_base(struct ldb_dn *base, struct ldb_dn *dn)
> > > {
> > > 	int ret;
> > > 	int n_base, n_dn;
> > > 
> > > 	if ( ! base || base->invalid) return 1;
> > > 	if ( ! dn || dn->invalid) return -1;
> > > 
> > > 	if (( ! base->valid_case) || ( ! dn->valid_case)) {
> > > 		if (base->linearized && dn->linearized) {
> > > 			/* try with a normal compare first, if we are lucky
> > > 			 * we will avoid exploding and casfolding */
> > > 			int dif;
> > > 			dif = strlen(dn->linearized) - strlen(base->linearized);
> > > 			if (dif < 0) return dif;
> > > 			if (strcmp(base->linearized, &dn->linearized[dif]) == 0) return 0;
> > > 		}
> > > 
> > > Firstly, it is my understanding that there are some (annoying)
> > > characters are longer when upper cased.  Secondly, could dn->liniarized
> > > contain escaped characters?
> > > 
> > > If either of these are true, is it valid to do the comparisons like this?
> > 
> > linearized strings are also canonicalized (As you see later on there is
> > a straight strcmp), there is no problem in doing a length comparison.
> 
> How so?  ldb_dn_new() sets the linearized string directly.  I have not
> yet found the function that does the canonicalization.  

Oh, you are right,
I forgot the casefolded string in in dn->casfold not in dn->linearized.
That length check is a bug indeed, I'll remove that optimization.

Thanks for spotting it.

Simo.

-- 
Simo Sorce
Samba Team GPL Compliance Officer <simo at samba.org>
Senior Software Engineer at Red Hat Inc. <simo at redhat.com>



More information about the samba-technical mailing list