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_ */
s++; i++;
}
- if (*s == '=') n -= 1;
+ if ((n > 0) && (*s == '=')) {
+ n -= 1;
+ }
/* fix up length */
decoded.length = n;
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);
}
*/
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));
* (JRA).
*/
if (mangled)
- mangled = !mangle_check_cache( name );
+ mangled = !mangle_check_cache( name, maxlength );
/* open the directory */
if (!(cur_dir = OpenDir(conn, path, True))) {
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);
}
/*
* 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
* ************************************************************************** **
*/
-static BOOL check_cache( char *s )
+static BOOL check_cache( char *s, size_t maxlen )
{
ubi_cacheEntryPtr FoundPtr;
char *ext_start = NULL;
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 );
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);
}
/*
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;
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;
*/
if (!rc && mangle_is_mangled(mask))
- mangle_check_cache( mask );
+ mangle_check_cache( mask, sizeof(pstring)-1 );
if (!has_wild) {
pstrcat(directory,"/");
*/
if (!rc && mangle_is_mangled(mask))
- mangle_check_cache( mask );
+ mangle_check_cache( mask, sizeof(pstring)-1 );
has_wild = ms_has_wild(mask);
*/
if (!rc && mangle_is_mangled(mask))
- mangle_check_cache( mask );
+ mangle_check_cache( mask, sizeof(pstring)-1 );
has_wild = ms_has_wild(mask);