summaryrefslogtreecommitdiffstats
path: root/source/lib/util_str.c
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2001-12-11 02:27:23 +0000
committerJeremy Allison <jra@samba.org>2001-12-11 02:27:23 +0000
commit9fb37917147f8a9f6dde3066cbce5a5690650df4 (patch)
tree57cf0182d2d438d35a1c29ec3803f90a9576ab15 /source/lib/util_str.c
parent7d9003c0a17b49cf11576a15603250c32a156014 (diff)
downloadsamba-9fb37917147f8a9f6dde3066cbce5a5690650df4.tar.gz
samba-9fb37917147f8a9f6dde3066cbce5a5690650df4.tar.xz
samba-9fb37917147f8a9f6dde3066cbce5a5690650df4.zip
Fix based on work from Ihar Viarheichyk <i.viarheichyk@sam-solutions.net>
to fix alpha_strcpy in non-US/English environment.s Run past the Tridge paranoia filter :-). Fixed boundary condition code. Jeremy.
Diffstat (limited to 'source/lib/util_str.c')
-rw-r--r--source/lib/util_str.c40
1 files changed, 32 insertions, 8 deletions
diff --git a/source/lib/util_str.c b/source/lib/util_str.c
index 6182eb1d7c9..4f9531834ba 100644
--- a/source/lib/util_str.c
+++ b/source/lib/util_str.c
@@ -924,6 +924,8 @@ char *safe_strcat(char *dest, const char *src, size_t maxlength)
char *alpha_strcpy(char *dest, const char *src, const char *other_safe_chars, size_t maxlength)
{
size_t len, i;
+ size_t buflen;
+ smb_ucs2_t *str_ucs, *other_ucs;
if (!dest) {
DEBUG(0,("ERROR: NULL dest in alpha_strcpy\n"));
@@ -935,22 +937,44 @@ char *alpha_strcpy(char *dest, const char *src, const char *other_safe_chars, si
return dest;
}
- len = strlen(src);
- if (len >= maxlength)
- len = maxlength - 1;
+ /* Get UCS2 version of src string*/
+
+ buflen=2*strlen(src)+2;
+ if (buflen >= (2*maxlength))
+ buflen = 2*(maxlength - 1);
+
+ str_ucs = (smb_ucs2_t*)malloc(buflen);
+ if(!str_ucs) {
+ *dest=0;
+ return dest;
+ }
+ unix_to_unicode(str_ucs, src, buflen);
+ len = strlen_w(str_ucs);
if (!other_safe_chars)
other_safe_chars = "";
+ /* Get UCS2 version of other_safe_chars string*/
+ buflen=2*strlen(other_safe_chars)+2;
+ other_ucs = (smb_ucs2_t*)malloc(buflen);
+ if(!other_ucs) {
+ *dest=0;
+ SAFE_FREE(str_ucs);
+ return dest;
+ }
+ unix_to_unicode(other_ucs, other_safe_chars, buflen);
+
for(i = 0; i < len; i++) {
- int val = (src[i] & 0xff);
- if(isupper(val) || islower(val) || isdigit(val) || strchr(other_safe_chars, val))
- dest[i] = src[i];
+ if(isupper_w(str_ucs[i]) || islower_w(str_ucs[i]) || isdigit_w(str_ucs[i]) || strchr_w(other_ucs, str_ucs[i]))
+ ;
else
- dest[i] = '_';
+ str_ucs[i] = (smb_ucs2_t)'_'; /*This will work*/
+
}
+ unicode_to_unix(dest, str_ucs, maxlength);
- dest[i] = '\0';
+ SAFE_FREE(other_ucs);
+ SAFE_FREE(str_ucs);
return dest;
}