smartcard: Fix usage of uninitialized values
authorOndrej Holy <oholy@redhat.com>
Wed, 3 Jun 2020 10:28:32 +0000 (12:28 +0200)
committerakallabeth <akallabeth@posteo.net>
Tue, 16 Jun 2020 07:08:28 +0000 (09:08 +0200)
This fixes the following defect reported by covscan tool:
 - channels/smartcard/client/smartcard_pack.c:942: uninit_use_in_call: Using uninitialized value "tmp" when calling "ConvertFromUnicode".
 - channels/smartcard/client/smartcard_pack.c:894: uninit_use_in_call: Using uninitialized value "tmp" when calling "ConvertFromUnicode".
 - channels/smartcard/client/smartcard_pack.c:475: uninit_use_in_call: Using uninitialized value "tmp" when calling "ConvertFromUnicode".

(cherry picked from commit e70e25715f89aac823281d7c0674d2387f70f8a6)

channels/smartcard/client/smartcard_pack.c

index de0e1ce..8f7c92f 100644 (file)
@@ -389,7 +389,7 @@ static char* smartcard_msz_dump_a(const char* msz, size_t len, char* buffer, siz
 
 static char* smartcard_msz_dump_w(const WCHAR* msz, size_t len, char* buffer, size_t bufferLen)
 {
-       char* sz;
+       char* sz = NULL;
        ConvertFromUnicode(CP_UTF8, 0, msz, (int)len, &sz, 0, NULL, NULL);
        return smartcard_msz_dump_a(sz, len, buffer, bufferLen);
 }
@@ -466,7 +466,7 @@ static void smartcard_trace_context_and_string_call_w(const char* name,
                                                       const REDIR_SCARDCONTEXT* phContext,
                                                       const WCHAR* sz)
 {
-       char* tmp;
+       char* tmp = NULL;
        if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
                return;
 
@@ -883,7 +883,7 @@ static void smartcard_trace_write_cache_a_call(SMARTCARD_DEVICE* smartcard,
 static void smartcard_trace_write_cache_w_call(SMARTCARD_DEVICE* smartcard,
                                                const WriteCacheW_Call* call)
 {
-       char* tmp;
+       char* tmp = NULL;
        char buffer[1024];
        WINPR_UNUSED(smartcard);
        if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))
@@ -931,7 +931,7 @@ static void smartcard_trace_read_cache_a_call(SMARTCARD_DEVICE* smartcard,
 static void smartcard_trace_read_cache_w_call(SMARTCARD_DEVICE* smartcard,
                                               const ReadCacheW_Call* call)
 {
-       char* tmp;
+       char* tmp= NULL;
        char buffer[1024];
        WINPR_UNUSED(smartcard);
        if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel))