From c922ebaab4184c9c4b2e5d40ded71a64a522bb63 Mon Sep 17 00:00:00 2001 From: Andreas Falkenhahn Date: Tue, 15 Nov 2022 21:35:59 +0100 Subject: [PATCH] Only call strlen() if CSA_SourceLen is not set When using CSA_SourceLen, the string passed in CSA_Source might not be NULL-terminated so we should not call strlen() on it. --- src/codesets.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/codesets.c b/src/codesets.c index 7fd17cb..6fbf861 100755 --- a/src/codesets.c +++ b/src/codesets.c @@ -2452,8 +2452,10 @@ LIBPROTO(CodesetsUTF8ToStrA, STRPTR, REG(a6, UNUSED __BASE_OR_IFACE), REG(a0, st ENTER(); - if((src = (UTF8 *)GetTagData(CSA_Source, 0, attrs)) != NULL && - (srcLen = GetTagData(CSA_SourceLen, src != NULL ? strlen((char *)src) : 0, attrs)) > 0) + src = (UTF8 *)GetTagData(CSA_Source, 0, attrs); + srcLen = FindTagItem(CSA_SourceLen, attrs) || !src ? GetTagData(CSA_SourceLen, 0, attrs) : strlen((char *)src); + + if(src != NULL && srcLen > 0) { struct convertMsg msg; struct codeset *codeset = NULL; @@ -3257,7 +3259,9 @@ LIBPROTO(CodesetsConvertStrA, STRPTR, REG(a6, UNUSED __BASE_OR_IFACE), REG(a0, s } else { - srcLen = strlen(srcStr); + if(!FindTagItem(CSA_SourceLen, attrs)) + srcLen = strlen(srcStr); + charSize = sizeof(char); } }