repo: fix a double free with invalid repodata.

Fixes #248

Added new test case to verify.
This commit is contained in:
Juan RP 2020-03-31 18:36:04 +02:00
parent 743e76938f
commit bd707acfee
No known key found for this signature in database
GPG Key ID: AF19F6CB482F9368
5 changed files with 31 additions and 4 deletions

View File

@ -156,7 +156,6 @@ repo_open_local(struct xbps_repo *repo, const char *repofile)
xbps_dbg_printf(repo->xhp,
"[repo] `%s' failed to open repodata archive %s\n",
repofile, strerror(rv));
xbps_repo_close(repo);
return false;
}
if ((repo->idx = repo_get_dict(repo)) == NULL) {
@ -164,7 +163,6 @@ repo_open_local(struct xbps_repo *repo, const char *repofile)
" index on archive, removing file.\n", repofile);
/* broken archive, remove it */
(void)unlink(repofile);
xbps_repo_close(repo);
return false;
}
xbps_dictionary_make_immutable(repo->idx);
@ -368,7 +366,8 @@ xbps_repo_open(struct xbps_handle *xhp, const char *url)
void
xbps_repo_close(struct xbps_repo *repo)
{
assert(repo);
if (!repo)
return;
if (repo->ar != NULL)
archive_read_finish(repo->ar);

View File

@ -29,3 +29,4 @@ atf_test_program{name="preserve_test"}
atf_test_program{name="orphans_test"}
atf_test_program{name="noextract_files_test"}
atf_test_program{name="transaction_check_revdeps_test"}
atf_test_program{name="repo_test"}

View File

@ -8,7 +8,7 @@ TESTSHELL+= issue31_test scripts_test incorrect_deps_test
TESTSHELL+= vpkg_test install_test preserve_files_test configure_test
TESTSHELL+= update_shlibs_test update_hold_test update_repolock_test
TESTSHELL+= cyclic_deps_test conflicts_test update_itself_test
TESTSHELL+= hold_test ignore_test preserve_test
TESTSHELL+= hold_test ignore_test preserve_test repo_test
TESTSHELL+= noextract_files_test orphans_test transaction_check_revdeps_test
EXTRA_FILES = Kyuafile

0
tests/xbps/libxbps/shell/conf_files_test.sh Executable file → Normal file
View File

View File

@ -0,0 +1,27 @@
#!/usr/bin/env atf-sh
atf_test_case repo_close
repo_close_head() {
atf_set "descr" "Tests for pkg repos: truncate repo size to 0"
}
repo_close_body() {
mkdir -p repo pkg_A
cd repo
xbps-create -A noarch -n A-1.0_1 -s "A pkg" ../pkg_A
atf_check_equal $? 0
xbps-rindex -d -a $PWD/*.xbps
atf_check_equal $? 0
cd ..
xbps-install -C empty.conf -r root --repository=repo -yn A
atf_check_equal $? 0
truncate --size 0 repo/*-repodata
xbps-install -C empty.conf -r root --repository=repo -yn A
# ENOENT because invalid repodata
atf_check_equal $? 2
}
atf_init_test_cases() {
atf_add_test_case repo_close
}