diff options
author | Martin Pool <mbp@samba.org> | 2003-04-09 07:34:49 +0000 |
---|---|---|
committer | Martin Pool <mbp@samba.org> | 2003-04-09 07:34:49 +0000 |
commit | 786564f2b4de78c1b9f9fea7dbb5d8cbe593f27c (patch) | |
tree | b4277dc023eee57abd101899857ee86465fbd1e1 | |
parent | a47b9e61e0512fe555f344a9534fb827f3412cfd (diff) | |
download | samba-786564f2b4de78c1b9f9fea7dbb5d8cbe593f27c.tar.gz samba-786564f2b4de78c1b9f9fea7dbb5d8cbe593f27c.tar.bz2 samba-786564f2b4de78c1b9f9fea7dbb5d8cbe593f27c.zip |
unix_strupper, unix_strlower: Remove fixed-length static buffer that
makes these functions fail for strings over 512 characters. Now we
use convert_string_allocate, which grows a buffer as necessary.
(This used to be commit a55dc493ca212bde22d9e68ea8a4cc16a142c69d)
-rw-r--r-- | source3/lib/charcnv.c | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index d727628e41..7acb7147fd 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -4,6 +4,7 @@ Copyright (C) Igor Vergeichik <iverg@mail.ru> 2001 Copyright (C) Andrew Tridgell 2001 Copyright (C) Simo Sorce 2001 + Copyright (C) Martin Pool 2003 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -37,7 +38,6 @@ * @sa lib/iconv.c */ -static pstring cvtbuf; static smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS]; @@ -193,7 +193,7 @@ size_t convert_string(charset_t from, charset_t to, **/ size_t convert_string_allocate(charset_t from, charset_t to, - void const *src, size_t srclen, void **dest) + void const *src, size_t srclen, void **dest) { size_t i_len, o_len, destlen; size_t retval; @@ -277,6 +277,8 @@ static size_t convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t t void *alloced_string; size_t dest_len; + /* FIXME: Ridiculous to allocate two buffers and then copy the string! */ + *dest = NULL; dest_len=convert_string_allocate(from, to, src, srclen, &alloced_string); if (dest_len == (size_t)-1) @@ -291,21 +293,40 @@ static size_t convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t t size_t unix_strupper(const char *src, size_t srclen, char *dest, size_t destlen) { size_t size; - smb_ucs2_t *buffer=(smb_ucs2_t*)cvtbuf; - size=convert_string(CH_UNIX, CH_UCS2, src, srclen, buffer, sizeof(cvtbuf)); - if (!strupper_w(buffer) && (dest == src)) + smb_ucs2_t *buffer; + + size = convert_string_allocate(CH_UNIX, CH_UCS2, src, srclen, + (void **) &buffer); + if (size == -1) { + smb_panic("failed to create UCS2 buffer"); + } + if (!strupper_w(buffer) && (dest == src)) { + free(buffer); return srclen; - return convert_string(CH_UCS2, CH_UNIX, buffer, size, dest, destlen); + } + + size = convert_string(CH_UCS2, CH_UNIX, buffer, size, dest, destlen); + free(buffer); + return size; } size_t unix_strlower(const char *src, size_t srclen, char *dest, size_t destlen) { size_t size; - smb_ucs2_t *buffer=(smb_ucs2_t*)cvtbuf; - size=convert_string(CH_UNIX, CH_UCS2, src, srclen, buffer, sizeof(cvtbuf)); - if (!strlower_w(buffer) && (dest == src)) + smb_ucs2_t *buffer; + + size = convert_string_allocate(CH_UNIX, CH_UCS2, src, srclen, + (void **) &buffer); + if (size == -1) { + smb_panic("failed to create UCS2 buffer"); + } + if (!strlower_w(buffer) && (dest == src)) { + free(buffer); return srclen; - return convert_string(CH_UCS2, CH_UNIX, buffer, size, dest, destlen); + } + size = convert_string(CH_UCS2, CH_UNIX, buffer, size, dest, destlen); + free(buffer); + return size; } |