From b66932e1a5dc3a368474e6e110c5a88a251465f5 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 16 Apr 2002 12:07:12 +0000 Subject: fixed the handling of STR_TERMINATE (This used to be commit dbc6b137a83cf9fe0558625dd32f92f15296fba6) --- source3/lib/charcnv.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'source3/lib/charcnv.c') diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index be7701237e3..803cda36c83 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -354,7 +354,13 @@ int pull_ascii(char *dest, const void *src, int dest_len, int src_len, int flags dest_len = sizeof(pstring); } - if (src_len == -1 && (flags & STR_TERMINATE)) src_len = strlen(src)+1; + if (flags & STR_TERMINATE) { + if (src_len == -1) { + src_len = strlen(src)+1; + } else { + src_len = strnlen(src, src_len) + 1; + } + } ret = convert_string(CH_DOS, CH_UNIX, src, src_len, dest, dest_len); @@ -543,7 +549,13 @@ int pull_ucs2(const void *base_ptr, char *dest, const void *src, int dest_len, i if (src_len > 0) src_len--; } - if (src_len == -1 && (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 { + src_len = strnlen_w(src, src_len/2)*2+2; + } + } /* ucs2 is always a multiple of 2 bytes */ src_len &= ~1; @@ -609,7 +621,13 @@ int pull_utf8(char *dest, const void *src, int dest_len, int src_len, int flags) dest_len = sizeof(pstring); } - if (src_len == -1 && (flags & STR_TERMINATE)) src_len = strlen(src)+1; + if (flags & STR_TERMINATE) { + if (src_len == -1) { + src_len = strlen(src)+1; + } else { + src_len = strnlen(src, src_len) + 1; + } + } ret = convert_string(CH_UTF8, CH_UNIX, src, src_len, dest, dest_len); if (dest_len) dest[MIN(ret, dest_len-1)] = 0; -- cgit