Fix bug reported in mangle_hash code (no bugid yet).
authorJeremy Allison <jra@samba.org>
Tue, 22 Dec 2009 01:46:32 +0000 (17:46 -0800)
committerJeremy Allison <jra@samba.org>
Tue, 22 Dec 2009 01:46:32 +0000 (17:46 -0800)
Don't change the contents of a const string via a pointer
alias (or if you do, change it back.....).

Jeremy.

source3/smbd/mangle_hash.c

index c08bc4019a3ad9b88e00fe69a8960167a4aa7461..8369af418ae0d3242b4c129c220a564512d69acb 100644 (file)
@@ -429,6 +429,13 @@ static void cache_mangled_name( const char mangled_name[13],
                if( !s1[i] && !s2[i] ) {
                        /* Truncate at the '.' */
                        *s1 = '\0';
+                       /*
+                        * DANGER WILL ROBINSON - this
+                        * is changing a const string via
+                        * an aliased pointer ! Remember to
+                        * put it back once we've used it.
+                        * JRA
+                        */
                        *s2 = '\0';
                }
        }
@@ -440,6 +447,8 @@ static void cache_mangled_name( const char mangled_name[13],
        } else {
                DEBUG(5,("cache_mangled_name: Stored entry %s -> %s\n", mangled_name_key, raw_name));
        }
+       /* Restore the change we made to the const string. */
+       *s2 = '.';
 }
 
 /* ************************************************************************** **