Be a bit more paranoid by checking allocs and expected types.

This commit is contained in:
Juan RP 2011-12-22 08:23:11 +01:00
parent 1c6794a4e4
commit 5a892023f4
6 changed files with 30 additions and 15 deletions

View File

@ -152,6 +152,10 @@ xbps_init(struct xbps_handle *xh)
xhp->cachedir = cfg_getstr(xhp->cfg, "cachedir"); xhp->cachedir = cfg_getstr(xhp->cfg, "cachedir");
} }
get_cachedir(xhp); get_cachedir(xhp);
if (xhp->cachedir_priv == NULL) {
xbps_end(xh);
return ENOMEM;
}
xhp->cachedir = xhp->cachedir_priv; xhp->cachedir = xhp->cachedir_priv;
if (xhp->cfg == NULL) { if (xhp->cfg == NULL) {
@ -199,8 +203,9 @@ xbps_end(struct xbps_handle *xh)
return; return;
if (xh->cfg != NULL) if (xh->cfg != NULL)
cfg_free(xh->cfg); cfg_free(xh->cfg);
if (xh->cachedir_priv != NULL)
free(xh->cachedir_priv); free(xh->cachedir_priv);
free(xh); free(xh);
xh = NULL; xh = NULL;
xhp = NULL; xhp = NULL;

View File

@ -138,7 +138,10 @@ find_orphan_pkg(prop_object_t obj, void *arg, bool *loop_done)
continue; continue;
pkgdepname = xbps_pkg_name(pkgdep); pkgdepname = xbps_pkg_name(pkgdep);
assert(pkgdepname != NULL); if (pkgdepname == NULL) {
prop_object_iterator_release(iter);
return ENOMEM;
}
for (i = 0; i < prop_array_count(od->orphans_user); i++) { for (i = 0; i < prop_array_count(od->orphans_user); i++) {
prop_array_get_cstring_nocopy(od->orphans_user, prop_array_get_cstring_nocopy(od->orphans_user,
i, &curpkgname); i, &curpkgname);

View File

@ -285,7 +285,7 @@ xbps_set_pkg_state_installed(const char *pkgname,
} }
out: out:
if (dict) if (prop_object_type(dict) == PROP_TYPE_DICTIONARY)
prop_object_release(dict); prop_object_release(dict);
if (metadir) if (metadir)
free(metadir); free(metadir);

View File

@ -408,6 +408,10 @@ unpack_archive(prop_dictionary_t pkg_repod, struct archive *ar)
* file but renaming it to <file>.old. * file but renaming it to <file>.old.
*/ */
buf = xbps_xasprintf("%s.old", entry_pname); buf = xbps_xasprintf("%s.old", entry_pname);
if (buf == NULL) {
rv = ENOMEM;
goto out;
}
(void)rename(entry_pname, buf); (void)rename(entry_pname, buf);
free(buf); free(buf);
xbps_set_cb_state(XBPS_STATE_CONFIG_FILE, 0, xbps_set_cb_state(XBPS_STATE_CONFIG_FILE, 0,
@ -538,9 +542,9 @@ out:
int int
xbps_unpack_binary_pkg(prop_dictionary_t pkg_repod) xbps_unpack_binary_pkg(prop_dictionary_t pkg_repod)
{ {
struct archive *ar; struct archive *ar = NULL;
const char *pkgname, *version, *repoloc, *pkgver, *fname; const char *pkgname, *version, *repoloc, *pkgver, *fname;
char *bpkg; char *bpkg = NULL;
int rv = 0; int rv = 0;
assert(prop_object_type(pkg_repod) == PROP_TYPE_DICTIONARY); assert(prop_object_type(pkg_repod) == PROP_TYPE_DICTIONARY);
@ -563,8 +567,8 @@ xbps_unpack_binary_pkg(prop_dictionary_t pkg_repod)
} }
if ((ar = archive_read_new()) == NULL) { if ((ar = archive_read_new()) == NULL) {
rv = ENOMEM; free(bpkg);
goto out; return ENOMEM;
} }
/* /*
* Enable support for tar format and all compression methods. * Enable support for tar format and all compression methods.
@ -578,8 +582,12 @@ xbps_unpack_binary_pkg(prop_dictionary_t pkg_repod)
rv, pkgname, version, rv, pkgname, version,
"%s: [unpack] failed to open binary package `%s': %s", "%s: [unpack] failed to open binary package `%s': %s",
pkgver, fname, strerror(rv)); pkgver, fname, strerror(rv));
goto out; free(bpkg);
archive_read_finish(ar);
return rv;
} }
free(bpkg);
/* /*
* Set package state to half-unpacked. * Set package state to half-unpacked.
*/ */
@ -613,8 +621,6 @@ xbps_unpack_binary_pkg(prop_dictionary_t pkg_repod)
pkgver, strerror(rv)); pkgver, strerror(rv));
} }
out: out:
if (bpkg)
free(bpkg);
if (ar) if (ar)
archive_read_finish(ar); archive_read_finish(ar);

View File

@ -228,7 +228,7 @@ xbps_repository_pool_find_virtualpkg(const char *pkg, bool bypattern, bool best)
assert(pkg != NULL); assert(pkg != NULL);
rpf = repo_find_pkg(pkg, bypattern, best, true); rpf = repo_find_pkg(pkg, bypattern, best, true);
if (rpf->pkgd != NULL) if (prop_object_type(rpf->pkgd) == PROP_TYPE_DICTIONARY)
pkgd = prop_dictionary_copy(rpf->pkgd); pkgd = prop_dictionary_copy(rpf->pkgd);
free(rpf); free(rpf);
@ -244,7 +244,7 @@ xbps_repository_pool_find_pkg(const char *pkg, bool bypattern, bool best)
assert(pkg != NULL); assert(pkg != NULL);
rpf = repo_find_pkg(pkg, bypattern, best, false); rpf = repo_find_pkg(pkg, bypattern, best, false);
if (rpf->pkgd != NULL) if (prop_object_type(rpf->pkgd) == PROP_TYPE_DICTIONARY)
pkgd = prop_dictionary_copy(rpf->pkgd); pkgd = prop_dictionary_copy(rpf->pkgd);
free(rpf); free(rpf);
@ -287,7 +287,7 @@ xbps_repository_pool_dictionary_metadata_plist(const char *pkgname,
out: out:
if (plistd == NULL) if (plistd == NULL)
errno = ENOENT; errno = ENOENT;
if (pkgd) if (prop_object_type(pkgd) == PROP_TYPE_DICTIONARY)
prop_object_release(pkgd); prop_object_release(pkgd);
return plistd; return plistd;

View File

@ -99,7 +99,7 @@ xbps_check_is_installed_pkg_by_name(const char *pkgname)
assert(pkgname != NULL); assert(pkgname != NULL);
pkgd = xbps_find_virtualpkg_dict_installed(pkgname, false); pkgd = xbps_find_virtualpkg_dict_installed(pkgname, false);
if (pkgd) { if (prop_object_type(pkgd) == PROP_TYPE_DICTIONARY) {
prop_object_release(pkgd); prop_object_release(pkgd);
return true; return true;
} }
@ -276,7 +276,8 @@ xbps_pkg_has_rundeps(prop_dictionary_t pkgd)
assert(prop_object_type(pkgd) == PROP_TYPE_DICTIONARY); assert(prop_object_type(pkgd) == PROP_TYPE_DICTIONARY);
array = prop_dictionary_get(pkgd, "run_depends"); array = prop_dictionary_get(pkgd, "run_depends");
if (array && prop_array_count(array) > 0) if ((prop_object_type(array) == PROP_TYPE_ARRAY) &&
prop_array_count(array) > 0)
return true; return true;
return false; return false;