From e90b65284812aaa5ff9e9935ce9bbad7791cbbcd Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 15 Jul 2002 10:35:28 +0000 Subject: updated the 3.0 branch from the head branch - ready for alpha18 (This used to be commit 03ac082dcb375b6f3ca3d810a6a6367542bc23ce) --- source3/lib/charcnv.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index cdfca8eb97..d42dc994b0 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -143,7 +143,7 @@ size_t convert_string(charset_t from, charset_t to, switch(errno) { case EINVAL: reason="Incomplete multibyte sequence"; break; case E2BIG: reason="No more room"; - DEBUG(0, ("Required %d, available %d\n", + DEBUG(0, ("convert_string: Required %d, available %d\n", srclen, destlen)); /* we are not sure we need srclen bytes, may be more, may be less. @@ -354,7 +354,15 @@ int pull_ascii(char *dest, const void *src, int dest_len, int src_len, int flags dest_len = sizeof(pstring); } - if (flags & STR_TERMINATE) src_len = strlen(src)+1; + if (flags & STR_TERMINATE) { + if (src_len == -1) { + src_len = strlen(src) + 1; + } else { + int len = strnlen(src, src_len); + if (len < src_len) len++; + src_len = len; + } + } ret = convert_string(CH_DOS, CH_UNIX, src, src_len, dest, dest_len); @@ -525,7 +533,7 @@ copy a string from a ucs2 source to a unix char* destination flags can have: STR_TERMINATE means the string in src is null terminated STR_NOALIGN means don't try to align -if STR_TERMINATE is set then src_len is ignored +if STR_TERMINATE is set then src_len is ignored if it is -1 src_len is the length of the source area in bytes return the number of bytes occupied by the string in src the resulting string in "dest" is always null terminated @@ -543,7 +551,15 @@ int pull_ucs2(const void *base_ptr, char *dest, const void *src, int dest_len, i if (src_len > 0) src_len--; } - if (flags & STR_TERMINATE) src_len = strlen_w(src)*2+2; + if (flags & STR_TERMINATE) { + if (src_len == -1) { + src_len = strlen_w(src)*2 + 2; + } else { + int len = strnlen_w(src, src_len/2); + if (len < src_len/2) len++; + src_len = len*2; + } + } /* ucs2 is always a multiple of 2 bytes */ src_len &= ~1; @@ -609,7 +625,15 @@ int pull_utf8(char *dest, const void *src, int dest_len, int src_len, int flags) dest_len = sizeof(pstring); } - if (flags & STR_TERMINATE) src_len = strlen(src)+1; + if (flags & STR_TERMINATE) { + if (src_len == -1) { + src_len = strlen(src) + 1; + } else { + int len = strnlen(src, src_len); + if (len < src_len) len++; + src_len = len; + } + } ret = convert_string(CH_UTF8, CH_UNIX, src, src_len, dest, dest_len); if (dest_len) dest[MIN(ret, dest_len-1)] = 0; @@ -687,7 +711,7 @@ flags can have: STR_UNICODE means to force as unicode STR_ASCII use ascii even with unicode packet STR_NOALIGN means don't do alignment -if STR_TERMINATE is set then src_len is ignored +if STR_TERMINATE is set then src_len is ignored is it is -1 src_len is the length of the source area in bytes return the number of bytes occupied by the string in src the resulting string in "dest" is always null terminated -- cgit