Skip to content

Commit 705dff9

Browse files
ifreundbapt
authored andcommitted
libpkg: validate SHLIB_PROVIDE_PATHS_* options
These require absolute paths, providing a relative path currently triggers an assertion failure. This commit adds validation of these options and test cases to prevent regression. Fixes: a35c0a3 Sponsored by: The FreeBSD Foundation
1 parent 4dec5da commit 705dff9

2 files changed

Lines changed: 51 additions & 1 deletion

File tree

libpkg/pkg_config.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,33 @@ config_validate_debug_flags(const ucl_object_t *o)
10501050
return (ret);
10511051
}
10521052

1053+
static bool
1054+
config_validate_shlib_provide_paths() {
1055+
const char *config_options[] = {
1056+
"SHLIB_PROVIDE_PATHS_NATIVE",
1057+
"SHLIB_PROVIDE_PATHS_COMPAT_32",
1058+
"SHLIB_PROVIDE_PATHS_COMPAT_LINUX",
1059+
"SHLIB_PROVIDE_PATHS_COMPAT_LINUX_32",
1060+
NULL,
1061+
};
1062+
bool valid = true;
1063+
for (const char **option = config_options; *option != NULL; option++) {
1064+
const ucl_object_t *paths = pkg_config_get(*option);
1065+
const ucl_object_t *cur;
1066+
ucl_object_iter_t it = NULL;
1067+
while ((cur = ucl_object_iterate(paths, &it, true))) {
1068+
const char *path = ucl_object_tostring(cur);
1069+
if (path[0] != '/') {
1070+
pkg_emit_error("Invalid value for config option %s, "
1071+
"'%s' is not an absolute path.",
1072+
*option, path);
1073+
valid = false;
1074+
}
1075+
}
1076+
}
1077+
return valid;
1078+
}
1079+
10531080
/* Parses ABI_FILE, ABI, ALTABI, and OSVERSION from the given ucl file and sets
10541081
* the values in the environment. These values must be parsed separately from
10551082
* the rest of the config because they are made available as variable expansions
@@ -1486,6 +1513,11 @@ pkg_ini(const char *path, const char *reposdir, pkg_init_flags flags)
14861513
ucl_object_unref(obj);
14871514
ucl_parser_free(p);
14881515

1516+
if (!config_validate_shlib_provide_paths()) {
1517+
err = EPKG_FATAL;
1518+
goto out;
1519+
}
1520+
14891521
{
14901522
/* Even though we no longer support setting ABI/ALTABI/OSVERSION
14911523
in the pkg.conf config file, we still need to expose these

tests/frontend/config.sh

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ tests_init \
66
duplicate_pkgs_notallowed \
77
inline_repo \
88
nameserver \
9-
expansion
9+
expansion \
10+
validate_shlib_provide_paths
1011
# duplicate_pkgs_allowed \
1112

1213
duplicate_pkgs_allowed_body() {
@@ -140,3 +141,20 @@ expansion_body() {
140141
atf_check -o inline:"${ARCH}\n" pkg -C ${TMPDIR}/pkg.conf config dot_file
141142

142143
}
144+
145+
validate_shlib_provide_paths_body() {
146+
for option in \
147+
SHLIB_PROVIDE_PATHS_NATIVE \
148+
SHLIB_PROVIDE_PATHS_COMPAT_32 \
149+
SHLIB_PROVIDE_PATHS_COMPAT_LINUX \
150+
SHLIB_PROVIDE_PATHS_COMPAT_LINUX_32
151+
do
152+
atf_check -o inline:"/bar/foo\n" -s exit:0 pkg -o $option=/bar/foo config $option
153+
154+
ERROR="pkg: Invalid value for config option ${option}, 'foo' is not an absolute path.
155+
pkg: Cannot parse configuration file!
156+
"
157+
atf_check -e inline:"${ERROR}" -s exit:1 pkg -o $option=foo config $option
158+
atf_check -e inline:"${ERROR}" -s exit:1 pkg -o $option=/bar/foo,foo config $option
159+
done
160+
}

0 commit comments

Comments
 (0)