From 49fb01d34a30b9f15028bf52c9d8dbdd07ad4b11 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Tue, 8 Dec 2009 07:58:34 +0100 Subject: [PATCH] Fix bug in bstrncat --- bacula/src/lib/bsys.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/bacula/src/lib/bsys.c b/bacula/src/lib/bsys.c index bca7f58ec5..9d1a7ca6b1 100644 --- a/bacula/src/lib/bsys.c +++ b/bacula/src/lib/bsys.c @@ -118,14 +118,21 @@ char *bstrncpy(char *dest, POOL_MEM &src, int maxlen) char *bstrncat(char *dest, const char *src, int maxlen) { - strncat(dest, src, maxlen-1); + int len = strlen(dest); + if (len < maxlen-1) { + strncpy(dest+len, src, maxlen-len-1); + } dest[maxlen-1] = 0; return dest; } char *bstrncat(char *dest, POOL_MEM &src, int maxlen) { - strncat(dest, src.c_str(), maxlen-1); + + int len = strlen(dest); + if (len < maxlen-1) { + strncpy(dest+len, src.c_str(), maxlen-len-1); + } dest[maxlen-1] = 0; return dest; } -- 2.39.5