diff --git libpkg/pkg_config.c libpkg/pkg_config.c index 3556716..cc52df1 100644 --- libpkg/pkg_config.c +++ libpkg/pkg_config.c @@ -365,12 +365,16 @@ obj_walk_object(ucl_object_t *obj, struct pkg_config *conf) struct pkg_config_kv *kv; ucl_object_t *cur; ucl_object_iter_t it = NULL; + const char *key; while ((cur = ucl_iterate_object(obj, &it, true))) { if (cur->type != UCL_STRING) continue; kv = malloc(sizeof(struct pkg_config_kv)); - kv->key = strdup(ucl_object_key(cur)); + key = ucl_object_key(cur); + if (key == NULL) + continue; + kv->key = strdup(key); kv->value = strdup(ucl_object_tostring(cur)); HASH_ADD_STR(conf->kvlist, value, kv); } @@ -389,6 +393,8 @@ pkg_object_walk(ucl_object_t *obj, struct pkg_config *conf_by_key) while ((cur = ucl_iterate_object(obj, &it, true))) { sbuf_clear(b); key = ucl_object_key(cur); + if (key == NULL) + continue; for (i = 0; i < strlen(key); i++) sbuf_putc(b, toupper(key[i])); sbuf_finish(b); @@ -693,6 +699,9 @@ add_repo(ucl_object_t *obj, struct pkg_repo *r, const char *rname) while ((cur = ucl_iterate_object(obj, &it, true))) { key = ucl_object_key(cur); + if (key == NULL) + continue; + if (strcasecmp(key, "url") == 0) { if (cur->type != UCL_STRING) { pkg_emit_error("Expecting a string for the " @@ -809,6 +818,8 @@ walk_repo_obj(ucl_object_t *obj) while ((cur = ucl_iterate_object(obj, &it, true))) { key = ucl_object_key(cur); + if (key == NULL) + continue; r = pkg_repo_find_ident(key); if (r != NULL) pkg_debug(1, "PkgConfig: overwriting repository %s", key); @@ -1102,6 +1113,8 @@ pkg_init(const char *path, const char *reposdir) if (obj->type == UCL_OBJECT) { while ((cur = ucl_iterate_object(obj, &it, true))) { key = ucl_object_key(cur); + if (key == NULL) + continue; if (strcasecmp(key, "REPOS_DIR") == 0 && cur->type != UCL_ARRAY) fallback = true; diff --git libpkg/pkg_manifest.c libpkg/pkg_manifest.c index 996f93b..e3a76a2 100644 --- libpkg/pkg_manifest.c +++ libpkg/pkg_manifest.c @@ -376,6 +376,8 @@ pkg_object(struct pkg *pkg, ucl_object_t *obj, int attr) pkg_debug(3, "%s", "Manifest: parsing object"); while ((cur = ucl_iterate_object(obj, &it, true))) { key = ucl_object_key(cur); + if (key == NULL) + continue; switch (attr) { case PKG_DEPS: if (cur->type != UCL_OBJECT && cur->type != UCL_ARRAY) @@ -498,11 +500,16 @@ pkg_set_files_from_object(struct pkg *pkg, ucl_object_t *obj) void *set = NULL; mode_t perm = 0; struct sbuf *fname = NULL; - const char *key; + const char *key, *okey; - urldecode(ucl_object_key(obj), &fname); + okey = ucl_object_key(obj); + if (okey == NULL) + return (EPKG_FATAL); + urldecode(okey, &fname); while ((cur = ucl_iterate_object(obj, &it, true))) { key = ucl_object_key(cur); + if (key == NULL) + continue; if (!strcasecmp(key, "uname") && cur->type == UCL_STRING) uname = ucl_object_tostring(cur); else if (!strcasecmp(key, "gname") && cur->type == UCL_STRING) @@ -540,11 +547,16 @@ pkg_set_dirs_from_object(struct pkg *pkg, ucl_object_t *obj) mode_t perm = 0; bool try = false; struct sbuf *dirname = NULL; - const char *key; + const char *key, *okey; - urldecode(ucl_object_key(obj), &dirname); + okey = ucl_object_key(obj); + if (okey == NULL) + return (EPKG_FATAL); + urldecode(okey, &dirname); while ((cur = ucl_iterate_object(obj, &it, true))) { key = ucl_object_key(cur); + if (key == NULL) + continue; if (!strcasecmp(key, "uname") && cur->type == UCL_STRING) uname = ucl_object_tostring(cur); else if (!strcasecmp(key, "gname") && cur->type == UCL_STRING) @@ -577,15 +589,20 @@ pkg_set_deps_from_object(struct pkg *pkg, ucl_object_t *obj) ucl_object_iter_t it = NULL, it2; const char *origin = NULL; const char *version = NULL; - const char *key; + const char *key, *okey; int64_t vint = 0; char vinteger[BUFSIZ]; - pkg_debug(2, "Found %s", ucl_object_key(obj)); + okey = ucl_object_key(obj); + if (okey == NULL) + return (EPKG_FATAL); + pkg_debug(2, "Found %s", okey); while ((self = ucl_iterate_object(obj, &it, (obj->type == UCL_ARRAY)))) { it2 = NULL; while ((cur = ucl_iterate_object(self, &it2, true))) { key = ucl_object_key(cur); + if (key == NULL) + continue; if (cur->type != UCL_STRING) { /* accept version to be an integer */ if (cur->type == UCL_INT && strcasecmp(key, "version") == 0) { @@ -595,7 +612,7 @@ pkg_set_deps_from_object(struct pkg *pkg, ucl_object_t *obj) } pkg_emit_error("Skipping malformed dependency entry " - "for %s", ucl_object_key(obj)); + "for %s", okey); continue; } if (strcasecmp(key, "origin") == 0) @@ -604,9 +621,9 @@ pkg_set_deps_from_object(struct pkg *pkg, ucl_object_t *obj) version = ucl_object_tostring(cur); } if (origin != NULL && (version != NULL || vint > 0)) - pkg_adddep(pkg, ucl_object_key(obj), origin, vint > 0 ? vinteger : version, false); + pkg_adddep(pkg, okey, origin, vint > 0 ? vinteger : version, false); else - pkg_emit_error("Skipping malformed dependency %s", ucl_object_key(obj)); + pkg_emit_error("Skipping malformed dependency %s", okey); } return (EPKG_OK); @@ -619,10 +636,14 @@ parse_manifest(struct pkg *pkg, struct pkg_manifest_key *keys, ucl_object_t *obj ucl_object_iter_t it = NULL; struct pkg_manifest_key *selected_key; struct dataparser *dp; + const char *key; while ((cur = ucl_iterate_object(obj, &it, true))) { - pkg_debug(2, "Manifest: found key: '%s'", ucl_object_key(cur)); - HASH_FIND_STR(keys, ucl_object_key(cur), selected_key); + key = ucl_object_key(cur); + if (key == NULL) + continue; + pkg_debug(2, "Manifest: found key: '%s'", key); + HASH_FIND_STR(keys, key, selected_key); if (selected_key != NULL) { HASH_FIND_UCLT(selected_key->parser, &cur->type, dp); if (dp != NULL) { @@ -644,6 +665,7 @@ pkg_parse_manifest(struct pkg *pkg, char *buf, size_t len, struct pkg_manifest_k struct pkg_manifest_key *sk; struct dataparser *dp; bool fallback = false; + const char *key; assert(pkg != NULL); assert(buf != NULL); @@ -658,7 +680,10 @@ pkg_parse_manifest(struct pkg *pkg, char *buf, size_t len, struct pkg_manifest_k obj = ucl_parser_get_object(p); if (obj != NULL) { while ((cur = ucl_iterate_object(obj, &it, true))) { - HASH_FIND_STR(keys, ucl_object_key(cur), sk); + key = ucl_object_key(cur); + if (key == NULL) + continue; + HASH_FIND_STR(keys, key, sk); if (sk != NULL) { HASH_FIND_UCLT(sk->parser, &cur->type, dp); if (dp == NULL) { @@ -702,6 +727,7 @@ pkg_parse_manifest_file(struct pkg *pkg, const char *file, struct pkg_manifest_k bool fallback = false; struct pkg_manifest_key *sk; struct dataparser *dp; + const char *key; assert(pkg != NULL); assert(file != NULL); @@ -722,7 +748,10 @@ pkg_parse_manifest_file(struct pkg *pkg, const char *file, struct pkg_manifest_k obj = ucl_parser_get_object(p); if (obj != NULL) { while ((cur = ucl_iterate_object(obj, &it, true))) { - HASH_FIND_STR(keys, ucl_object_key(cur), sk); + key = ucl_object_key(cur); + if (key == NULL) + continue; + HASH_FIND_STR(keys, key, sk); if (sk != NULL) { HASH_FIND_UCLT(sk->parser, &cur->type, dp); if (dp == NULL) { diff --git libpkg/pkg_ports.c libpkg/pkg_ports.c index 1381494..4b8503a 100644 --- libpkg/pkg_ports.c +++ libpkg/pkg_ports.c @@ -668,6 +668,8 @@ parse_attributes(ucl_object_t *o, struct file_attr **a) { while ((cur = ucl_iterate_object(o, &it, true))) { key = ucl_object_key(cur); + if (key == NULL) + continue; if (!strcasecmp(key, "owner") && cur->type == UCL_STRING) { free((*a)->owner); (*a)->owner = strdup(ucl_object_tostring(cur)); @@ -704,6 +706,8 @@ parse_and_apply_keyword_file(ucl_object_t *obj, struct plist *p, char *line, str while ((cur = ucl_iterate_object(obj, &it, true))) { key = ucl_object_key(cur); + if (key == NULL) + continue; if (!strcasecmp(key, "actions") && cur->type == UCL_ARRAY) { actions = cur; continue; diff --git pkg/which.c pkg/which.c index 33e52bb..437e10c 100644 --- pkg/which.c +++ pkg/which.c @@ -50,7 +50,7 @@ exec_which(int argc, char **argv) struct pkgdb_it *it = NULL; struct pkg *pkg = NULL; char pathabs[MAXPATHLEN + 1]; - int ret = EPKG_OK, retcode = EX_OK; + int ret = EPKG_OK, retcode = EX_SOFTWARE; int ch; bool orig = false; bool glob = false; @@ -96,6 +96,7 @@ exec_which(int argc, char **argv) return (EX_IOERR); while ((ret = pkgdb_it_next(it, &pkg, PKG_LOAD_BASIC)) == EPKG_OK) { + retcode = EX_OK; if (quiet && orig) pkg_printf("%o\n", pkg); else if (quiet && !orig) @@ -104,19 +105,11 @@ exec_which(int argc, char **argv) pkg_printf("%S was installed by package %o\n", pathabs, pkg); else if (!quiet && !orig) pkg_printf("%S was installed by package %n-%v\n", pathabs, pkg, pkg); - if (!glob) - break; } - if (ret != EPKG_END) { - retcode = EX_SOFTWARE; - } - else if (!glob) { - if (!quiet) - printf("%s was not found in the database\n", pathabs); - retcode = EX_DATAERR; - } - + if (retcode != EX_OK && !quiet) + printf("%s was not found in the database\n", pathabs); + pkg_free(pkg); pkgdb_it_free(it);