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