From 58c8b838040557cba501f6b6e7bd585f18c0f3cc Mon Sep 17 00:00:00 2001 From: Ken Raeburn Date: Mon, 8 Jan 2007 22:41:01 +0000 Subject: [PATCH] crash creating db2 database in non-existent directory * kdb_db2.c (krb5_db2_db_create): If the creation of the first database file fails, return the error, instead of attempting to create the second (and using a null pointer as an input string in formatting a filename). Reported by Jeff Blaine. ticket: new git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@19038 dc483132-0cff-0310-8789-dd5450dbe970 --- src/plugins/kdb/db2/kdb_db2.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src/plugins/kdb/db2/kdb_db2.c b/src/plugins/kdb/db2/kdb_db2.c index 9a0254dd3..d438171cb 100644 --- a/src/plugins/kdb/db2/kdb_db2.c +++ b/src/plugins/kdb/db2/kdb_db2.c @@ -702,25 +702,22 @@ krb5_db2_db_create(krb5_context context, char *db_name, krb5_int32 flags) } db = k5db2_dbopen(db_ctx, db_name, O_RDWR | O_CREAT | O_EXCL, 0600, db_ctx->tempdb); if (db == NULL) - retval = errno; - else - (*db->close) (db); - if (retval == 0) { + return errno; + (*db->close) (db); - db_name2 = db_ctx->tempdb ? gen_dbsuffix(db_name, "~") : strdup(db_name); - if (db_name2 == NULL) - return ENOMEM; - okname = gen_dbsuffix(db_name2, KDB2_LOCK_EXT); - if (!okname) - retval = ENOMEM; - else { - fd = open(okname, O_CREAT | O_RDWR | O_TRUNC, 0600); - if (fd < 0) - retval = errno; - else - close(fd); - free_dbsuffix(okname); - } + db_name2 = db_ctx->tempdb ? gen_dbsuffix(db_name, "~") : strdup(db_name); + if (db_name2 == NULL) + return ENOMEM; + okname = gen_dbsuffix(db_name2, KDB2_LOCK_EXT); + if (!okname) + retval = ENOMEM; + else { + fd = open(okname, O_CREAT | O_RDWR | O_TRUNC, 0600); + if (fd < 0) + retval = errno; + else + close(fd); + free_dbsuffix(okname); } sprintf(policy_db_name, "%s.kadm5", db_name2); -- 2.26.2