diff options
author | Jeremy Allison <jra@samba.org> | 1999-12-23 18:58:44 +0000 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 1999-12-23 18:58:44 +0000 |
commit | 61e06c44b47834ed297aacee6d59c40796b4ffb5 (patch) | |
tree | 02dae103fac8f795490adf02dbf8126d11ca2552 /source/lib | |
parent | 2e03ed62542152264ca5315b9ee9bb045b7f0b03 (diff) | |
download | samba-61e06c44b47834ed297aacee6d59c40796b4ffb5.tar.gz samba-61e06c44b47834ed297aacee6d59c40796b4ffb5.tar.xz samba-61e06c44b47834ed297aacee6d59c40796b4ffb5.zip |
Fixed range checking in unicode to multibyte function. Oops.
Jeremy.
Diffstat (limited to 'source/lib')
-rw-r--r-- | source/lib/util_unistr.c | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/source/lib/util_unistr.c b/source/lib/util_unistr.c index dddf4bde92a..ddcea26e389 100644 --- a/source/lib/util_unistr.c +++ b/source/lib/util_unistr.c @@ -572,25 +572,28 @@ BOOL load_unix_unicode_map(const char *unix_char_set) static char *unicode_to_multibyte(char *dst, const smb_ucs2_t *src, size_t dst_len, const uint16 *ucs2_to_cp) { - size_t i; + size_t dst_pos; - for(i = 0; (i < (dst_len - 1)) && src[i];) { - smb_ucs2_t val = ucs2_to_cp[*src]; + for(dst_pos = 0; *src && (dst_pos < dst_len - 1);) { + smb_ucs2_t val = ucs2_to_cp[*src++]; if(val < 256) { - dst[i++] = (char)val; - } else if (i < (dst_len - 2)) { + dst[dst_pos++] = (char)val; + } else { + + if(dst_pos >= dst_len - 2) + break; /* * A 2 byte value is always written as * high/low into the buffer stream. */ - dst[i++] = (char)((val >> 8) & 0xff); - dst[i++] = (char)(val & 0xff); + dst[dst_pos++] = (char)((val >> 8) & 0xff); + dst[dst_pos++] = (char)(val & 0xff); } } - dst[i] = '\0'; + dst[dst_pos] = '\0'; return dst; } @@ -898,7 +901,7 @@ smb_ucs2_t *wstrtok(smb_ucs2_t *s1, const smb_ucs2_t *s2) smb_ucs2_t *wstrdup(const smb_ucs2_t *s) { - size_t newlen = (wstrlen(s)*sizeof(smb_ucs2_t)) + 1; + size_t newlen = (wstrlen(s)+1)*sizeof(smb_ucs2_t); smb_ucs2_t *newstr = (smb_ucs2_t *)malloc(newlen); if (newstr == NULL) return NULL; @@ -929,6 +932,7 @@ int wisupper( smb_ucs2_t val) { return (map_table[val].flags & UNI_UPPER); } + /******************************************************************* Is a lower case wchar. ********************************************************************/ @@ -937,6 +941,7 @@ int wislower( smb_ucs2_t val) { return (map_table[val].flags & UNI_LOWER); } + /******************************************************************* Is a digit wchar. ********************************************************************/ @@ -945,6 +950,7 @@ int wisdigit( smb_ucs2_t val) { return (map_table[val].flags & UNI_DIGIT); } + /******************************************************************* Is a hex digit wchar. ********************************************************************/ |