summaryrefslogtreecommitdiff
path: root/source3/lib/util.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>1998-05-06 02:30:52 +0000
committerAndrew Tridgell <tridge@samba.org>1998-05-06 02:30:52 +0000
commitf714ff90982b986b9b0498b2d11d0efd8a8aaf6b (patch)
tree0017983fcc1b72860ee274c102649c05cdacc218 /source3/lib/util.c
parenta2bddb20ed078c3e1b9cb60a7420b3d107898f52 (diff)
downloadsamba-f714ff90982b986b9b0498b2d11d0efd8a8aaf6b.tar.gz
samba-f714ff90982b986b9b0498b2d11d0efd8a8aaf6b.tar.bz2
samba-f714ff90982b986b9b0498b2d11d0efd8a8aaf6b.zip
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)
Diffstat (limited to 'source3/lib/util.c')
-rw-r--r--source3/lib/util.c40
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;
}