r2016: Add message to ease access-control-debugging.
[ira/wip.git] / source3 / smbd / mangle_map.c
index 71d9340718140cbba2bea60dfd450fa70143c9fb..9e798fd41b46ce6d5912d362346417bdc4c28b06 100644 (file)
@@ -127,8 +127,8 @@ static char *map_filename( char *s,         /* This is null terminated */
  */
 static void mangled_map(char *s, const char *MangledMap)
 {
-       char *start=MangledMap;       /* Use this to search for mappings. */
-       char *end;                    /* Used to find the end of strings. */
+       const char *start=MangledMap;       /* Use this to search for mappings. */
+       const char *end;                    /* Used to find the end of strings. */
        char *match_string;
        pstring new_string;           /* Make up the result here. */
        char *np;                     /* Points into new_string. */
@@ -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) );
                }
@@ -192,7 +201,7 @@ static void mangled_map(char *s, const char *MangledMap)
   front end routine to the mangled map code 
   personally I think that the whole idea of "mangled map" is completely bogus
 */
-void mangle_map_filename(char *fname, int snum)
+void mangle_map_filename(fstring fname, int snum)
 {
        char *map;