From 83c716424f97cfc1dfa2a1e88a64cd695f2717fa Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Sun, 21 Nov 2010 04:00:32 -0300 Subject: [PATCH] qpkg: perform sanity checks after parsing a package entry - gobble.c (compact_pkg, gobble_buf): renamed compact_pkg to finish_pkg - gobble.c (finish_pkg): check that the package has a version - gobble.c (finish_pkg): check that the package has an architecture - gobble.c (finish_pkg): check that the package either has a file name or is installed --- qpkg/gobble.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/qpkg/gobble.c b/qpkg/gobble.c index 3c9dfa4..a64f750 100644 --- a/qpkg/gobble.c +++ b/qpkg/gobble.c @@ -92,10 +92,29 @@ #define DONE goto done -static void compact_pkg(struct pkg *new, struct jrb *jrb) +static void finish_pkg(struct pkg *new, struct jrb *jrb) { struct pkg *old; + if (!new->version) { + fprintf(stderr, "package %.*s has no version\n", + ID2PF(new->id)); + exit(1); + } + if (!new->arch) { + fprintf(stderr, + "package %.*s version %.*s has no architecture\n", + ID2PF(new->id), ID2PF(new->version)); + exit(1); + } + if (!new->filename && !(new->flags & QPKG_INSTALLED)) { + fprintf(stderr, + "package %.*s version %.*s has no file name " + "(nor is it installed)\n", + ID2PF(new->id), ID2PF(new->version)); + exit(1); + } + for (old = new->more; old; old = old->more) if (old->version == new->version) goto compact; @@ -280,7 +299,7 @@ depends: package: if (pkg) - compact_pkg(pkg, jrb); + finish_pkg(pkg, jrb); WHITESPACE; pkg = alloc_type(struct pkg); @@ -407,7 +426,7 @@ list_with_version: done: if (pkg) - compact_pkg(pkg, jrb); + finish_pkg(pkg, jrb); return; fail: