From f714ff90982b986b9b0498b2d11d0efd8a8aaf6b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 6 May 1998 02:30:52 +0000 Subject: much faster pstrcpy() and fstrcpy() also print out the first 50 chars of an overflowing string so we have some chance of working out what is causng them. (This used to be commit 7a67e76722521ac8099cbcda054b0f4bf45c7bfe) --- source3/lib/util.c | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) (limited to 'source3/lib') 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; } -- cgit