diff options
Diffstat (limited to 'source3/lib/util.c')
-rw-r--r-- | source3/lib/util.c | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/source3/lib/util.c b/source3/lib/util.c index 57370bc67e..a081cf0368 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -4800,6 +4800,7 @@ safe string copy into a fstring void fstrcpy(char *dest, char *src) { int maxlength = sizeof(fstring) - 1; + int len; if (!dest) { DEBUG(0,("ERROR: NULL dest in fstrcpy\n")); return; @@ -4809,14 +4810,17 @@ void fstrcpy(char *dest, char *src) *dest = 0; return; } + + len = strlen(src); + + if (len > maxlength) { + DEBUG(0,("ERROR: string overflow by %d in fstrcpy [%.50s]\n", + len-maxlength, src)); + len = maxlength; + } - while (maxlength-- && *src) - *dest++ = *src++; - *dest = 0; - if (*src) { - DEBUG(0,("ERROR: string overflow by %d in fstrcpy\n", - strlen(src))); - } + memcpy(dest, src, len); + dest[len] = 0; } /******************************************************************* @@ -4825,23 +4829,27 @@ safe string copy into a pstring void pstrcpy(char *dest, char *src) { int maxlength = sizeof(pstring) - 1; + int len; if (!dest) { DEBUG(0,("ERROR: NULL dest in pstrcpy\n")); return; } - + if (!src) { *dest = 0; return; + } + + len = strlen(src); + + if (len > maxlength) { + DEBUG(0,("ERROR: string overflow by %d in pstrcpy [%.50s]\n", + len-maxlength, src)); + len = maxlength; } - - while (maxlength-- && *src) - *dest++ = *src++; - *dest = 0; - if (*src) { - DEBUG(0,("ERROR: string overflow by %d in pstrcpy\n", - strlen(src))); - } + + memcpy(dest, src, len); + dest[len] = 0; } |