From 9fb3c38aa28bae508f02764cc205df04dab4c9d2 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Wed, 19 Oct 2011 16:53:38 +0200 Subject: [PATCH] Extend assertions by checking passed in proplib type. --- lib/init_virtualpkgs.c | 2 ++ lib/package_config_files.c | 4 ++-- lib/package_purge.c | 1 + lib/package_register.c | 2 ++ lib/package_remove.c | 2 +- lib/package_remove_obsoletes.c | 4 ++-- lib/package_replaces.c | 3 +++ lib/package_requiredby.c | 6 ++++-- lib/package_state.c | 8 ++++---- lib/package_unpack.c | 4 ++-- lib/plist_find.c | 8 ++++---- lib/plist_match.c | 4 +++- lib/plist_remove.c | 4 +++- lib/repository_finddeps.c | 16 ++++++++++------ lib/repository_pool_find.c | 6 ++++++ lib/util.c | 8 ++++---- lib/util_hash.c | 4 ++-- 17 files changed, 55 insertions(+), 31 deletions(-) diff --git a/lib/init_virtualpkgs.c b/lib/init_virtualpkgs.c index 5f523614..423833d9 100644 --- a/lib/init_virtualpkgs.c +++ b/lib/init_virtualpkgs.c @@ -46,6 +46,8 @@ xbps_init_virtual_pkgs(struct xbps_handle *xh) prop_string_t vpkgdir; char *vpkgfile; + assert(xh != NULL); + if (prop_object_type(xh->confdir) != PROP_TYPE_STRING) { vpkgdir = prop_string_create_cstring(XBPS_SYSCONF_PATH); prop_string_append_cstring(vpkgdir, "/"); diff --git a/lib/package_config_files.c b/lib/package_config_files.c index 2c8a1f31..6476f44e 100644 --- a/lib/package_config_files.c +++ b/lib/package_config_files.c @@ -42,7 +42,7 @@ xbps_entry_is_a_conf_file(prop_dictionary_t propsd, char *cffile; int rv = 0; - assert(propsd != NULL); + assert(prop_object_type(propsd) == PROP_TYPE_DICTIONARY); assert(entry_pname != NULL); if (!prop_dictionary_get(propsd, "conf_files")) @@ -89,7 +89,7 @@ xbps_entry_install_conf_file(prop_dictionary_t filesd, char *buf, *sha256_cur = NULL, *sha256_orig = NULL; int rv = 0; - assert(filesd != NULL); + assert(prop_object_type(filesd) == PROP_TYPE_DICTIONARY); assert(entry != NULL); assert(entry_pname != NULL); assert(pkgname != NULL); diff --git a/lib/package_purge.c b/lib/package_purge.c index 333028ff..29dac630 100644 --- a/lib/package_purge.c +++ b/lib/package_purge.c @@ -55,6 +55,7 @@ remove_pkg_metadata(const char *pkgname, const char *rootdir) int rv = 0; assert(pkgname != NULL); + assert(rootdir != NULL); metadir = xbps_xasprintf("%s/%s/metadata/%s", rootdir, XBPS_META_PATH, pkgname); diff --git a/lib/package_register.c b/lib/package_register.c index c90470eb..c8c0463d 100644 --- a/lib/package_register.c +++ b/lib/package_register.c @@ -50,6 +50,8 @@ xbps_register_pkg(prop_dictionary_t pkgrd) int rv = 0; bool autoinst = false; + assert(prop_object_type(pkgrd) == PROP_TYPE_DICTIONARY); + xhp = xbps_handle_get(); plist = xbps_xasprintf("%s/%s/%s", prop_string_cstring_nocopy(xhp->rootdir), diff --git a/lib/package_remove.c b/lib/package_remove.c index 7a5afe7e..e89713b9 100644 --- a/lib/package_remove.c +++ b/lib/package_remove.c @@ -81,7 +81,7 @@ xbps_remove_pkg_files(prop_dictionary_t dict, const char *key) char *path = NULL; int rv = 0; - assert(dict != NULL); + assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY); assert(key != NULL); xhp = xbps_handle_get(); diff --git a/lib/package_remove_obsoletes.c b/lib/package_remove_obsoletes.c index 65e06e0e..410200e2 100644 --- a/lib/package_remove_obsoletes.c +++ b/lib/package_remove_obsoletes.c @@ -48,8 +48,8 @@ xbps_remove_obsoletes(prop_dictionary_t oldd, prop_dictionary_t newd) int rv = 0; bool found, dodirs = false, dolinks = false; - assert(oldd != NULL); - assert(newd != NULL); + assert(prop_object_type(oldd) == PROP_TYPE_DICTIONARY); + assert(prop_object_type(newd) == PROP_TYPE_DICTIONARY); again: iter = xbps_array_iter_from_dict(oldd, array_str); diff --git a/lib/package_replaces.c b/lib/package_replaces.c index 9ab11fbe..24f67a89 100644 --- a/lib/package_replaces.c +++ b/lib/package_replaces.c @@ -43,6 +43,9 @@ xbps_repository_pkg_replaces(prop_dictionary_t transd, const char *pattern, *pkgname, *curpkgname; bool instd_auto = false; + assert(prop_object_type(transd) == PROP_TYPE_DICTIONARY); + assert(prop_object_type(pkg_repod) == PROP_TYPE_DICTIONARY); + replaces = prop_dictionary_get(pkg_repod, "replaces"); if (replaces == NULL || prop_array_count(replaces) == 0) return 0; diff --git a/lib/package_requiredby.c b/lib/package_requiredby.c index b0f99500..09ca5717 100644 --- a/lib/package_requiredby.c +++ b/lib/package_requiredby.c @@ -38,6 +38,8 @@ add_pkg_into_reqby(prop_dictionary_t pkgd, const char *pkgver) prop_string_t reqstr; bool alloc = false; + assert(prop_object_type(pkgd) == PROP_TYPE_DICTIONARY); + if ((reqby = prop_dictionary_get(pkgd, "requiredby")) == NULL) { alloc = true; if ((reqby = prop_array_create()) == NULL) @@ -150,8 +152,8 @@ xbps_requiredby_pkg_add(prop_array_t pkgs_array, prop_dictionary_t pkgd) const char *pkgver, *str; int rv = 0; - assert(pkgs_array != NULL); - assert(pkgd != NULL); + assert(prop_object_type(pkgs_array) == PROP_TYPE_ARRAY); + assert(prop_object_type(pkgd) == PROP_TYPE_DICTIONARY); prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver); pkg_rdeps = prop_dictionary_get(pkgd, "run_depends"); diff --git a/lib/package_state.c b/lib/package_state.c index 5a7bd8cc..d7dc2100 100644 --- a/lib/package_state.c +++ b/lib/package_state.c @@ -59,7 +59,7 @@ set_new_state(prop_dictionary_t dict, pkg_state_t state) const struct state *stp; const char *pkgname; - assert(dict != NULL); + assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY); for (stp = states; stp->string != NULL; stp++) if (state == stp->number) @@ -85,7 +85,7 @@ get_state(prop_dictionary_t dict) const struct state *stp; const char *state_str; - assert(dict != NULL); + assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY); if (!prop_dictionary_get_cstring_nocopy(dict, "state", &state_str)) @@ -121,7 +121,7 @@ xbps_pkg_state_installed(const char *pkgname, pkg_state_t *state) int xbps_pkg_state_dictionary(prop_dictionary_t dict, pkg_state_t *state) { - assert(dict != NULL); + assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY); assert(state != NULL); if ((*state = get_state(dict)) == 0) @@ -133,7 +133,7 @@ xbps_pkg_state_dictionary(prop_dictionary_t dict, pkg_state_t *state) int xbps_set_pkg_state_dictionary(prop_dictionary_t dict, pkg_state_t state) { - assert(dict != NULL); + assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY); return set_new_state(dict, state); } diff --git a/lib/package_unpack.c b/lib/package_unpack.c index 55cf7bf5..8bed1fed 100644 --- a/lib/package_unpack.c +++ b/lib/package_unpack.c @@ -165,8 +165,8 @@ unpack_archive(prop_dictionary_t pkg_repod, int rv, flags; bool preserve, update; + assert(prop_object_type(pkg_repod) == PROP_TYPE_DICTIONARY); assert(ar != NULL); - assert(pkg_repod != NULL); assert(pkgname != NULL); assert(version != NULL); @@ -467,7 +467,7 @@ xbps_unpack_binary_pkg(prop_dictionary_t pkg_repod) char *bpkg; int rv = 0; - assert(pkg_repod != NULL); + assert(prop_object_type(pkg_repod) == PROP_TYPE_DICTIONARY); prop_dictionary_get_cstring_nocopy(pkg_repod, "pkgname", &pkgname); prop_dictionary_get_cstring_nocopy(pkg_repod, "version", &version); diff --git a/lib/plist_find.c b/lib/plist_find.c index c96c0f3d..329e934f 100644 --- a/lib/plist_find.c +++ b/lib/plist_find.c @@ -50,7 +50,7 @@ find_pkg_in_array(prop_array_t array, prop_object_t obj = NULL; const char *pkgver, *dpkgn; - assert(array != NULL); + assert(prop_object_type(array) == PROP_TYPE_ARRAY); assert(str != NULL); iter = prop_array_iterator(array); @@ -172,7 +172,7 @@ find_virtualpkg_user_in_array(prop_array_t array, prop_object_iterator_t iter; const char *pkgver, *virtualpkg; - assert(array != NULL); + assert(prop_object_type(array) == PROP_TYPE_ARRAY); assert(str != NULL); virtualpkg = find_virtualpkg_user_in_conf(str, bypattern); @@ -201,7 +201,7 @@ find_virtualpkg_user_in_dict(prop_dictionary_t d, { prop_array_t array; - assert(d != NULL); + assert(prop_object_type(d) == PROP_TYPE_DICTIONARY); assert(str != NULL); assert(key != NULL); @@ -221,7 +221,7 @@ find_pkg_in_dict(prop_dictionary_t d, { prop_array_t array; - assert(d != NULL); + assert(prop_object_type(d) == PROP_TYPE_DICTIONARY); assert(str != NULL); assert(key != NULL); diff --git a/lib/plist_match.c b/lib/plist_match.c index 1bc2eab9..6cc03397 100644 --- a/lib/plist_match.c +++ b/lib/plist_match.c @@ -47,6 +47,8 @@ xbps_match_virtual_pkg_in_dict(prop_dictionary_t d, prop_array_t provides; bool found = false; + assert(prop_object_type(d) == PROP_TYPE_DICTIONARY); + if ((provides = prop_dictionary_get(d, "provides"))) { if (bypattern) found = xbps_match_pkgpattern_in_array(provides, str); @@ -65,7 +67,7 @@ match_string_in_array(prop_array_t array, const char *str, int mode) char *curpkgname; bool found = false; - assert(array != NULL); + assert(prop_object_type(array) == PROP_TYPE_ARRAY); assert(str != NULL); iter = prop_array_iterator(array); diff --git a/lib/plist_remove.c b/lib/plist_remove.c index 9d66bf64..be2f310c 100644 --- a/lib/plist_remove.c +++ b/lib/plist_remove.c @@ -48,6 +48,8 @@ remove_string_from_array(prop_array_t array, const char *str, int mode) size_t i, idx = 0; bool found = false; + assert(prop_object_type(array) == PROP_TYPE_ARRAY); + for (i = 0; i < prop_array_count(array); i++) { obj = prop_array_get(array, i); if (mode == 0) { @@ -111,7 +113,7 @@ xbps_remove_pkg_from_dict_by_name(prop_dictionary_t dict, { prop_array_t array; - assert(dict != NULL); + assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY); assert(key != NULL); assert(pkgname != NULL); diff --git a/lib/repository_finddeps.c b/lib/repository_finddeps.c index f845eca0..7bb445a1 100644 --- a/lib/repository_finddeps.c +++ b/lib/repository_finddeps.c @@ -39,8 +39,8 @@ store_dependency(prop_dictionary_t transd, prop_dictionary_t repo_pkgd) int rv = 0; pkg_state_t state = 0; - assert(transd != NULL); - assert(repo_pkgd != NULL); + assert(prop_object_type(transd) == PROP_TYPE_DICTIONARY); + assert(prop_object_type(repo_pkgd) == PROP_TYPE_DICTIONARY); /* * Get some info about dependencies and current repository. */ @@ -122,7 +122,7 @@ add_missing_reqdep(prop_array_t missing_rdeps, const char *reqpkg) bool add_pkgdep, pkgfound, update_pkgdep; int rv = 0; - assert(missing_rdeps != NULL); + assert(prop_object_type(missing_rdeps) == PROP_TYPE_ARRAY); assert(reqpkg != NULL); add_pkgdep = update_pkgdep = pkgfound = false; @@ -214,6 +214,10 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */ char *pkgname; int rv = 0; + assert(prop_object_type(transd) == PROP_TYPE_DICTIONARY); + assert(prop_object_type(mrdeps) == PROP_TYPE_ARRAY); + assert(prop_object_type(pkg_rdeps_array) == PROP_TYPE_ARRAY); + if (depth >= MAX_DEPTH) return ELOOP; @@ -445,9 +449,9 @@ xbps_repository_find_pkg_deps(prop_dictionary_t transd, const char *pkgver; int rv = 0; - assert(transd != NULL); - assert(mdeps != NULL); - assert(repo_pkgd != NULL); + assert(prop_object_type(transd) == PROP_TYPE_DICTIONARY); + assert(prop_object_type(mdeps) == PROP_TYPE_ARRAY); + assert(prop_object_type(repo_pkgd) == PROP_TYPE_DICTIONARY); pkg_rdeps = prop_dictionary_get(repo_pkgd, "run_depends"); if (pkg_rdeps == NULL) diff --git a/lib/repository_pool_find.c b/lib/repository_pool_find.c index e656105f..fa4c3c8d 100644 --- a/lib/repository_pool_find.c +++ b/lib/repository_pool_find.c @@ -48,6 +48,8 @@ repo_find_virtualpkg_cb(struct repository_pool_index *rpi, void *arg, bool *done { struct repo_pool_fpkg *rpf = arg; + assert(rpi != NULL); + if (rpf->bypattern) { rpf->pkgd = xbps_find_virtualpkg_conf_in_dict_by_pattern(rpi->rpi_repod, @@ -77,6 +79,8 @@ repo_find_pkg_cb(struct repository_pool_index *rpi, void *arg, bool *done) { struct repo_pool_fpkg *rpf = arg; + assert(rpi != NULL); + if (rpf->bypattern) { rpf->pkgd = xbps_find_pkg_in_dict_by_pattern(rpi->rpi_repod, "packages", rpf->pattern); @@ -122,6 +126,8 @@ repo_find_best_pkg_cb(struct repository_pool_index *rpi, prop_dictionary_t instpkgd; const char *instver, *repover; + assert(rpi != NULL); + rpf->pkgd = xbps_find_pkg_in_dict_by_name(rpi->rpi_repod, "packages", rpf->pattern); if (rpf->pkgd == NULL) { diff --git a/lib/util.c b/lib/util.c index 7e7cb579..4acec108 100644 --- a/lib/util.c +++ b/lib/util.c @@ -248,7 +248,7 @@ xbps_path_from_repository_uri(prop_dictionary_t pkg_repod, const char *repoloc) const char *filen, *arch; char *lbinpkg = NULL; - assert(pkg_repod != NULL); + assert(prop_object_type(pkg_repod) == PROP_TYPE_DICTIONARY); assert(repoloc != NULL); if (!prop_dictionary_get_cstring_nocopy(pkg_repod, @@ -278,13 +278,13 @@ xbps_path_from_repository_uri(prop_dictionary_t pkg_repod, const char *repoloc) } bool -xbps_pkg_has_rundeps(prop_dictionary_t pkg) +xbps_pkg_has_rundeps(prop_dictionary_t pkgd) { prop_array_t array; - assert(pkg != NULL); + assert(prop_object_type(pkgd) == PROP_TYPE_DICTIONARY); - array = prop_dictionary_get(pkg, "run_depends"); + array = prop_dictionary_get(pkgd, "run_depends"); if (array && prop_array_count(array) > 0) return true; diff --git a/lib/util_hash.c b/lib/util_hash.c index f60bcff1..8a20c27a 100644 --- a/lib/util_hash.c +++ b/lib/util_hash.c @@ -145,7 +145,7 @@ xbps_file_hash_dictionary(prop_dictionary_t d, prop_object_iterator_t iter; const char *curfile, *sha256; - assert(d != NULL); + assert(prop_object_type(d) == PROP_TYPE_DICTIONARY); assert(key != NULL); assert(file != NULL); @@ -181,7 +181,7 @@ xbps_file_hash_check_dictionary(prop_dictionary_t d, const char *sha256d; int rv; - assert(d != NULL); + assert(prop_object_type(d) == PROP_TYPE_DICTIONARY); assert(key != NULL); assert(file != NULL);