Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions lib/package_config_files.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ xbps_entry_is_a_conf_file(xbps_dictionary_t filesd,

for (unsigned int i = 0; i < xbps_array_count(array); i++) {
d = xbps_array_get(array, i);
xbps_dictionary_get_cstring_nocopy(d, "file", &cffile);
if (!xbps_dictionary_get_cstring_nocopy(d, "file", &cffile))
continue;
if (strcmp(cffile, entry_pname) == 0)
return true;
}
Expand Down Expand Up @@ -115,8 +116,9 @@ xbps_entry_install_conf_file(struct xbps_handle *xhp,
iter2 = xbps_array_iter_from_dict(pkg_filesd, "conf_files");
if (iter2 != NULL) {
while ((obj2 = xbps_object_iterator_next(iter2))) {
xbps_dictionary_get_cstring_nocopy(obj2,
"file", &cffile);
if (!xbps_dictionary_get_cstring_nocopy(obj2,
"file", &cffile))
continue;
snprintf(buf, sizeof(buf), ".%s", cffile);
if (strcmp(entry_pname, buf) == 0) {
xbps_dictionary_get_cstring_nocopy(obj2, "sha256", &sha256_orig);
Expand All @@ -139,7 +141,8 @@ xbps_entry_install_conf_file(struct xbps_handle *xhp,
* Compare original, installed and new hash for current file.
*/
while ((obj = xbps_object_iterator_next(iter))) {
xbps_dictionary_get_cstring_nocopy(obj, "file", &cffile);
if (!xbps_dictionary_get_cstring_nocopy(obj, "file", &cffile))
continue;
snprintf(buf, sizeof(buf), ".%s", cffile);
if (strcmp(entry_pname, buf)) {
continue;
Expand All @@ -158,7 +161,8 @@ xbps_entry_install_conf_file(struct xbps_handle *xhp,
break;
}
}
xbps_dictionary_get_cstring_nocopy(obj, "sha256", &sha256_new);
if (!xbps_dictionary_get_cstring_nocopy(obj, "sha256", &sha256_new))
continue;
/*
* Orig = X, Curr = X, New = X
*
Expand Down
23 changes: 17 additions & 6 deletions lib/transaction_files.c
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,10 @@ collect_files(struct xbps_handle *xhp, xbps_dictionary_t d,
if ((a = xbps_dictionary_get(d, "files"))) {
for (i = 0; i < xbps_array_count(a); i++) {
filed = xbps_array_get(a, i);
xbps_dictionary_get_cstring_nocopy(filed, "file", &file);
if (!xbps_dictionary_get_cstring_nocopy(filed, "file", &file)) {
rv = EINVAL;
goto out;
}
if (removefile)
xbps_dictionary_get_cstring_nocopy(filed, "sha256", &sha256);
size = 0;
Expand All @@ -603,7 +606,10 @@ collect_files(struct xbps_handle *xhp, xbps_dictionary_t d,
if ((a = xbps_dictionary_get(d, "conf_files"))) {
for (i = 0; i < xbps_array_count(a); i++) {
filed = xbps_array_get(a, i);
xbps_dictionary_get_cstring_nocopy(filed, "file", &file);
if (!xbps_dictionary_get_cstring_nocopy(filed, "file", &file)) {
rv = EINVAL;
goto out;
}
size = 0;
xbps_dictionary_get_uint64(filed, "size", &size);
if (removefile)
Expand All @@ -627,9 +633,11 @@ collect_files(struct xbps_handle *xhp, xbps_dictionary_t d,
for (i = 0; i < xbps_array_count(a); i++) {
const char *target = NULL;
filed = xbps_array_get(a, i);
xbps_dictionary_get_cstring_nocopy(filed, "file", &file);
xbps_dictionary_get_cstring_nocopy(filed, "target", &target);
assert(target);
if (!xbps_dictionary_get_cstring_nocopy(filed, "file", &file) ||
!xbps_dictionary_get_cstring_nocopy(filed, "target", &target)) {
rv = EINVAL;
goto out;
}
rv = collect_file(xhp, file, 0, pkgname, pkgver, idx, NULL,
TYPE_LINK, update, removepkg, preserve, removefile, target);
if (rv == EEXIST) {
Expand All @@ -643,7 +651,10 @@ collect_files(struct xbps_handle *xhp, xbps_dictionary_t d,
if ((a = xbps_dictionary_get(d, "dirs"))) {
for (i = 0; i < xbps_array_count(a); i++) {
filed = xbps_array_get(a, i);
xbps_dictionary_get_cstring_nocopy(filed, "file", &file);
if (!xbps_dictionary_get_cstring_nocopy(filed, "file", &file)) {
rv = EINVAL;
goto out;
}
rv = collect_file(xhp, file, 0, pkgname, pkgver, idx, NULL,
TYPE_DIR, update, removepkg, preserve, removefile, NULL);
if (rv == EEXIST) {
Expand Down
5 changes: 3 additions & 2 deletions lib/util_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,9 @@ file_hash_dictionary(xbps_dictionary_t d, const char *key, const char *file)
return NULL;
}
while ((obj = xbps_object_iterator_next(iter)) != NULL) {
xbps_dictionary_get_cstring_nocopy(obj,
"file", &curfile);
if (!xbps_dictionary_get_cstring_nocopy(obj,
"file", &curfile))
continue;
if (strcmp(file, curfile) == 0) {
/* file matched */
xbps_dictionary_get_cstring_nocopy(obj,
Expand Down
24 changes: 24 additions & 0 deletions tests/xbps/libxbps/shell/install_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,29 @@ install_empty_body() {
atf_check_equal $rv 0
}

atf_test_case install_malformed_files_plist

install_malformed_files_plist_head() {
atf_set "descr" "Tests for pkg installations: files.plist entry without a file key"
}

install_malformed_files_plist_body() {
mkdir -p repo pkg_A/usr/bin
echo A > pkg_A/usr/bin/foo
cd repo
xbps-create --compression none -A noarch -n A-1.0_1 -s "A pkg" ../pkg_A
atf_check_equal $? 0
# rename the file keys in files.plist; the replacement has the same
# length, so the uncompressed archive stays valid.
sed -e 's,<key>file</key>,<key>nope</key>,' -i A-1.0_1.noarch.xbps
atf_check_equal $? 0
xbps-rindex -d -a $PWD/*.xbps
atf_check_equal $? 0
cd ..
xbps-install -C empty.conf -r root --repository=$PWD/repo -yd A
atf_check_equal $? 22
}

atf_test_case install_with_deps

install_with_deps_head() {
Expand Down Expand Up @@ -774,6 +797,7 @@ update_issue_218_body() {

atf_init_test_cases() {
atf_add_test_case install_empty
atf_add_test_case install_malformed_files_plist
atf_add_test_case install_with_deps
atf_add_test_case install_with_vpkg_deps
atf_add_test_case install_if_not_installed_on_update
Expand Down