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

@@ -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;