crash creating db2 database in non-existent directory
authorKen Raeburn <raeburn@mit.edu>
Mon, 8 Jan 2007 22:41:01 +0000 (22:41 +0000)
committerKen Raeburn <raeburn@mit.edu>
Mon, 8 Jan 2007 22:41:01 +0000 (22:41 +0000)
* 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

index 9a0254dd3d57984a5638dd1668f8f8fe9ddc6506..d438171cbdb0fe670f5eb3285f1256986862f9ba 100644 (file)
@@ -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);