forked from ariadne/pkgconf
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>feature/tap-sh
parent
c13acaca47
commit
4e4c1d628a
6
pkg.c
6
pkg.c
|
@ -32,17 +32,19 @@ pkg_get_pkgconfig_path(void)
|
|||
static bool computed = false;
|
||||
static char path[PKG_CONFIG_PATH_SZ];
|
||||
char *env_path;
|
||||
size_t len;
|
||||
|
||||
if (computed)
|
||||
return path;
|
||||
|
||||
strncpy(path, PKG_DEFAULT_PATH, sizeof path);
|
||||
len = strlen(PKG_DEFAULT_PATH);
|
||||
|
||||
env_path = getenv("PKG_CONFIG_PATH");
|
||||
if (env_path != NULL)
|
||||
{
|
||||
strncat(path, ":", sizeof path);
|
||||
strncat(path, env_path, sizeof path);
|
||||
strncat(path, ":", sizeof path - len - 1);
|
||||
strncat(path, env_path, sizeof path - len - 2);
|
||||
}
|
||||
|
||||
return path;
|
||||
|
|
Loading…
Reference in New Issue