Extensively verified that all functions have its return value

checked for any spurious error, this should make the core more safer :-)

--HG--
extra : convert_revision : xtraeme%40gmail.com-20091123094651-5prw0bkqmt3y8h23
This commit is contained in:
Juan RP 2009-11-23 09:46:51 +00:00
parent ea468f850f
commit bf82b6512d
17 changed files with 416 additions and 105 deletions

View File

@ -64,8 +64,16 @@ xbps_check_pkg_integrity_all(void)
return ENOENT;
while ((obj = prop_object_iterator_next(iter)) != NULL) {
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
if (!prop_dictionary_get_cstring_nocopy(obj,
"pkgname", &pkgname)) {
prop_object_iterator_release(iter);
return errno;
}
if (!prop_dictionary_get_cstring_nocopy(obj,
"version", &version)) {
prop_object_iterator_release(iter);
return errno;
}
printf("Checking %s-%s ...\n", pkgname, version);
if ((rv = xbps_check_pkg_integrity(pkgname)) != 0)
nbrokenpkgs++;
@ -177,7 +185,12 @@ xbps_check_pkg_integrity(const char *pkgname)
goto out2;
}
while ((obj = prop_object_iterator_next(iter))) {
prop_dictionary_get_cstring_nocopy(obj, "file", &file);
if (!prop_dictionary_get_cstring_nocopy(obj,
"file", &file)) {
prop_object_iterator_release(iter);
rv = errno;
goto out2;
}
path = xbps_xasprintf("%s/%s",
xbps_get_rootdir(), file);
if (path == NULL) {
@ -185,8 +198,13 @@ xbps_check_pkg_integrity(const char *pkgname)
rv = errno;
goto out2;
}
prop_dictionary_get_cstring_nocopy(obj,
"sha256", &sha256);
if (!prop_dictionary_get_cstring_nocopy(obj,
"sha256", &sha256)) {
free(path);
prop_object_iterator_release(iter);
rv = errno;
goto out2;
}
rv = xbps_check_file_hash(path, sha256);
switch (rv) {
case 0:
@ -227,7 +245,12 @@ xbps_check_pkg_integrity(const char *pkgname)
goto out2;
}
while ((obj = prop_object_iterator_next(iter))) {
prop_dictionary_get_cstring_nocopy(obj, "file", &file);
if (!prop_dictionary_get_cstring_nocopy(obj,
"file", &file)) {
prop_object_iterator_release(iter);
rv = errno;
goto out2;
}
path = xbps_xasprintf("%s/%s",
xbps_get_rootdir(), file);
if (path == NULL) {
@ -264,6 +287,11 @@ xbps_check_pkg_integrity(const char *pkgname)
}
while ((obj = prop_object_iterator_next(iter))) {
reqpkg = prop_string_cstring_nocopy(obj);
if (reqpkg == NULL) {
prop_object_iterator_release(iter);
rv = EINVAL;
goto out2;
}
if (xbps_check_is_installed_pkg(reqpkg) <= 0) {
rv = ENOENT;
printf("%s: dependency not satisfied: %s\n",

View File

@ -82,7 +82,10 @@ check_pkg_hashes(prop_object_iterator_t iter)
printf("Checking binary package file(s) integrity...\n");
while ((obj = prop_object_iterator_next(iter)) != NULL) {
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
if (!prop_dictionary_get_cstring_nocopy(obj,
"pkgname", &pkgname))
return errno;
state = 0;
if (xbps_get_pkg_state_dictionary(obj, &state) != 0)
return EINVAL;
@ -90,8 +93,12 @@ check_pkg_hashes(prop_object_iterator_t iter)
if (state == XBPS_PKG_STATE_UNPACKED)
continue;
prop_dictionary_get_cstring_nocopy(obj, "repository", &repoloc);
prop_dictionary_get_cstring_nocopy(obj, "filename", &filename);
if (!prop_dictionary_get_cstring_nocopy(obj,
"repository", &repoloc))
return errno;
if (!prop_dictionary_get_cstring_nocopy(obj,
"filename", &filename))
return errno;
rv = xbps_check_pkg_file_hash(obj, repoloc);
if (rv != 0 && rv != ERANGE) {
printf("Unexpected error while checking hash for "
@ -118,16 +125,24 @@ download_package_list(prop_object_iterator_t iter)
printf("Downloading binary package file(s)...\n");
while ((obj = prop_object_iterator_next(iter)) != NULL) {
prop_dictionary_get_cstring_nocopy(obj, "repository", &repoloc);
if (!prop_dictionary_get_cstring_nocopy(obj,
"repository", &repoloc))
return errno;
/*
* Skip packages in local repositories.
*/
if (!xbps_check_is_repo_string_remote(repoloc))
continue;
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
prop_dictionary_get_cstring_nocopy(obj, "filename", &filename);
prop_dictionary_get_cstring_nocopy(obj, "architecture", &arch);
if (!prop_dictionary_get_cstring_nocopy(obj,
"pkgver", &pkgver))
return errno;
if (!prop_dictionary_get_cstring_nocopy(obj,
"filename", &filename))
return errno;
if (!prop_dictionary_get_cstring_nocopy(obj,
"architecture", &arch))
return errno;
repoloc_trans = xbps_get_remote_repo_string(repoloc);
if (repoloc_trans == NULL)
@ -139,14 +154,12 @@ download_package_list(prop_object_iterator_t iter)
free(repoloc_trans);
return errno;
}
lbinfile = xbps_xasprintf("%s/%s", savedir, filename);
if (lbinfile == NULL) {
free(repoloc_trans);
free(savedir);
return errno;
}
if (access(lbinfile, R_OK) == 0) {
free(savedir);
free(lbinfile);
@ -182,7 +195,10 @@ change_repodir:
if (savedir == NULL)
return errno;
prop_dictionary_set_cstring(obj, "repository", savedir);
if (!prop_dictionary_set_cstring(obj, "repository", savedir)) {
free(savedir);
return errno;
}
free(savedir);
}
prop_object_iterator_reset(iter);
@ -199,8 +215,12 @@ show_package_list(prop_object_iterator_t iter, const char *match)
bool first = false;
while ((obj = prop_object_iterator_next(iter)) != NULL) {
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
prop_dictionary_get_cstring_nocopy(obj, "trans-action", &tract);
if (!prop_dictionary_get_cstring_nocopy(obj,
"pkgver", &pkgver))
return;
if (!prop_dictionary_get_cstring_nocopy(obj,
"trans-action", &tract))
return;
if (strcmp(match, tract))
continue;
@ -233,17 +253,24 @@ show_transaction_sizes(prop_object_iterator_t iter)
* installed and check the file hash.
*/
while ((obj = prop_object_iterator_next(iter)) != NULL) {
prop_dictionary_get_uint64(obj, "filename-size", &tsize);
if (!prop_dictionary_get_uint64(obj, "filename-size", &tsize))
return errno;
dlsize += tsize;
tsize = 0;
prop_dictionary_get_uint64(obj, "installed_size", &tsize);
if (!prop_dictionary_get_uint64(obj, "installed_size", &tsize))
return errno;
instsize += tsize;
tsize = 0;
}
prop_object_iterator_reset(iter);
while ((obj = prop_object_iterator_next(iter))) {
prop_dictionary_get_cstring_nocopy(obj, "trans-action", &tract);
if (!prop_dictionary_get_cstring_nocopy(obj,
"trans-action", &tract))
return errno;
if (strcmp(tract, "install") == 0)
trans_inst = true;
else if (strcmp(tract, "update") == 0)
@ -384,8 +411,11 @@ xbps_exec_transaction(const char *pkgname, bool force, bool update)
goto out2;
}
prop_dictionary_get_cstring_nocopy(trans->dict,
"origin", &trans->originpkgname);
if (!prop_dictionary_get_cstring_nocopy(trans->dict,
"origin", &trans->originpkgname)) {
rv = errno;
goto out2;
}
if (update) {
/*
@ -434,6 +464,9 @@ replace_packages(prop_object_iterator_t iter, const char *pkgver)
*/
while ((obj = prop_object_iterator_next(iter))) {
reppkgn = prop_string_cstring_nocopy(obj);
if (reppkgn == NULL)
return errno;
instd = xbps_find_pkg_installed_from_plist(reppkgn);
if (instd == NULL)
continue;
@ -505,12 +538,22 @@ exec_transaction(struct transaction *trans)
* Iterate over the transaction dictionary.
*/
while ((obj = prop_object_iterator_next(trans->iter)) != NULL) {
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
if (!prop_dictionary_get_cstring_nocopy(obj,
"pkgname", &pkgname))
return errno;
if (!prop_dictionary_get_cstring_nocopy(obj,
"version", &version))
return errno;
if (!prop_dictionary_get_cstring_nocopy(obj,
"pkgver", &pkgver))
return errno;
prop_dictionary_get_bool(obj, "essential", &essential);
prop_dictionary_get_cstring_nocopy(obj, "filename", &filename);
prop_dictionary_get_cstring_nocopy(obj, "trans-action", &tract);
if (!prop_dictionary_get_cstring_nocopy(obj,
"filename", &filename))
return errno;
if (!prop_dictionary_get_cstring_nocopy(obj,
"trans-action", &tract))
return errno;
replaces_iter = xbps_get_array_iter_from_dict(obj, "replaces");
/*
@ -556,11 +599,17 @@ exec_transaction(struct transaction *trans)
return EINVAL;
}
prop_dictionary_get_cstring_nocopy(instpkgd,
"version", &instver);
if (!prop_dictionary_get_cstring_nocopy(instpkgd,
"version", &instver)) {
prop_object_release(instpkgd);
return errno;
}
autoinst = false;
prop_dictionary_get_bool(instpkgd, "automatic-install",
&autoinst);
if (!prop_dictionary_get_bool(instpkgd,
"automatic-install", &autoinst)) {
prop_object_release(instpkgd);
return errno;
}
prop_object_release(instpkgd);
/*
@ -618,8 +667,12 @@ exec_transaction(struct transaction *trans)
* Configure all unpacked packages.
*/
while ((obj = prop_object_iterator_next(trans->iter)) != NULL) {
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
if (!prop_dictionary_get_cstring_nocopy(obj,
"pkgname", &pkgname))
return errno;
if (!prop_dictionary_get_cstring_nocopy(obj,
"version", &version))
return errno;
if ((rv = xbps_configure_pkg(pkgname, version, false)) != 0) {
printf("Error configuring package %s (%s)\n",
pkgname, strerror(rv));

View File

@ -68,7 +68,11 @@ xbps_autoremove_pkgs(void)
printf("The following packages were installed automatically\n"
"(as dependencies) and aren't needed anymore:\n\n");
while ((obj = prop_object_iterator_next(iter)) != NULL) {
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
if (!prop_dictionary_get_cstring_nocopy(obj,
"pkgver", &pkgver)) {
rv = errno;
goto out2;
}
cols += strlen(pkgver) + 4;
if (cols <= 80) {
if (first == false) {
@ -90,8 +94,16 @@ xbps_autoremove_pkgs(void)
}
while ((obj = prop_object_iterator_next(iter)) != NULL) {
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
if (!prop_dictionary_get_cstring_nocopy(obj,
"pkgname", &pkgname)) {
rv = errno;
goto out2;
}
if (!prop_dictionary_get_cstring_nocopy(obj,
"version", &version)) {
rv = errno;
goto out;
}
printf("Removing package %s-%s ...\n", pkgname, version);
if ((rv = xbps_remove_pkg(pkgname, version, false)) != 0)
goto out2;
@ -120,7 +132,8 @@ xbps_remove_installed_pkg(const char *pkgname, bool force)
printf("Package %s is not installed.\n", pkgname);
return 0;
}
prop_dictionary_get_cstring_nocopy(dict, "version", &version);
if (!prop_dictionary_get_cstring_nocopy(dict, "version", &version))
return errno;
reqby = prop_dictionary_get(dict, "requiredby");
if (reqby != NULL && prop_array_count(reqby) > 0) {

View File

@ -61,10 +61,17 @@ repoidx_getdict(const char *pkgdir)
goto out;
}
prop_dictionary_set(dict, "packages", array);
if (!prop_dictionary_set(dict, "packages", array)) {
prop_object_release(dict);
prop_object_release(array);
goto out;
}
prop_object_release(array);
prop_dictionary_set_cstring_nocopy(dict,
"pkgindex-version", XBPS_PKGINDEX_VERSION);
if (!prop_dictionary_set_cstring_nocopy(dict,
"pkgindex-version", XBPS_PKGINDEX_VERSION)) {
prop_object_release(dict);
goto out;
}
}
out:
free(plist);
@ -128,10 +135,18 @@ xbps_repo_addpkg_index(prop_dictionary_t idxdict, const char *file)
break;
}
prop_dictionary_get_cstring_nocopy(newpkgd, "pkgname",
&pkgname);
prop_dictionary_get_cstring_nocopy(newpkgd, "version",
&version);
if (!prop_dictionary_get_cstring_nocopy(newpkgd, "pkgname",
&pkgname)) {
prop_object_release(newpkgd);
rv = errno;
break;
}
if (!prop_dictionary_get_cstring_nocopy(newpkgd, "version",
&version)) {
prop_object_release(newpkgd);
rv = errno;
break;
}
/*
* Check if this package exists already in the index, but first
* checking the version. If current package version is greater
@ -140,8 +155,12 @@ xbps_repo_addpkg_index(prop_dictionary_t idxdict, const char *file)
*/
curpkgd = xbps_find_pkg_in_dict(idxdict, "packages", pkgname);
if (curpkgd) {
prop_dictionary_get_cstring_nocopy(curpkgd,
"version", &regver);
if (!prop_dictionary_get_cstring_nocopy(curpkgd,
"version", &regver)) {
prop_object_release(newpkgd);
rv = errno;
break;
}
if (xbps_cmpver(version, regver) <= 0) {
printf("W: skipping %s. %s-%s already "
"registered.\n", filen, pkgname, regver);
@ -167,14 +186,24 @@ xbps_repo_addpkg_index(prop_dictionary_t idxdict, const char *file)
* We have the dictionary now, add the required
* objects for the index.
*/
prop_dictionary_set_cstring(newpkgd, "filename", filen);
if (!prop_dictionary_set_cstring(newpkgd, "filename", filen)) {
prop_object_release(newpkgd);
rv = errno;
break;
}
sha256 = xbps_get_file_hash(file);
if (sha256 == NULL) {
prop_object_release(newpkgd);
rv = errno;
break;
}
prop_dictionary_set_cstring(newpkgd, "filename-sha256", sha256);
if (!prop_dictionary_set_cstring(newpkgd,
"filename-sha256", sha256)) {
prop_object_release(newpkgd);
free(sha256);
rv = errno;
break;
}
free(sha256);
if (stat(file, &st) == -1) {
@ -182,8 +211,12 @@ xbps_repo_addpkg_index(prop_dictionary_t idxdict, const char *file)
rv = errno;
break;
}
prop_dictionary_set_uint64(newpkgd, "filename-size",
(uint64_t)st.st_size);
if (!prop_dictionary_set_uint64(newpkgd, "filename-size",
(uint64_t)st.st_size)) {
prop_object_release(newpkgd);
rv = errno;
break;
}
/*
* Add dictionary into the index and update package count.
*/
@ -199,8 +232,13 @@ xbps_repo_addpkg_index(prop_dictionary_t idxdict, const char *file)
rv = EINVAL;
break;
}
prop_dictionary_set_uint64(idxdict, "total-pkgs",
prop_array_count(pkgar));
if (!prop_dictionary_set_uint64(idxdict, "total-pkgs",
prop_array_count(pkgar))) {
prop_object_release(newpkgd);
rv = errno;
break;
}
prop_object_release(newpkgd);
printf("Registered %s-%s in package index.\n",
pkgname, version);
printf("\033[1A\033[K");

View File

@ -207,7 +207,12 @@ show_pkg_files_from_metadir(const char *pkgname)
goto out;
}
while ((obj = prop_object_iterator_next(iter))) {
prop_dictionary_get_cstring_nocopy(obj, "file", &file);
if (!prop_dictionary_get_cstring_nocopy(obj,
"file", &file)) {
prop_object_iterator_release(iter);
rv = errno;
goto out;
}
printf("%s\n", file);
}
prop_object_iterator_release(iter);
@ -230,7 +235,12 @@ show_pkg_files_from_metadir(const char *pkgname)
goto out;
}
while ((obj = prop_object_iterator_next(iter))) {
prop_dictionary_get_cstring_nocopy(obj, "file", &file);
if (!prop_dictionary_get_cstring_nocopy(obj,
"file", &file)) {
prop_object_iterator_release(iter);
rv = errno;
goto out;
}
printf("%s\n", file);
}
prop_object_iterator_release(iter);

View File

@ -52,8 +52,16 @@ xbps_configure_all_pkgs(void)
return ENOENT;
while ((obj = prop_object_iterator_next(iter)) != NULL) {
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
if (!prop_dictionary_get_cstring_nocopy(obj,
"pkgname", &pkgname)) {
rv = errno;
break;
}
if (!prop_dictionary_get_cstring_nocopy(obj,
"version", &version)) {
rv = errno;
break;
}
if ((rv = xbps_get_pkg_state_dictionary(obj, &state)) != 0)
break;
if (state != XBPS_PKG_STATE_UNPACKED)
@ -102,7 +110,11 @@ xbps_configure_pkg(const char *pkgname, const char *version, bool check_state)
if (pkgd == NULL)
return ENOENT;
prop_dictionary_get_cstring_nocopy(pkgd, "version", &lver);
if (!prop_dictionary_get_cstring_nocopy(pkgd,
"version", &lver)) {
prop_object_release(pkgd);
return errno;
}
prop_object_release(pkgd);
} else {
lver = version;

View File

@ -50,7 +50,8 @@ store_dependency(prop_dictionary_t master, prop_dictionary_t depd,
/*
* Get some info about dependencies and current repository.
*/
prop_dictionary_get_cstring_nocopy(depd, "pkgname", &pkgname);
if (!prop_dictionary_get_cstring_nocopy(depd, "pkgname", &pkgname))
return errno;
dict = prop_dictionary_copy(depd);
if (dict == NULL)
@ -84,7 +85,10 @@ store_dependency(prop_dictionary_t master, prop_dictionary_t depd,
/*
* Add required objects into package dep's dictionary.
*/
prop_dictionary_set_cstring(dict, "repository", repoloc);
if (!prop_dictionary_set_cstring(dict, "repository", repoloc)) {
prop_object_release(dict);
return errno;
}
/*
* Remove some unneeded objects.
*/
@ -121,9 +125,14 @@ add_missing_reqdep(prop_dictionary_t master, const char *pkgname,
return errno;
missing_rdeps = prop_dictionary_get(master, "missing_deps");
prop_dictionary_set_cstring(mdepd, "pkgname", pkgname);
prop_dictionary_set_cstring(mdepd, "version", version);
if (!prop_dictionary_set_cstring(mdepd, "pkgname", pkgname)) {
prop_object_release(mdepd);
return errno;
}
if (!prop_dictionary_set_cstring(mdepd, "version", version)) {
prop_object_release(mdepd);
return errno;
}
if (!xbps_add_obj_to_array(missing_rdeps, mdepd)) {
prop_object_release(mdepd);
return EINVAL;
@ -147,7 +156,9 @@ xbps_find_deps_in_pkg(prop_dictionary_t master, prop_dictionary_t pkg)
if (pkg_rdeps == NULL)
return 0;
prop_dictionary_get_cstring_nocopy(pkg, "pkgname", &pkgname);
if (!prop_dictionary_get_cstring_nocopy(pkg, "pkgname", &pkgname))
return errno;
DPRINTF(("Checking rundeps for %s.\n", pkgname));
/*
* Iterate over the repository pool and find out if we have
@ -213,6 +224,10 @@ find_repo_deps(prop_dictionary_t master, prop_dictionary_t repo,
*/
while ((obj = prop_object_iterator_next(iter)) != NULL) {
reqpkg = prop_string_cstring_nocopy(obj);
if (reqpkg == NULL) {
rv = EINVAL;
break;
}
/*
* Check if required dep is satisfied and installed.
*/

View File

@ -156,6 +156,11 @@ xbps_prepare_repolist_data(void)
}
rdata->rd_uri = prop_string_cstring(obj);
if (rdata->rd_uri == NULL) {
free(plist);
rv = EINVAL;
goto out2;
}
rdata->rd_repod = prop_dictionary_internalize_from_file(plist);
if (rdata->rd_repod == NULL) {
free(plist);
@ -225,7 +230,11 @@ xbps_find_new_packages(void)
* installed packages.
*/
while ((obj = prop_object_iterator_next(iter)) != NULL) {
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
if (!prop_dictionary_get_cstring_nocopy(obj,
"pkgname", &pkgname)) {
rv = errno;
break;
}
rv = xbps_find_new_pkg(pkgname, obj);
if (rv == ENOENT)
continue;
@ -276,10 +285,16 @@ xbps_find_new_pkg(const char *pkgname, prop_dictionary_t instpkg)
* Check if version in repository is greater than
* the version currently installed.
*/
prop_dictionary_get_cstring_nocopy(instpkg,
"version", &instver);
prop_dictionary_get_cstring_nocopy(pkgrd,
"version", &repover);
if (!prop_dictionary_get_cstring_nocopy(instpkg,
"version", &instver)) {
rv = errno;
break;
}
if (!prop_dictionary_get_cstring_nocopy(pkgrd,
"version", &repover)) {
rv = errno;
break;
}
if (xbps_cmpver(repover, instver) > 0) {
DPRINTF(("Found %s-%s in repo %s.\n",
pkgname, repover, rdata->rd_uri));
@ -307,7 +322,10 @@ xbps_find_new_pkg(const char *pkgname, prop_dictionary_t instpkg)
/*
* Set repository in pkg dictionary.
*/
prop_dictionary_set_cstring(pkgrd, "repository", rdata->rd_uri);
if (!prop_dictionary_set_cstring(pkgrd, "repository", rdata->rd_uri)) {
rv = errno;
goto out;
}
/*
* Construct the dependency chain for this package.
@ -332,7 +350,11 @@ xbps_find_new_pkg(const char *pkgname, prop_dictionary_t instpkg)
if ((rv = set_pkg_state(pkgrd, pkgname)) != 0)
goto out;
prop_dictionary_set_cstring_nocopy(pkgrd, "trans-action", "update");
if (!prop_dictionary_set_cstring_nocopy(pkgrd,
"trans-action", "update")) {
rv = errno;
goto out;
}
if (!prop_array_add(unsorted, pkgrd))
rv = errno;
@ -405,8 +427,14 @@ xbps_prepare_pkg(const char *pkgname)
/*
* Set repository in pkg dictionary.
*/
prop_dictionary_set_cstring(pkgrd, "repository", rdata->rd_uri);
prop_dictionary_set_cstring(pkg_props, "origin", pkgname);
if (!prop_dictionary_set_cstring(pkgrd, "repository", rdata->rd_uri)) {
rv = errno;
goto out;
}
if (!prop_dictionary_set_cstring(pkg_props, "origin", pkgname)) {
rv = errno;
goto out;
}
/*
* Check if this package needs dependencies.
@ -458,7 +486,11 @@ xbps_prepare_pkg(const char *pkgname)
if ((rv = set_pkg_state(pkgrd, pkgname)) != 0)
goto out;
prop_dictionary_set_cstring_nocopy(pkgrd, "trans-action", "install");
if (!prop_dictionary_set_cstring_nocopy(pkgrd,
"trans-action", "install")) {
rv = errno;
goto out;
}
if (!prop_array_add(pkgs_array, pkgrd))
rv = errno;

View File

@ -83,6 +83,9 @@ find_orphan_pkg(prop_object_t obj, void *arg, bool *loop_done)
while ((obj2 = prop_object_iterator_next(iter)) != NULL) {
pkgname = xbps_get_pkg_name(prop_string_cstring_nocopy(obj2));
if (pkgname == NULL)
return EINVAL;
SIMPLEQ_FOREACH(orphan, &orphan_list, chain) {
if (strcmp(orphan->pkgname, pkgname) == 0) {
ndep++;
@ -101,7 +104,11 @@ add_orphan:
if (orphan == NULL)
return errno;
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &orphan->pkgname);
if (!prop_dictionary_get_cstring_nocopy(obj, "pkgname",
&orphan->pkgname)) {
free(orphan);
return errno;
}
orphan->dict = prop_dictionary_copy(obj);
SIMPLEQ_INSERT_TAIL(&orphan_list, orphan, chain);
@ -151,7 +158,10 @@ xbps_find_orphan_packages(void)
return NULL;
}
while ((orphan = SIMPLEQ_FIRST(&orphan_list)) != NULL) {
prop_array_add(array, orphan->dict);
if (!prop_array_add(array, orphan->dict)) {
cleanup();
return NULL;
}
SIMPLEQ_REMOVE(&orphan_list, orphan, orphan_pkg, chain);
prop_object_release(orphan->dict);
free(orphan);

View File

@ -372,8 +372,11 @@ xbps_remove_pkg_from_dict(prop_dictionary_t dict, const char *key,
/* Iterate over the array of dictionaries to find its index. */
while ((obj = prop_object_iterator_next(iter))) {
prop_dictionary_get_cstring_nocopy(obj, "pkgname",
&curpkgname);
if (!prop_dictionary_get_cstring_nocopy(obj, "pkgname",
&curpkgname)) {
prop_object_iterator_release(iter);
return errno;
}
if ((curpkgname && (strcmp(curpkgname, pkgname) == 0))) {
found = true;
break;

View File

@ -53,7 +53,11 @@ xbps_purge_all_pkgs(void)
return ENOENT;
while ((obj = prop_object_iterator_next(iter)) != NULL) {
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
if (!prop_dictionary_get_cstring_nocopy(obj,
"pkgname", &pkgname)) {
rv = errno;
break;
}
if ((rv = xbps_get_pkg_state_dictionary(obj, &state)) != 0)
break;
if (state != XBPS_PKG_STATE_CONFIG_FILES)
@ -139,7 +143,12 @@ xbps_purge_pkg(const char *pkgname, bool check_state)
prop_object_release(dict);
return EINVAL;
}
prop_dictionary_get_cstring_nocopy(obj, "sha256", &sha256);
if (!prop_dictionary_get_cstring_nocopy(obj,
"sha256", &sha256)) {
prop_object_iterator_release(iter);
prop_object_release(dict);
return errno;
}
rv = xbps_check_file_hash(path, sha256);
if (rv == ENOENT) {
printf("Configuration file %s doesn't exist!\n", file);

View File

@ -68,10 +68,30 @@ xbps_register_pkg(prop_dictionary_t pkgrd, bool automatic)
rv = ENOENT;
goto out;
}
prop_dictionary_set_cstring_nocopy(pkgd, "version", version);
prop_dictionary_set_cstring_nocopy(pkgd, "pkgver", pkgver);
prop_dictionary_set_cstring_nocopy(pkgd, "short_desc", desc);
prop_dictionary_set_bool(pkgd, "automatic-install", automatic);
if (!prop_dictionary_set_cstring_nocopy(pkgd,
"version", version)) {
prop_object_release(pkgd);
rv = errno;
goto out;
}
if (!prop_dictionary_set_cstring_nocopy(pkgd,
"pkgver", pkgver)) {
prop_object_release(pkgd);
rv = errno;
goto out;
}
if (!prop_dictionary_set_cstring_nocopy(pkgd,
"short_desc", desc)) {
prop_object_release(pkgd);
rv = errno;
goto out;
}
if (!prop_dictionary_set_bool(pkgd,
"automatic-install", automatic)) {
prop_object_release(pkgd);
rv = errno;
goto out;
}
/*
* Add the requiredby objects for dependent packages.

View File

@ -101,7 +101,12 @@ files:
prop_object_iterator_release(iter);
return EINVAL;
}
prop_dictionary_get_cstring_nocopy(obj, "sha256", &sha256);
if (!prop_dictionary_get_cstring_nocopy(obj,
"sha256", &sha256)) {
prop_object_iterator_release(iter);
free(path);
return errno;
}
rv = xbps_check_file_hash(path, sha256);
if (rv == ENOENT) {
printf("WARNING: '%s' doesn't exist!\n", file);

View File

@ -101,6 +101,11 @@ remove_pkg_from_reqby(prop_object_t obj, void *arg, bool *loop_done)
while ((obj2 = prop_object_iterator_next(iter)) != NULL) {
curpkgname =
xbps_get_pkg_name(prop_string_cstring_nocopy(obj2));
if (curpkgname == NULL) {
prop_object_iterator_release(iter);
return EINVAL;
}
if (strcmp(curpkgname, pkgname) == 0) {
free(curpkgname);
found = true;
@ -157,7 +162,8 @@ xbps_requiredby_pkg_add(prop_array_t regar, prop_dictionary_t pkg)
char *rdepname;
int rv = 0;
prop_dictionary_get_cstring_nocopy(pkg, "pkgver", &pkgver);
if (!prop_dictionary_get_cstring_nocopy(pkg, "pkgver", &pkgver))
return errno;
rdeps = prop_dictionary_get(pkg, "run_depends");
if (rdeps == NULL || prop_array_count(rdeps) == 0)
@ -169,7 +175,15 @@ xbps_requiredby_pkg_add(prop_array_t regar, prop_dictionary_t pkg)
while ((obj = prop_object_iterator_next(iter)) != NULL) {
str = prop_string_cstring_nocopy(obj);
if (str == NULL) {
rv = errno;
goto out;
}
rdepname = xbps_get_pkgdep_name(str);
if (rdepname == NULL) {
rv = EINVAL;
goto out;
}
iter2 = prop_array_iterator(regar);
if (iter2 == NULL) {
free(rdepname);
@ -182,8 +196,13 @@ xbps_requiredby_pkg_add(prop_array_t regar, prop_dictionary_t pkg)
* current run dependency.
*/
while ((obj2 = prop_object_iterator_next(iter2)) != NULL) {
prop_dictionary_get_cstring_nocopy(obj2, "pkgname",
&reqname);
if (!prop_dictionary_get_cstring_nocopy(obj2,
"pkgname", &reqname)) {
free(rdepname);
prop_object_iterator_release(iter2);
rv = errno;
goto out;
}
if (strcmp(rdepname, reqname) == 0) {
rv = add_pkg_into_reqby(obj2, pkgver);
if (rv == EEXIST)

View File

@ -80,9 +80,7 @@ xbps_sort_pkg_deps(prop_dictionary_t chaindeps)
prop_dictionary_set(chaindeps, "packages", sorted);
return 0;
}
ndeps = prop_array_count(unsorted);
unsorted = prop_dictionary_get(chaindeps, "unsorted_deps");
iter = prop_array_iterator(unsorted);
if (iter == NULL) {
@ -94,7 +92,11 @@ again:
* Order all deps by looking at its run_depends array.
*/
while ((obj = prop_object_iterator_next(iter)) != NULL) {
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
if (!prop_dictionary_get_cstring_nocopy(obj,
"pkgname", &pkgname)) {
rv = errno;
goto out;
}
if (find_sorteddep_by_name(pkgname) != NULL)
continue;
@ -126,7 +128,17 @@ again:
*/
while ((obj2 = prop_object_iterator_next(iter2)) != NULL) {
str = prop_string_cstring_nocopy(obj2);
if (str == NULL) {
free(sdep);
rv = EINVAL;
goto out;
}
curpkgnamedep = xbps_get_pkgdep_name(str);
if (curpkgnamedep == NULL) {
free(sdep);
rv = EINVAL;
goto out;
}
/*
* If dependency is already installed or queued,
* pass to the next one.
@ -163,7 +175,11 @@ again:
* Add all sorted dependencies into the sorted deps array.
*/
while ((sdep = SIMPLEQ_FIRST(&sdep_list)) != NULL) {
prop_array_add(sorted, sdep->dict);
if (!prop_array_add(sorted, sdep->dict)) {
free(sdep);
rv = errno;
goto out;
}
SIMPLEQ_REMOVE(&sdep_list, sdep, sorted_dependency, chain);
prop_object_release(sdep->dict);
free(sdep);

View File

@ -72,8 +72,7 @@ get_state(prop_dictionary_t dict)
assert(dict != NULL);
prop_dictionary_get_cstring_nocopy(dict, "state", &state_str);
if (state_str == NULL)
if (!prop_dictionary_get_cstring_nocopy(dict, "state", &state_str))
return 0;
if (strcmp(state_str, "unpacked") == 0)
@ -177,7 +176,12 @@ xbps_set_pkg_state_installed(const char *pkgname, pkg_state_t state)
rv = errno;
goto out;
}
prop_dictionary_set_cstring_nocopy(pkgd, "pkgname", pkgname);
if (!prop_dictionary_set_cstring_nocopy(pkgd, "pkgname",
pkgname)) {
prop_object_release(array);
rv = errno;
goto out;
}
if ((rv = set_new_state(pkgd, state)) != 0) {
prop_object_release(array);
goto out;
@ -198,8 +202,12 @@ xbps_set_pkg_state_installed(const char *pkgname, pkg_state_t state)
if (pkgd == NULL) {
newpkg = true;
pkgd = prop_dictionary_create();
prop_dictionary_set_cstring_nocopy(pkgd, "pkgname",
pkgname);
if (!prop_dictionary_set_cstring_nocopy(pkgd,
"pkgname", pkgname)) {
prop_object_release(pkgd);
rv = errno;
goto out;
}
}
array = prop_dictionary_get(dict, "packages");
if (array == NULL) {

View File

@ -50,7 +50,9 @@ xbps_unpack_binary_pkg(prop_dictionary_t pkg, bool essential)
/*
* Append filename to the full path for binary pkg.
*/
prop_dictionary_get_cstring_nocopy(pkg, "pkgname", &pkgname);
if (!prop_dictionary_get_cstring_nocopy(pkg, "pkgname", &pkgname))
return errno;
filename = prop_dictionary_get(pkg, "filename");
arch = prop_dictionary_get(pkg, "architecture");
repoloc = prop_dictionary_get(pkg, "repository");
@ -172,8 +174,12 @@ install_config_file(prop_dictionary_t d, struct archive_entry *entry,
iter2 = xbps_get_array_iter_from_dict(forigd, "conf_files");
if (iter2 != NULL) {
while ((obj2 = prop_object_iterator_next(iter2))) {
prop_dictionary_get_cstring_nocopy(obj2,
"file", &cffile);
if (!prop_dictionary_get_cstring_nocopy(obj2,
"file", &cffile)) {
prop_object_iterator_release(iter2);
rv = errno;
goto out;
}
buf = xbps_xasprintf(".%s", cffile);
if (buf == NULL) {
prop_object_iterator_release(iter2);
@ -204,7 +210,11 @@ install_config_file(prop_dictionary_t d, struct archive_entry *entry,
* Compare original, installed and new hash for current file.
*/
while ((obj = prop_object_iterator_next(iter))) {
prop_dictionary_get_cstring_nocopy(obj, "file", &cffile);
if (!prop_dictionary_get_cstring_nocopy(obj,
"file", &cffile)) {
prop_object_iterator_release(iter);
return errno;
}
buf = xbps_xasprintf(".%s", cffile);
if (buf == NULL) {
prop_object_iterator_release(iter);
@ -217,8 +227,8 @@ install_config_file(prop_dictionary_t d, struct archive_entry *entry,
}
sha256_cur = xbps_get_file_hash(buf);
free(buf);
prop_dictionary_get_cstring_nocopy(obj, "sha256", &sha256_new);
if (sha256_new == NULL) {
if (!prop_dictionary_get_cstring_nocopy(obj,
"sha256", &sha256_new)) {
rv = EINVAL;
break;
}
@ -341,8 +351,10 @@ unpack_archive_fini(struct archive *ar, prop_dictionary_t pkg,
if (chdir(rootdir) == -1)
return errno;
prop_dictionary_get_cstring_nocopy(pkg, "pkgname", &pkgname);
prop_dictionary_get_cstring_nocopy(pkg, "version", &version);
if (!prop_dictionary_get_cstring_nocopy(pkg, "pkgname", &pkgname))
return errno;
if (!prop_dictionary_get_cstring_nocopy(pkg, "version", &version))
return errno;
while (archive_read_next_header(ar, &entry) == ARCHIVE_OK) {
entry_str = archive_entry_pathname(entry);
@ -536,8 +548,16 @@ again:
while ((obj = prop_object_iterator_next(iter))) {
found = false;
oldstr = prop_dictionary_get(obj, "file");
if (oldstr == NULL) {
rv = errno;
goto out;
}
while ((obj2 = prop_object_iterator_next(iter2))) {
newstr = prop_dictionary_get(obj2, "file");
if (newstr == NULL) {
rv = errno;
goto out;
}
if (prop_string_equals(oldstr, newstr)) {
found = true;
break;