From 8931dec78b2e258f0702250eb17f148cb514c8a5 Mon Sep 17 00:00:00 2001 From: Tom Yu Date: Thu, 29 Mar 2007 21:36:12 +0000 Subject: [PATCH] pull up r19038 from trunk r19038@cathode-dark-space: raeburn | 2007-01-08 17:41:01 -0500 ticket: new subject: 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: 5293 version_fixed: 1.6.1 git-svn-id: svn://anonsvn.mit.edu/krb5/branches/krb5-1-6@19308 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