*
*/
-static const char basechars[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_-!@#$%";
+static const char basechars[43]="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_-!@#$%";
#define MANGLE_BASE (sizeof(basechars)/sizeof(char)-1)
#define mangle(V) ((char)(basechars[(V) % MANGLE_BASE]))
if (strlen(f) > 12)
return False;
- if (!push_ucs2_allocate(&ucs2name, f, &size)) {
- DEBUG(0,("is_8_3: internal error push_ucs2_allocate() failed!\n"));
+ if (!push_ucs2_talloc(NULL, &ucs2name, f, &size)) {
+ DEBUG(0,("is_8_3: internal error push_ucs2_talloc() failed!\n"));
goto done;
}
ret = is_8_3_w(ucs2name, allow_wildcards);
done:
- SAFE_FREE(ucs2name);
+ TALLOC_FREE(ucs2name);
if (!NT_STATUS_IS_OK(ret)) {
return False;
chartest = SMB_MALLOC_ARRAY(unsigned char, 256);
SMB_ASSERT(chartest != NULL);
+ memset(chartest, '\0', 256);
for( s = (const unsigned char *)basechars; *s; s++ ) {
chartest[*s] |= BASECHAR_MASK;
{
TDB_DATA data_val;
char mangled_name_key[13];
- char *s1;
- char *s2;
+ char *s1 = NULL;
+ char *s2 = NULL;
/* If the cache isn't initialized, give up. */
if( !tdb_mangled_cache )
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';
}
}
} 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. */
+ if (s2) {
+ *s2 = '.';
+ }
}
/* ************************************************************************** **
magic_char = lp_magicchar(p);
- if (!push_ucs2_allocate(&name_ucs2, name, &converted_size)) {
- DEBUG(0, ("push_ucs2_allocate failed!\n"));
+ if (!push_ucs2_talloc(NULL, &name_ucs2, name, &converted_size)) {
+ DEBUG(0, ("push_ucs2_talloc failed!\n"));
return False;
}
status = is_valid_name(name_ucs2, False, False);
- SAFE_FREE(name_ucs2);
- return NT_STATUS_IS_OK(status);
+ TALLOC_FREE(name_ucs2);
+ /* We return true if we *must* mangle, so if it's
+ * a valid name (status == OK) then we must return
+ * false. Bug #6939. */
+ return !NT_STATUS_IS_OK(status);
}
/*****************************************************************************
DEBUG(5,("hash_name_to_8_3( %s, cache83 = %s)\n", in,
cache83 ? "True" : "False"));
- if (!push_ucs2_allocate(&in_ucs2, in, &converted_size)) {
- DEBUG(0, ("push_ucs2_allocate failed!\n"));
+ if (!push_ucs2_talloc(NULL, &in_ucs2, in, &converted_size)) {
+ DEBUG(0, ("push_ucs2_talloc failed!\n"));
return False;
}
/* If it's already 8.3, just copy. */
if (NT_STATUS_IS_OK(is_valid_name(in_ucs2, False, False)) &&
NT_STATUS_IS_OK(is_8_3_w(in_ucs2, False))) {
- SAFE_FREE(in_ucs2);
+ TALLOC_FREE(in_ucs2);
safe_strcpy(out, in, 12);
return True;
}
- SAFE_FREE(in_ucs2);
+ TALLOC_FREE(in_ucs2);
if (!to_8_3(magic_char, in, out, default_case)) {
return False;
}