r8517: fixed a crash bug in ldb_dn_compare_base()
authorAndrew Tridgell <tridge@samba.org>
Sun, 17 Jul 2005 09:06:58 +0000 (09:06 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:29:34 +0000 (13:29 -0500)
(This used to be commit 19d789e82526eff236aeed77ddc8d2606c5118b6)

source4/lib/ldb/common/ldb_dn.c

index 3cdc7ba85f815c0e78572d08dfa7b6bb7ab78459..edb5124d99d950aff2f2d2bf74ce5c102c673687 100644 (file)
@@ -412,13 +412,13 @@ int ldb_dn_compare_base(struct ldb_context *ldb,
                   const struct ldb_dn *base,
                   const struct ldb_dn *dn)
 {
-       int i, ret;
+       int ret;
        int n0, n1;
 
        /* if the number of components doesn't match they differ */
        n0 = base->comp_num - 1;
        n1 = dn->comp_num - 1;
-       for (i = 0; i < base->comp_num; i++, n0--, n1--) {
+       while (n0 >= 0 && n1 >= 0) {
                const struct ldb_attrib_handler *h;
 
                /* compare names (attribute names are guaranteed to be ASCII only) */
@@ -435,6 +435,8 @@ int ldb_dn_compare_base(struct ldb_context *ldb,
                if (ret) {
                        return ret;
                }
+               n1--;
+               n0--;
        }
 
        return 0;