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