]> pd.if.org Git - zpackage/commitdiff
fix pointer related bugs
authorNathan Wagner <nw@hydaspes.if.org>
Sat, 29 Sep 2018 22:35:06 +0000 (22:35 +0000)
committerNathan Wagner <nw@hydaspes.if.org>
Sat, 29 Sep 2018 22:35:06 +0000 (22:35 +0000)
lib/dbquery.c
lib/vercmp.c
lib/zpm.c
zpm-runscript.c

index d6ef8b55239ebe19e1480381d91f5b52c4e07634..3f818418d88486e477df17a7544f8bfc04f1efe3 100644 (file)
@@ -12,7 +12,11 @@ sqlite3_stmt *zpm_dbquery(struct zpm *zpm, char *query, ...) {
        sqlite3_stmt *st;
        int rv;
 
-       if (!zpm || zpm->error || !zpm->db) {
+       if (!zpm || zpm->error) {
+               return 0;
+       }
+
+       if (!zpm->db) {
                zpm->error = 1;
                return 0;
        }
index 91d536305cdcf97d6c84d0b32343a1f794d69c73..16cf1cdc4eab48ab1f4b89b4cac0178d23b4a858 100644 (file)
@@ -52,6 +52,9 @@ static int ver_cmp(struct ver *a, struct ver *b) {
        }
        if (a->type == 1) {
                int cmp;
+               if (a->s && ! b->s) return 1;
+               if (b->s && ! a->s) return -1;
+               if (!b->s && ! a->s) return 0;
                cmp = strcmp(a->s, b->s);
                if (cmp == 0) {
                        return 0;
@@ -127,6 +130,9 @@ int zpm_vercmp(const char *vsa, const char *vsb) {
                        }
                        return an < bn ? -1 : 1;
                }
+               if (an == 0 && bn == 0) {
+                       return 0;
+               }
                cmp = ver_cmp(&a, &b);
                if (cmp != 0) {
                        return cmp;
index b8b77b0861b2e3f9a28d16b71fbe56f54ab0425a..e775b1209809f36c22ba7584d1036168a442432d 100644 (file)
--- a/lib/zpm.c
+++ b/lib/zpm.c
@@ -328,6 +328,10 @@ int zpm_init(struct zpm *pkg, char *path) {
        sqlite3 *db = 0;
        int appid;
 
+       if (!pkg) {
+               return 0;
+       }
+
        zpm_clearmem(pkg);
 
        rc = sqlite3_open_v2(path, &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
@@ -576,7 +580,7 @@ static int set_elf_info(sqlite3 *db, char *hash, char *content, size_t length) {
 
                /* if exe, set neededs */
                if (libelf_type(content) == ET_EXEC) {
-                       Elf64_Shdr *dsect;
+                       Elf64_Shdr *dsect = 0;
                        char *elf;
 
                        elf = (char *)content;
@@ -587,10 +591,17 @@ static int set_elf_info(sqlite3 *db, char *hash, char *content, size_t length) {
                                        dsect = (Elf64_Shdr *)(elf + phdr->p_offset);
                                }
                        }
+                       if (!dsect) {
+                               /* no dynamic section found */
+                               return 1;
+                       }
+
+#if 0
                        dyn = (Elf64_Dyn *)(elf + dsect->sh_offset);
                        if (!dyn) {
                                exit(9);
                        }
+#endif
                        dyn = (Elf64_Dyn *)dsect;
 
                        dsect = libelf_section(elf, SHT_DYNAMIC);
index 06d0c701bde537cd86aef6513c58cd3803301a1b..ccaee48c30229f062e97afd8280b63a9c2086de7 100644 (file)
@@ -192,8 +192,12 @@ int main(int ac, char **av){
                                                pkgid, rv);
                        }
                        /* TODO log output */
-                       unlink(script);
-                       unlink(output);
+                       if (script) {
+                               unlink(script);
+                       }
+                       if (output) {
+                               unlink(output);
+                       }
                        if (rv) {
                                failures++;
                        }