]> pd.if.org Git - zpackage/blobdiff - lib/zpm.c
fix potential use after free
[zpackage] / lib / zpm.c
index 30e8dc81cdeb15617f5a8089533d792898445373..87ffbbb3ebde53cf464a48fe5a9972883b8a1203 100644 (file)
--- a/lib/zpm.c
+++ b/lib/zpm.c
@@ -258,7 +258,6 @@ static
 #include "newdb.c"
 
 int zpm_db_initialize(struct zpm *pkg) {
-       //fprintf(stderr, "initializing zpm database\n");
        char *error;
        switch (sqlite3_exec(pkg->db, createdb, (int (*)(void *,int,char **,char **))0, NULL, &error)) {
                case SQLITE_OK: break;
@@ -266,6 +265,7 @@ int zpm_db_initialize(struct zpm *pkg) {
                        SQLERROR(sqlite3_errmsg(pkg->db));
                        fprintf(stderr, "error: %s\n", error);
                        sqlite3_free(error);
+                       zpm_rollback(pkg);
                        return 0;
                        break;
        }
@@ -333,6 +333,8 @@ static void zpm_set_db_errmsg(struct zpm *zpm, const char *msg) {
                        if (!zpm->dberrmsg) {
                                zpm->error = 1;
                        }
+               } else {
+                       zpm->dberrmsg = 0;
                }
        }
 }
@@ -357,7 +359,7 @@ int zpm_init(struct zpm *pkg, char *path) {
                        sqlite3_close(db);
                }
                fprintf(stderr, "error (%d): %s: %s\n", rc,
-                               pkg->dberrmsg, path);
+                               pkg->dberrmsg ? pkg->dberrmsg : "null", path);
 
                return 0;
        }
@@ -562,10 +564,6 @@ static int set_elf_info(sqlite3 *db, char *hash, char *content, size_t length) {
                int rc;
 
                /* clear existing for this hash */
-               if (!run_for_hash(db, "delete from elfinfo where file = ?", hash)) {
-                       SQLERP(db, "error clearing elf info");
-                       return 0;
-               }
 
                if (!run_for_hash(db, "delete from elflibraries where file = ?", hash)) {
                        SQLERP(db, "error clearing elf library");