summaryrefslogtreecommitdiff
path: root/source3/smbd
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2003-03-12 19:08:01 +0000
committerJeremy Allison <jra@samba.org>2003-03-12 19:08:01 +0000
commit15ae0c4dedbfb279c9ee77cd37e9c4a55b8434e5 (patch)
treec18faf2253347d5983cfdd0cdabc4896d2cd5af0 /source3/smbd
parentc992f66d733d230bc71f61ab4d13c08354ec0685 (diff)
downloadsamba-15ae0c4dedbfb279c9ee77cd37e9c4a55b8434e5.tar.gz
samba-15ae0c4dedbfb279c9ee77cd37e9c4a55b8434e5.tar.bz2
samba-15ae0c4dedbfb279c9ee77cd37e9c4a55b8434e5.zip
Ensure we count the length correctly in mangle_map.
Jeremy. (This used to be commit 596705198c555568da208f59008ab87c5164bfb4)
Diffstat (limited to 'source3/smbd')
-rw-r--r--source3/smbd/mangle_map.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/source3/smbd/mangle_map.c b/source3/smbd/mangle_map.c
index 553e3d949d..5ae3ebd174 100644
--- a/source3/smbd/mangle_map.c
+++ b/source3/smbd/mangle_map.c
@@ -150,36 +150,45 @@ static void mangled_map(char *s, const char *MangledMap)
}
DEBUG( 5, ("End of first in pair '%s'\n", end) );
if( (match_string = map_filename( s, start, end-start )) ) {
+ int size_left = sizeof(new_string) - 1;
DEBUG( 5, ("Found a match\n") );
/* Found a match. */
start = end + 1; /* Point to start of what it is to become. */
DEBUG( 5, ("Start of second in pair '%s'\n", start) );
end = start;
np = new_string;
- while( (*end) /* Not the end of string. */
+ while( (*end && size_left > 0) /* Not the end of string. */
&& (*end != ')') /* Not the end of the pattern. */
- && (*end != '*') ) /* Not a wildcard. */
+ && (*end != '*') ) { /* Not a wildcard. */
*np++ = *end++;
+ size_left--;
+ }
if( !*end ) {
start = end;
continue; /* Always check for the end. */
}
if( *end == '*' ) {
- pstrcpy( np, match_string );
+ if (size_left > 0 )
+ safe_strcpy( np, match_string, size_left );
np += strlen( match_string );
+ size_left -= strlen( match_string );
end++; /* Skip the '*' */
- while ((*end) /* Not the end of string. */
+ while ((*end && size_left > 0) /* Not the end of string. */
&& (*end != ')') /* Not the end of the pattern. */
- && (*end != '*'))/* Not a wildcard. */
+ && (*end != '*')) { /* Not a wildcard. */
*np++ = *end++;
+ size_left--;
+ }
}
if (!*end) {
start = end;
continue; /* Always check for the end. */
}
- *np++ = '\0'; /* NULL terminate it. */
+ if (size_left > 0)
+ *np++ = '\0'; /* NULL terminate it. */
DEBUG(5,("End of second in pair '%s'\n", end));
+ new_string[sizeof(new_string)-1] = '\0';
pstrcpy( s, new_string ); /* Substitute with the new name. */
DEBUG( 5, ("s is now '%s'\n", s) );
}