From: Noel Power Date: Fri, 5 Jul 2019 11:07:07 +0000 (+0000) Subject: s4/dsdb/common: clang: Fix 'Access results in a deref of a null pointer' X-Git-Tag: tdb-1.4.2~507 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=55f18757aae0f7fb137217e42ced6e2e08bfbfa2;p=thirdparty%2Fsamba.git s4/dsdb/common: clang: Fix 'Access results in a deref of a null pointer' 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 Reviewed-by: Gary Lockyer --- diff --git a/source4/dsdb/common/util.c b/source4/dsdb/common/util.c index 7e6b5b490d1..13354384f09 100644 --- a/source4/dsdb/common/util.c +++ b/source4/dsdb/common/util.c @@ -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],