diff options
author | Andrew Bartlett <abartlet@samba.org> | 2011-05-03 12:16:16 +1000 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2011-05-03 07:37:07 +0200 |
commit | 2742ec0e34c06ded2885aa2607f1c1729a57b034 (patch) | |
tree | c10f1501c68c54ffc61c1f3545f7d272187b0aa2 /source3 | |
parent | 39081a20c5b570430e28866e34ae965c60ee2039 (diff) | |
download | samba-2742ec0e34c06ded2885aa2607f1c1729a57b034.tar.gz samba-2742ec0e34c06ded2885aa2607f1c1729a57b034.tar.bz2 samba-2742ec0e34c06ded2885aa2607f1c1729a57b034.zip |
Remove strlower_m() and strupper_m() from source4 and common code.
This function is problematic because a string may expand in size when
changed into upper or lower case. This will then push characters off
the end of the string in the s3 implementation, or panic in the former
s4 implementation.
Andrew Bartlett
Diffstat (limited to 'source3')
-rw-r--r-- | source3/lib/util_str.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index b15dd7907b..4d76cc0a9f 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -796,6 +796,36 @@ static bool unix_strlower(const char *src, size_t srclen, char *dest, size_t des return ret; } +#if 0 /* Alternate function that avoid talloc calls for ASCII and non ASCII */ + +/** + Convert a string to lower case. +**/ +_PUBLIC_ void strlower_m(char *s) +{ + char *d; + struct smb_iconv_handle *iconv_handle; + + iconv_handle = get_iconv_handle(); + + d = s; + + while (*s) { + size_t c_size, c_size2; + codepoint_t c = next_codepoint_handle(iconv_handle, s, &c_size); + c_size2 = push_codepoint_handle(iconv_handle, d, tolower_m(c)); + if (c_size2 > c_size) { + DEBUG(0,("FATAL: codepoint 0x%x (0x%x) expanded from %d to %d bytes in strlower_m\n", + c, tolower_m(c), (int)c_size, (int)c_size2)); + smb_panic("codepoint expansion in strlower_m\n"); + } + s += c_size; + d += c_size2; + } + *d = 0; +} + +#endif /** Convert a string to lower case. @@ -851,6 +881,37 @@ static bool unix_strupper(const char *src, size_t srclen, char *dest, size_t des return ret; } +#if 0 /* Alternate function that avoid talloc calls for ASCII and non ASCII */ + +/** + Convert a string to UPPER case. +**/ +_PUBLIC_ void strupper_m(char *s) +{ + char *d; + struct smb_iconv_handle *iconv_handle; + + iconv_handle = get_iconv_handle(); + + d = s; + + while (*s) { + size_t c_size, c_size2; + codepoint_t c = next_codepoint_handle(iconv_handle, s, &c_size); + c_size2 = push_codepoint_handle(iconv_handle, d, toupper_m(c)); + if (c_size2 > c_size) { + DEBUG(0,("FATAL: codepoint 0x%x (0x%x) expanded from %d to %d bytes in strupper_m\n", + c, toupper_m(c), (int)c_size, (int)c_size2)); + smb_panic("codepoint expansion in strupper_m\n"); + } + s += c_size; + d += c_size2; + } + *d = 0; +} + +#endif + /** Convert a string to upper case. **/ |