From 1bcf9de67a0c8bea96b8ad9d773b79caeb9fc706 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Thu, 20 May 2010 15:10:36 +0200 Subject: [PATCH] xbps_[gs]et_cachedir(): ensure we don't copy more than buffer's size including NUL. --- lib/util.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/util.c b/lib/util.c index b23beee9..4c6e8a90 100644 --- a/lib/util.c +++ b/lib/util.c @@ -431,8 +431,8 @@ xbps_set_cachedir(const char *dir) assert(dir != NULL); - r = snprintf(res, sizeof(res), "%s/%s", xbps_get_rootdir(), dir); - if (r == -1 || r >= (int)sizeof(res)) { + r = snprintf(res, sizeof(res) - 1, "%s/%s", xbps_get_rootdir(), dir); + if (r == -1 || r >= (int)sizeof(res) - 1) { /* If error or truncated set to default */ cachedir = XBPS_CACHE_PATH; return; @@ -447,9 +447,9 @@ xbps_get_cachedir(void) int r = 0; if (cachedir == NULL) { - r = snprintf(res, sizeof(res), "%s/%s", + r = snprintf(res, sizeof(res) - 1, "%s/%s", xbps_get_rootdir(), XBPS_CACHE_PATH); - if (r == -1 || r >= (int)sizeof(res)) + if (r == -1 || r >= (int)sizeof(res) - 1) return NULL; cachedir = res;