From 431c37f3a9fa4bdcdad70a334c74f99e96eaea8d Mon Sep 17 00:00:00 2001 From: "Pascal J. Bourguignon" Date: Fri, 26 Apr 2019 09:10:41 +0200 Subject: [PATCH] 5360 segfault using smartcard without any readers (#5361) * Fix: corrected test for astyle. * Fix: added test for NULL readers returned by ConvertFromUnicode. --- channels/smartcard/client/smartcard_operations.c | 8 ++++---- scripts/format_code.sh | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/channels/smartcard/client/smartcard_operations.c b/channels/smartcard/client/smartcard_operations.c index 47971f1fd..759085d41 100644 --- a/channels/smartcard/client/smartcard_operations.c +++ b/channels/smartcard/client/smartcard_operations.c @@ -493,21 +493,21 @@ static DWORD filter_device_by_name_w(wLinkedList* list, LPWSTR* mszReaders, DWOR { int res; DWORD rc; - LPSTR readers; + LPSTR readers = NULL; if (LinkedList_Count(list) < 1) return cchReaders; res = ConvertFromUnicode(CP_UTF8, 0, *mszReaders, (int)cchReaders, &readers, 0, NULL, - NULL); + NULL); - if ((res < 0) || ((DWORD)res != cchReaders)) + /* When res==0, readers may have been set to NULL by ConvertFromUnicode */ + if ((res < 0) || ((DWORD)res != cchReaders) || (readers == 0)) return 0; free(*mszReaders); *mszReaders = NULL; rc = filter_device_by_name_a(list, &readers, cchReaders); - res = ConvertToUnicode(CP_UTF8, 0, readers, (int)rc, mszReaders, 0); if ((res < 0) || ((DWORD)res != rc)) diff --git a/scripts/format_code.sh b/scripts/format_code.sh index 3ad769b13..f3561ba2f 100755 --- a/scripts/format_code.sh +++ b/scripts/format_code.sh @@ -2,7 +2,7 @@ ASTYLE=$(which astyle) -if [ ! -x $ASTYLE ]; then +if [ ! -x "$ASTYLE" ]; then echo "No astyle found in path, please install." exit 1 fi