From: Pekka Riikonen Date: Sun, 27 Mar 2005 21:01:31 +0000 (+0000) Subject: Fixed length checking. X-Git-Tag: silc.server.0.9.19~36 X-Git-Url: http://git.silcnet.org/gitweb/?p=silc.git;a=commitdiff_plain;h=fd2b2f4d2232ff6762e413b1c3c7796889a8ee38 Fixed length checking. --- diff --git a/lib/silcutil/silcutf8.c b/lib/silcutil/silcutf8.c index 4d37c91e..6c4168c1 100644 --- a/lib/silcutil/silcutf8.c +++ b/lib/silcutil/silcutf8.c @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 2004 Pekka Riikonen + Copyright (C) 2004 - 2005 Pekka Riikonen 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 @@ -35,8 +35,13 @@ SilcUInt32 silc_utf8_encode(const unsigned char *bin, SilcUInt32 bin_len, if (!bin || !bin_len) return 0; - if (bin_encoding == SILC_STRING_UTF8 || - (silc_utf8_valid(bin, bin_len) && bin_len <= utf8_size)) { + if (bin_encoding == SILC_STRING_UTF8) { + if (!silc_utf8_valid(bin, bin_len)) + return 0; + if (!utf8) + return bin_len; + if (bin_len > utf8_size) + return 0; memcpy(utf8, bin, bin_len); return bin_len; }