lib/hdb: hdb_create consistently check cb_ctx.h

instead of testing both cb_ctx.h and cb_ctx.h->prefix
for non-NULL, ensure that cb_ctx.h is NULL after each
failed for() loop.  This also ensures that cb_ctx.h
is never left pointing to an invalid non-NULL value.

Change-Id: I3264577b0fbf1d620b00f87d251e8c43b81e0f29
This commit is contained in:
Jeffrey Altman
2022-01-23 21:27:56 -05:00
parent 38536d7313
commit e0e61d2b91

View File

@@ -795,9 +795,11 @@ hdb_create(krb5_context context, HDB **db, const char *filename)
(*db)->hdb_destroy(context, *db);
*db = NULL;
}
if (cb_ctx.h->prefix == NULL)
cb_ctx.h = NULL;
}
#ifdef HDB_DEFAULT_DB_TYPE
if (cb_ctx.h == NULL || cb_ctx.h->prefix == NULL) {
if (cb_ctx.h == NULL) {
/*
* If still we've not picked a backend, use a build configuration time
* default.
@@ -809,7 +811,7 @@ hdb_create(krb5_context context, HDB **db, const char *filename)
cb_ctx.h = NULL;
}
#endif
if (cb_ctx.h == NULL || cb_ctx.h->prefix == NULL)
if (cb_ctx.h == NULL)
/* Last resort default */
cb_ctx.h = &default_dbmethod;
if (cb_ctx.h->prefix == NULL) {