samdb: Fix CID 1034910 Dereference before null check
authorVolker Lendecke <vl@samba.org>
Sun, 18 Aug 2013 19:37:56 +0000 (19:37 +0000)
committerAndrew Bartlett <abartlet@samba.org>
Sun, 18 Aug 2013 23:08:21 +0000 (11:08 +1200)
strncmp("tdb://", sam_name, 6) dereferences sam_name. Check for
NULL before that.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source4/dsdb/samdb/ldb_modules/partition_metadata.c

index 5826ac2ee1128ede0f89914f9d7e5b6af22e5822..c67d6cf18f85316a8e76cef5954aae3dab5c35e5 100644 (file)
@@ -199,13 +199,13 @@ static int partition_metadata_open(struct ldb_module *module, bool create)
        }
 
        sam_name = (const char *)ldb_get_opaque(ldb, "ldb_url");
-       if (strncmp("tdb://", sam_name, 6) == 0) {
-               sam_name += 6;
-       }
        if (!sam_name) {
                talloc_free(tmp_ctx);
                return ldb_operr(ldb);
        }
+       if (strncmp("tdb://", sam_name, 6) == 0) {
+               sam_name += 6;
+       }
        filename = talloc_asprintf(tmp_ctx, "%s.d/metadata.tdb", sam_name);
        if (!filename) {
                talloc_free(tmp_ctx);