]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s4:dsdb: Access correct member of union
authorJoseph Sutton <josephsutton@catalyst.net.nz>
Wed, 2 Aug 2023 03:32:05 +0000 (15:32 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 14 Aug 2023 04:57:34 +0000 (04:57 +0000)
Accessing the wrong member of a union invokes undefined behaviour.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source4/dsdb/common/util.c
source4/dsdb/samdb/ldb_modules/acl_read.c
source4/dsdb/samdb/ldb_modules/anr.c
source4/dsdb/samdb/ldb_modules/operational.c
source4/dsdb/samdb/ldb_modules/resolve_oids.c

index e32f4750cf5d26c7f0629e8b67b71f2b33337286..5e0bccb36b0a09343a096abe41cfe2e59aac8956 100644 (file)
@@ -5902,10 +5902,14 @@ bool dsdb_attr_in_parse_tree(struct ldb_parse_tree *tree,
        case LDB_OP_NOT:
                return dsdb_attr_in_parse_tree(tree->u.isnot.child, attr);
        case LDB_OP_EQUALITY:
+               if (ldb_attr_cmp(tree->u.equality.attr, attr) == 0) {
+                       return true;
+               }
+               return false;
        case LDB_OP_GREATER:
        case LDB_OP_LESS:
        case LDB_OP_APPROX:
-               if (ldb_attr_cmp(tree->u.equality.attr, attr) == 0) {
+               if (ldb_attr_cmp(tree->u.comparison.attr, attr) == 0) {
                        return true;
                }
                return false;
index e82af68c3124fa0c63264be5b51ff71c5c588c2b..0b6280c3a8f69b17a5f64f4f52e079ef448c7221 100644 (file)
@@ -252,18 +252,27 @@ static int ldb_parse_tree_collect_acl_attrs(const struct ldb_module *module,
                        return 0;
                }
 
-               FALL_THROUGH;
-       case LDB_OP_EQUALITY:
                if (ldb_attr_always_visible(tree->u.present.attr)) {
                        /* No need to check this attribute. */
                        return 0;
                }
 
-               FALL_THROUGH;
+               break;
+
+       case LDB_OP_EQUALITY:
+               if (ldb_attr_always_visible(tree->u.equality.attr)) {
+                       /* No need to check this attribute. */
+                       return 0;
+               }
+
+               break;
+
        default:                        /* single attribute in tree */
-               attr = ldb_parse_tree_get_attr(tree);
-               return attr_vec_add_unique(mem_ctx, attrs, attr);
+               break;
        }
+
+       attr = ldb_parse_tree_get_attr(tree);
+       return attr_vec_add_unique(mem_ctx, attrs, attr);
 }
 
 /*
index 63aafa020430502410b886795cff9fc98cc92e19..d0cdaa3ddb8ff3fb68d1cfe7b6de6e5078781960 100644 (file)
@@ -296,10 +296,14 @@ static int parse_tree_anr_present(struct ldb_parse_tree *tree, void *private_con
        struct anr_present_ctx *ctx = private_context;
        switch (tree->operation) {
        case LDB_OP_EQUALITY:
+               if (ldb_attr_cmp(tree->u.equality.attr, ctx->attr) == 0) {
+                       ctx->found_anr = true;
+               }
+               break;
        case LDB_OP_GREATER:
        case LDB_OP_LESS:
        case LDB_OP_APPROX:
-               if (ldb_attr_cmp(tree->u.equality.attr, ctx->attr) == 0) {
+               if (ldb_attr_cmp(tree->u.comparison.attr, ctx->attr) == 0) {
                        ctx->found_anr = true;
                }
                break;
index bfde14db1a3ab7c0a0a79097e680d6e71c83d2e3..d7c40c82efcc59012927c70a7938387ef5b58135 100644 (file)
@@ -1696,10 +1696,14 @@ static int operational_present(struct ldb_parse_tree *tree, void *private_contex
        struct operational_present_ctx *ctx = private_context;
        switch (tree->operation) {
        case LDB_OP_EQUALITY:
+               if (ldb_attr_cmp(tree->u.equality.attr, ctx->attr) == 0) {
+                       ctx->found_operational = true;
+               }
+               break;
        case LDB_OP_GREATER:
        case LDB_OP_LESS:
        case LDB_OP_APPROX:
-               if (ldb_attr_cmp(tree->u.equality.attr, ctx->attr) == 0) {
+               if (ldb_attr_cmp(tree->u.comparison.attr, ctx->attr) == 0) {
                        ctx->found_operational = true;
                }
                break;
index b5c5f8efee7ddb911bb2ac7c66868b92841bec89..5c1639671e59d08b077f539f290fa121395df142 100644 (file)
@@ -111,11 +111,14 @@ static int resolve_oids_parse_tree_need(struct ldb_context *ldb,
                return resolve_oids_parse_tree_need(ldb, schema,
                                                tree->u.isnot.child);
        case LDB_OP_EQUALITY:
+               attr = tree->u.equality.attr;
+               valp = &tree->u.equality.value;
+               break;
        case LDB_OP_GREATER:
        case LDB_OP_LESS:
        case LDB_OP_APPROX:
-               attr = tree->u.equality.attr;
-               valp = &tree->u.equality.value;
+               attr = tree->u.comparison.attr;
+               valp = &tree->u.comparison.value;
                break;
        case LDB_OP_SUBSTRING:
                attr = tree->u.substring.attr;
@@ -300,11 +303,14 @@ static int resolve_oids_parse_tree_replace(struct ldb_context *ldb,
                return resolve_oids_parse_tree_replace(ldb, schema,
                                                tree->u.isnot.child);
        case LDB_OP_EQUALITY:
+               attrp = &tree->u.equality.attr;
+               valp = &tree->u.equality.value;
+               break;
        case LDB_OP_GREATER:
        case LDB_OP_LESS:
        case LDB_OP_APPROX:
-               attrp = &tree->u.equality.attr;
-               valp = &tree->u.equality.value;
+               attrp = &tree->u.comparison.attr;
+               valp = &tree->u.comparison.value;
                break;
        case LDB_OP_SUBSTRING:
                attrp = &tree->u.substring.attr;