From e219727d402cbe39d44e2d8d149bf893b1462403 Mon Sep 17 00:00:00 2001 From: rumtid Date: Sun, 16 Oct 2022 12:21:56 +0800 Subject: [PATCH] Fix an error check in utils (#1426) --- src/utils/utils-win.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/utils/utils-win.cpp b/src/utils/utils-win.cpp index 52bc8b419..4a7d099a3 100644 --- a/src/utils/utils-win.cpp +++ b/src/utils/utils-win.cpp @@ -283,7 +283,9 @@ char *b64encode(const char *input) { char buf[32767] = {0}; DWORD retlen = 32767; - CryptBinaryToString((BYTE*) input, strlen(input), CRYPT_STRING_BASE64 | CRYPT_STRING_NOCRLF, buf, &retlen); + if (!CryptBinaryToString((BYTE*) input, strlen(input), CRYPT_STRING_BASE64 | CRYPT_STRING_NOCRLF, buf, &retlen)) { + return NULL; + } return strdup(buf); } @@ -307,8 +309,10 @@ std::string getLocalPipeName(const char *pipe_name) } else { std::string ret(pipe_name); char *encoded = b64encode(user_name_buf); - ret += encoded; - free(encoded); + if (encoded) { + ret += encoded; + free(encoded); + } return ret; } }