From b5fb03adeb411d7fc5ee5a33c35e289465fdfe9a 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 a23d041fa9..7527ec4122 100644 --- a/bacula/src/lib/bsys.c +++ b/bacula/src/lib/bsys.c @@ -108,14 +108,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