]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s4/dsdb/common: clang: Fix 'Access results in a deref of a null pointer'
authorNoel Power <noel.power@suse.com>
Fri, 5 Jul 2019 11:07:07 +0000 (11:07 +0000)
committerGary Lockyer <gary@samba.org>
Wed, 24 Jul 2019 04:19:27 +0000 (04:19 +0000)
Fixes:

source4/dsdb/common/util.c:2000:6: warning: Access to field 'count' results in a dereference of a null pointer (loaded from variable 'res') <--[clang]
        if (res->count != 1) {
            ^~~

source4/dsdb/common/util.c:3281:28: warning: Access to field 'msgs' results in a dereference of a null pointer (loaded from variable 'res') <--[clang]
        el = ldb_msg_find_element(res->msgs[0], attr);
                                  ^~~
source4/dsdb/common/util.c:3568:6: warning: Access to field 'count' results in a dereference of a null pointer (loaded from variable 'res') <--[clang]
        if (res->count != 1 || ret != LDB_SUCCESS) {
            ^~~

Signed-off-by: Noel Power <noel.power@suse.com>
Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
source4/dsdb/common/util.c

index 7e6b5b490d16ccec3f6c40e525dea5a3ebe67749..13354384f09e24cea3946f11267e28ccbae49943 100644 (file)
@@ -1997,6 +1997,11 @@ int samdb_search_for_parent_domain(struct ldb_context *ldb, TALLOC_CTX *mem_ctx,
                talloc_free(local_ctx);
                return ret;
        }
+       /* should never be true with 'ret=LDB_SUCCESS', here to satisfy clang */
+       if (res == NULL) {
+               talloc_free(local_ctx);
+               return LDB_ERR_OTHER;
+       }
        if (res->count != 1) {
                *errstring = talloc_asprintf(mem_ctx, "Invalid dn (%s), not child of a domain object",
                                             ldb_dn_get_linearized(dn));
@@ -3278,6 +3283,11 @@ WERROR dsdb_loadreps(struct ldb_context *sam_ctx, TALLOC_CTX *mem_ctx, struct ld
                return WERR_DS_DRA_INTERNAL_ERROR;
        }
 
+       /* satisfy clang */
+       if (res == NULL) {
+               talloc_free(tmp_ctx);
+               return WERR_DS_DRA_INTERNAL_ERROR;
+       }
        el = ldb_msg_find_element(res->msgs[0], attr);
        if (el == NULL) {
                /* it's OK to be empty */
@@ -3571,6 +3581,11 @@ int samdb_dns_host_name(struct ldb_context *sam_ctx, const char **host_name)
                TALLOC_FREE(tmp_ctx);
                return ret;
        }
+       /* satisfy clang */
+       if (res == NULL) {
+               TALLOC_FREE(tmp_ctx);
+               return LDB_ERR_OTHER;
+       }
 
 
        _host_name = ldb_msg_find_attr_as_string(res->msgs[0],