tests/xbps/libxbps/config: safer string handling

Closes: #61 [via git-merge-pr]
This commit is contained in:
Cameron Nemo 2019-03-17 12:15:43 -07:00 committed by Duncaen
parent 5aa1adca90
commit 31737ff946

View File

@ -39,6 +39,7 @@ ATF_TC_BODY(config_include_test, tc)
struct xbps_handle xh;
const char *tcsdir;
char *buf, *buf2, pwd[PATH_MAX];
int ret;
/* get test source dir */
tcsdir = atf_tc_get_config_var(tc, "srcdir");
@ -48,7 +49,9 @@ ATF_TC_BODY(config_include_test, tc)
xbps_strlcpy(xh.rootdir, pwd, sizeof(xh.rootdir));
xbps_strlcpy(xh.metadir, pwd, sizeof(xh.metadir));
snprintf(xh.confdir, sizeof(xh.confdir), "%s/xbps.d", pwd);
ret = snprintf(xh.confdir, sizeof(xh.confdir), "%s/xbps.d", pwd);
ATF_REQUIRE_EQ((ret >= 0), 1);
ATF_REQUIRE_EQ(((size_t)ret < sizeof(xh.confdir)), 1);
ATF_REQUIRE_EQ(xbps_mkpath(xh.confdir, 0755), 0);
@ -88,6 +91,7 @@ ATF_TC_BODY(config_include_nomatch_test, tc)
struct xbps_handle xh;
const char *tcsdir;
char *buf, *buf2, pwd[PATH_MAX];
int ret;
/* get test source dir */
tcsdir = atf_tc_get_config_var(tc, "srcdir");
@ -97,7 +101,9 @@ ATF_TC_BODY(config_include_nomatch_test, tc)
xbps_strlcpy(xh.rootdir, tcsdir, sizeof(xh.rootdir));
xbps_strlcpy(xh.metadir, tcsdir, sizeof(xh.metadir));
snprintf(xh.confdir, sizeof(xh.confdir), "%s/xbps.d", pwd);
ret = snprintf(xh.confdir, sizeof(xh.confdir), "%s/xbps.d", pwd);
ATF_REQUIRE_EQ((ret >= 0), 1);
ATF_REQUIRE_EQ(((size_t)ret < sizeof(xh.confdir)), 1);
ATF_REQUIRE_EQ(xbps_mkpath(xh.confdir, 0755), 0);