r1570: merging changes from 3.0.5
authorGerald Carter <jerry@samba.org>
Thu, 22 Jul 2004 13:39:43 +0000 (13:39 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 15:52:15 +0000 (10:52 -0500)
(This used to be commit 430cf63b9148441bce42bfb15a8045de5da108f4)

source3/include/mangle.h
source3/lib/util_str.c
source3/smbd/filename.c
source3/smbd/mangle.c
source3/smbd/mangle_hash.c
source3/smbd/mangle_hash2.c
source3/smbd/reply.c

index 1d7cdf736281c9066ea9dd983e9d443be8c3da8b..08d511689dcb891b14c82a4f529465c6c21ef485 100644 (file)
@@ -8,7 +8,7 @@ struct mangle_fns {
        BOOL (*is_mangled)(const char *s);
        BOOL (*is_8_3)(const char *fname, BOOL check_case, BOOL allow_wildcards);
        void (*reset)(void);
-       BOOL (*check_cache)(char *s);
+       BOOL (*check_cache)(char *s, size_t maxlen);
        void (*name_map)(char *OutName, BOOL need83, BOOL cache83, int default_case);
 };
 #endif /* _MANGLE_H_ */
index 7c5fa11c92d6453e203354b1c6d9ea03aa65fbde..1083076edd4d1893621a641335a87f89532086b8 100644 (file)
@@ -1949,7 +1949,9 @@ DATA_BLOB base64_decode_data_blob(const char *s)
                s++; i++;
        }
 
-       if (*s == '=') n -= 1;
+       if ((n > 0) && (*s == '=')) {
+               n -= 1;
+       }
 
        /* fix up length */
        decoded.length = n;
@@ -1962,9 +1964,15 @@ DATA_BLOB base64_decode_data_blob(const char *s)
 void base64_decode_inplace(char *s)
 {
        DATA_BLOB decoded = base64_decode_data_blob(s);
-       memcpy(s, decoded.data, decoded.length);
-       /* null terminate */
-       s[decoded.length] = '\0';
+
+       if ( decoded.length != 0 ) {
+               memcpy(s, decoded.data, decoded.length);
+
+               /* null terminate */
+               s[decoded.length] = '\0';
+       } else {
+               *s = '\0';
+       }
 
        data_blob_free(&decoded);
 }
index ab75d9c06aec989442d7a28fcf0a66d088b9d492..cc1c0a40b665f2ae820ab0172eed68a6f84a9d26 100644 (file)
@@ -326,7 +326,7 @@ BOOL unix_convert(pstring name,connection_struct *conn,char *saved_last_componen
                                 */
 
                                if (mangle_is_mangled(start)) {
-                                       mangle_check_cache( start );
+                                       mangle_check_cache( start, sizeof(pstring) - 1 - (start - name) );
                                }
 
                                DEBUG(5,("New file %s\n",start));
@@ -476,7 +476,7 @@ static BOOL scan_directory(const char *path, char *name, size_t maxlength,
         * (JRA).
         */
        if (mangled)
-               mangled = !mangle_check_cache( name );
+               mangled = !mangle_check_cache( name, maxlength );
 
        /* open the directory */
        if (!(cur_dir = OpenDir(conn, path, True))) {
index b77fe601b6981d6d3e4f3ec070c87573407ccf57..43becff69db99abb9bf27e0e9fe001d49e89e996 100644 (file)
@@ -98,9 +98,9 @@ BOOL mangle_is_8_3_wildcards(const char *fname, BOOL check_case)
   looking for a matching name if it doesn't. It should succeed most of the time
   or there will be a huge performance penalty
 */
-BOOL mangle_check_cache(char *s)
+BOOL mangle_check_cache(char *s, size_t maxlen)
 {
-       return mangle_fns->check_cache(s);
+       return mangle_fns->check_cache(s, maxlen);
 }
 
 /* 
index d7239b82a79a349dcba855b69e10fecba58218c2..13ec99a917f7bebbac5b640420958c19cecd46fc 100644 (file)
@@ -557,7 +557,7 @@ static void cache_mangled_name( char *mangled_name, char *raw_name )
  * Check for a name on the mangled name stack
  *
  *  Input:  s - Input *and* output string buffer.
- *
+ *         maxlen - space in i/o string buffer.
  *  Output: True if the name was found in the cache, else False.
  *
  *  Notes:  If a reverse map is found, the function will overwrite the string
@@ -568,7 +568,7 @@ static void cache_mangled_name( char *mangled_name, char *raw_name )
  * ************************************************************************** **
  */
 
-static BOOL check_cache( char *s )
+static BOOL check_cache( char *s, size_t maxlen )
 {
        ubi_cacheEntryPtr FoundPtr;
        char             *ext_start = NULL;
@@ -602,7 +602,7 @@ static BOOL check_cache( char *s )
        if( !FoundPtr ) {
                if(saved_ext) {
                        /* Replace the saved_ext as it was truncated. */
-                       (void)pstrcat( s, saved_ext );
+                       (void)safe_strcat( s, saved_ext, maxlen );
                        SAFE_FREE(saved_ext);
                }
                return( False );
@@ -612,10 +612,10 @@ static BOOL check_cache( char *s )
        found_name = (char *)(FoundPtr + 1);
        found_name += (strlen( found_name ) + 1);
 
-       (void)pstrcpy( s, found_name );
+       (void)safe_strcpy( s, found_name, maxlen );
        if( saved_ext ) {
                /* Replace the saved_ext as it was truncated. */
-               (void)pstrcat( s, saved_ext );
+               (void)safe_strcat( s, saved_ext, maxlen );
                SAFE_FREE(saved_ext);
        }
 
index dcfd7663ba3848b154e49740aab0651fbbbc7d2c..f68873687bdc277783d8e0a7cb6f2dba7d93736a 100644 (file)
@@ -362,10 +362,8 @@ static void mangle_reset(void)
 /*
   try to find a 8.3 name in the cache, and if found then
   replace the string with the original long name. 
-
-  The filename must be able to hold at least sizeof(fstring) 
 */
-static BOOL check_cache(char *name)
+static BOOL check_cache(char *name, size_t maxlen)
 {
        u32 hash, multiplier;
        unsigned int i;
@@ -403,10 +401,10 @@ static BOOL check_cache(char *name)
 
        if (extension[0]) {
                M_DEBUG(10,("check_cache: %s -> %s.%s\n", name, prefix, extension));
-               slprintf(name, sizeof(fstring), "%s.%s", prefix, extension);
+               slprintf(name, maxlen, "%s.%s", prefix, extension);
        } else {
                M_DEBUG(10,("check_cache: %s -> %s\n", name, prefix));
-               fstrcpy(name, prefix);
+               safe_strcpy(name, prefix, maxlen);
        }
 
        return True;
index 71efb793af0edd1cf78d2e251023f14f4c96f441..f3ab709df48e8be0601ed4a012d6fcc0492fecc0 100644 (file)
@@ -1583,7 +1583,7 @@ NTSTATUS unlink_internals(connection_struct *conn, int dirtype, char *name)
         */
        
        if (!rc && mangle_is_mangled(mask))
-               mangle_check_cache( mask );
+               mangle_check_cache( mask, sizeof(pstring)-1 );
        
        if (!has_wild) {
                pstrcat(directory,"/");
@@ -3738,7 +3738,7 @@ NTSTATUS rename_internals(connection_struct *conn, char *name, char *newname, ui
         */
 
        if (!rc && mangle_is_mangled(mask))
-               mangle_check_cache( mask );
+               mangle_check_cache( mask, sizeof(pstring)-1 );
 
        has_wild = ms_has_wild(mask);
 
@@ -4216,7 +4216,7 @@ int reply_copy(connection_struct *conn, char *inbuf,char *outbuf, int dum_size,
         */
 
        if (!rc && mangle_is_mangled(mask))
-               mangle_check_cache( mask );
+               mangle_check_cache( mask, sizeof(pstring)-1 );
 
        has_wild = ms_has_wild(mask);