tests/xbps/libxbps/config: safer string handling
Closes: #61 [via git-merge-pr]
This commit is contained in:
@ -39,6 +39,7 @@ ATF_TC_BODY(config_include_test, tc)
|
|||||||
struct xbps_handle xh;
|
struct xbps_handle xh;
|
||||||
const char *tcsdir;
|
const char *tcsdir;
|
||||||
char *buf, *buf2, pwd[PATH_MAX];
|
char *buf, *buf2, pwd[PATH_MAX];
|
||||||
|
int ret;
|
||||||
|
|
||||||
/* get test source dir */
|
/* get test source dir */
|
||||||
tcsdir = atf_tc_get_config_var(tc, "srcdir");
|
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.rootdir, pwd, sizeof(xh.rootdir));
|
||||||
xbps_strlcpy(xh.metadir, pwd, sizeof(xh.metadir));
|
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);
|
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;
|
struct xbps_handle xh;
|
||||||
const char *tcsdir;
|
const char *tcsdir;
|
||||||
char *buf, *buf2, pwd[PATH_MAX];
|
char *buf, *buf2, pwd[PATH_MAX];
|
||||||
|
int ret;
|
||||||
|
|
||||||
/* get test source dir */
|
/* get test source dir */
|
||||||
tcsdir = atf_tc_get_config_var(tc, "srcdir");
|
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.rootdir, tcsdir, sizeof(xh.rootdir));
|
||||||
xbps_strlcpy(xh.metadir, tcsdir, sizeof(xh.metadir));
|
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);
|
ATF_REQUIRE_EQ(xbps_mkpath(xh.confdir, 0755), 0);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user