fix handling of length with strncat
The length arg in the strncat func represents the max number of bytes that may be appended, but the total length of the buffer. So we have to subtract the length of bytes already in there. Signed-off-by: Mike Frysinger <vapier@gentoo.org>pull/1/merge
parent
c13acaca47
commit
4e4c1d628a
6
pkg.c
6
pkg.c
|
@ -32,17 +32,19 @@ pkg_get_pkgconfig_path(void)
|
||||||
static bool computed = false;
|
static bool computed = false;
|
||||||
static char path[PKG_CONFIG_PATH_SZ];
|
static char path[PKG_CONFIG_PATH_SZ];
|
||||||
char *env_path;
|
char *env_path;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
if (computed)
|
if (computed)
|
||||||
return path;
|
return path;
|
||||||
|
|
||||||
strncpy(path, PKG_DEFAULT_PATH, sizeof path);
|
strncpy(path, PKG_DEFAULT_PATH, sizeof path);
|
||||||
|
len = strlen(PKG_DEFAULT_PATH);
|
||||||
|
|
||||||
env_path = getenv("PKG_CONFIG_PATH");
|
env_path = getenv("PKG_CONFIG_PATH");
|
||||||
if (env_path != NULL)
|
if (env_path != NULL)
|
||||||
{
|
{
|
||||||
strncat(path, ":", sizeof path);
|
strncat(path, ":", sizeof path - len - 1);
|
||||||
strncat(path, env_path, sizeof path);
|
strncat(path, env_path, sizeof path - len - 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
|
|
Loading…
Reference in New Issue