From 66ad508b455f45960a643f37d271763c02e2bb3f Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Tue, 29 Oct 2019 11:25:44 +0100 Subject: [PATCH] Removed strlen use in wlog (and speed up check) --- winpr/libwinpr/utils/wlog/Appender.c | 3 ++- winpr/libwinpr/utils/wlog/BinaryAppender.c | 9 +++++---- winpr/libwinpr/utils/wlog/ConsoleAppender.c | 3 ++- winpr/libwinpr/utils/wlog/FileAppender.c | 3 ++- winpr/libwinpr/utils/wlog/JournaldAppender.c | 3 ++- winpr/libwinpr/utils/wlog/UdpAppender.c | 10 ++++++---- 6 files changed, 19 insertions(+), 12 deletions(-) diff --git a/winpr/libwinpr/utils/wlog/Appender.c b/winpr/libwinpr/utils/wlog/Appender.c index 6a331c2..4a5324a 100644 --- a/winpr/libwinpr/utils/wlog/Appender.c +++ b/winpr/libwinpr/utils/wlog/Appender.c @@ -167,7 +167,8 @@ BOOL WLog_SetLogAppenderType(wLog* log, DWORD logAppenderType) BOOL WLog_ConfigureAppender(wLogAppender *appender, const char *setting, void *value) { - if (!appender || !setting || !strlen(setting)) + /* Just check the settings string is not empty */ + if (!appender || !setting || (strnlen(setting, 2) == 0)) return FALSE; if (appender->Set) diff --git a/winpr/libwinpr/utils/wlog/BinaryAppender.c b/winpr/libwinpr/utils/wlog/BinaryAppender.c index 17562bb..dcfb0e7 100644 --- a/winpr/libwinpr/utils/wlog/BinaryAppender.c +++ b/winpr/libwinpr/utils/wlog/BinaryAppender.c @@ -124,9 +124,9 @@ static BOOL WLog_BinaryAppender_WriteMessage(wLog* log, wLogAppender* appender, if (!fp) return FALSE; - FileNameLength = strlen(message->FileName); - FunctionNameLength = strlen(message->FunctionName); - TextStringLength = strlen(message->TextString); + FileNameLength = strnlen(message->FileName, UINT32_MAX); + FunctionNameLength = strnlen(message->FunctionName, UINT32_MAX); + TextStringLength = strnlen(message->TextString, UINT32_MAX); MessageLength = 16 + (4 + FileNameLength + 1) + @@ -180,7 +180,8 @@ static BOOL WLog_BinaryAppender_Set(wLogAppender* appender, const char *setting, { wLogBinaryAppender *binaryAppender = (wLogBinaryAppender *) appender; - if (!value || !strlen(value)) + /* Just check if the value string is longer than 0 */ + if (!value || (strnlen(value, 2) == 0)) return FALSE; if (!strcmp("outputfilename", setting)) diff --git a/winpr/libwinpr/utils/wlog/ConsoleAppender.c b/winpr/libwinpr/utils/wlog/ConsoleAppender.c index 36bcf6f..2e1274f 100644 --- a/winpr/libwinpr/utils/wlog/ConsoleAppender.c +++ b/winpr/libwinpr/utils/wlog/ConsoleAppender.c @@ -214,7 +214,8 @@ static BOOL WLog_ConsoleAppender_Set(wLogAppender* appender, const char *setting { wLogConsoleAppender *consoleAppender = (wLogConsoleAppender *)appender; - if (!value || !strlen(value)) + /* Just check the value string is not empty */ + if (!value || (strnlen(value, 2) == 0)) return FALSE; if (strcmp("outputstream", setting)) diff --git a/winpr/libwinpr/utils/wlog/FileAppender.c b/winpr/libwinpr/utils/wlog/FileAppender.c index 5eeb77d..a8b3403 100644 --- a/winpr/libwinpr/utils/wlog/FileAppender.c +++ b/winpr/libwinpr/utils/wlog/FileAppender.c @@ -192,7 +192,8 @@ static BOOL WLog_FileAppender_Set(wLogAppender* appender, const char* setting, v { wLogFileAppender* fileAppender = (wLogFileAppender*) appender; - if (!value || !strlen(value)) + /* Just check the value string is not empty */ + if (!value || (strnlen(value, 2) == 0)) return FALSE; if (!strcmp("outputfilename", setting)) diff --git a/winpr/libwinpr/utils/wlog/JournaldAppender.c b/winpr/libwinpr/utils/wlog/JournaldAppender.c index 5854c95..eded5be 100644 --- a/winpr/libwinpr/utils/wlog/JournaldAppender.c +++ b/winpr/libwinpr/utils/wlog/JournaldAppender.c @@ -140,7 +140,8 @@ static BOOL WLog_JournaldAppender_Set(wLogAppender* appender, const char *settin { wLogJournaldAppender* journaldAppender = (wLogJournaldAppender *)appender; - if (!value || !strlen(value)) + /* Just check the value string is not empty */ + if (!value || (strnlen(value, 2) == 0)) return FALSE; if (strcmp("identifier", setting)) diff --git a/winpr/libwinpr/utils/wlog/UdpAppender.c b/winpr/libwinpr/utils/wlog/UdpAppender.c index 0bfd74a..7ed26a6 100644 --- a/winpr/libwinpr/utils/wlog/UdpAppender.c +++ b/winpr/libwinpr/utils/wlog/UdpAppender.c @@ -104,9 +104,9 @@ static BOOL WLog_UdpAppender_WriteMessage(wLog* log, wLogAppender* appender, wLo udpAppender = (wLogUdpAppender*)appender; message->PrefixString = prefix; WLog_Layout_GetMessagePrefix(log, appender->Layout, message); - _sendto(udpAppender->sock, message->PrefixString, strlen(message->PrefixString), + _sendto(udpAppender->sock, message->PrefixString, (int)strnlen(message->PrefixString, INT_MAX), 0, &udpAppender->targetAddr, udpAppender->targetAddrLen); - _sendto(udpAppender->sock, message->TextString, strlen(message->TextString), + _sendto(udpAppender->sock, message->TextString, (int)strnlen(message->TextString, INT_MAX), 0, &udpAppender->targetAddr, udpAppender->targetAddrLen); _sendto(udpAppender->sock, "\n", 1, 0, &udpAppender->targetAddr, udpAppender->targetAddrLen); return TRUE; @@ -132,12 +132,14 @@ static BOOL WLog_UdpAppender_WriteImageMessage(wLog* log, wLogAppender* appender static BOOL WLog_UdpAppender_Set(wLogAppender* appender, const char* setting, void* value) { + const char target[] = "target"; wLogUdpAppender* udpAppender = (wLogUdpAppender*)appender; - if (!value || !strlen(value)) + /* Just check the value string is not empty */ + if (!value || (strnlen(value, 2) == 0)) return FALSE; - if (strcmp("target", setting)) + if (strncmp(target, setting, sizeof(target))) return FALSE; udpAppender->targetAddrLen = 0; -- 2.7.4