From 4e4c1d628a1a21b48b93f8fd813899d25749f5d1 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Sun, 29 Apr 2012 23:58:52 -0400 Subject: [PATCH] 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 --- pkg.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg.c b/pkg.c index 4e4d464..2ce3605 100644 --- a/pkg.c +++ b/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;