From: Nathan Wagner Date: Sat, 29 Sep 2018 22:35:06 +0000 (+0000) Subject: fix pointer related bugs X-Git-Tag: v0.1.7~13 X-Git-Url: https://pd.if.org/git/?a=commitdiff_plain;h=e65e12081df227971bcf449ebcb230e1c980649b;hp=8db0580dab2fa716c486acbf34e459a56427acc3;p=zpackage fix pointer related bugs --- diff --git a/lib/dbquery.c b/lib/dbquery.c index d6ef8b5..3f81841 100644 --- a/lib/dbquery.c +++ b/lib/dbquery.c @@ -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; } diff --git a/lib/vercmp.c b/lib/vercmp.c index 91d5363..16cf1cd 100644 --- a/lib/vercmp.c +++ b/lib/vercmp.c @@ -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; diff --git a/lib/zpm.c b/lib/zpm.c index b8b77b0..e775b12 100644 --- 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); diff --git a/zpm-runscript.c b/zpm-runscript.c index 06d0c70..ccaee48 100644 --- a/zpm-runscript.c +++ b/zpm-runscript.c @@ -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++; }