From 18bc76a0c6830358a137b4198e17b1b7ce92b9bf Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 27 Mar 2000 12:38:45 +0000 Subject: changed the definition of dos_PutUniCode the previous definition could result is us overflowing a buffer. The null termination was always added yet the size returned did not include the null termination. the new function takes a BOOL null_terminate, and always returns the total number of bytes consumed by the string. (This used to be commit 426c90433396a95033eefcc4af97603abc934221) --- source3/lib/util_unistr.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'source3/lib') diff --git a/source3/lib/util_unistr.c b/source3/lib/util_unistr.c index 27bd615bf4..6983d1100a 100644 --- a/source3/lib/util_unistr.c +++ b/source3/lib/util_unistr.c @@ -46,11 +46,13 @@ static uint16 *ucs2_to_unixcp; the current DOS codepage. len is the length in bytes of the string pointed to by dst. - the return value is the length of the string *without* the trailing - two bytes of zero + if null_terminate is True then null terminate the packet (adds 2 bytes) + + the return value is the length consumed by the string, including the + null termination if applied ********************************************************************/ -int dos_PutUniCode(char *dst,const char *src, ssize_t len) +int dos_PutUniCode(char *dst,const char *src, ssize_t len, BOOL null_terminate) { int ret = 0; while (*src && (len > 2)) { @@ -74,7 +76,10 @@ int dos_PutUniCode(char *dst,const char *src, ssize_t len) else src++; } - SSVAL(dst,ret,0); + if (null_terminate) { + SSVAL(dst,ret,0); + ret += 2; + } return(ret); } -- cgit