From: Kern Sibbald Date: Tue, 8 Dec 2009 06:58:34 +0000 (+0100) Subject: Fix bug in bstrncat X-Git-Tag: Release-7.0.0~2493 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=b5fb03adeb411d7fc5ee5a33c35e289465fdfe9a;p=bacula%2Fbacula Fix bug in bstrncat --- 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; }