From d42dcc1705034cf381d7d85f77bafc557ff58059 Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Sat, 3 Nov 2018 04:53:51 -0400 Subject: [PATCH] fix buffer overrun --- extensions/bingtranslate.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/extensions/bingtranslate.cpp b/extensions/bingtranslate.cpp index c8810c6..3a10fe3 100644 --- a/extensions/bingtranslate.cpp +++ b/extensions/bingtranslate.cpp @@ -1,6 +1,5 @@ #include "extension.h" #include -#include #include #include #include @@ -83,7 +82,7 @@ std::wstring Translate(std::wstring text, std::wstring& translateFrom, std::wstr if (!internet) internet = WinHttpOpen(L"Mozilla/5.0 Textractor", WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, NULL, NULL, 0); char buffer[10000] = {}; - WideCharToMultiByte(CP_UTF8, 0, text.c_str(), -1, buffer, text.size() * 5, NULL, NULL); + WideCharToMultiByte(CP_UTF8, 0, text.c_str(), -1, buffer, 10000, NULL, NULL); text.clear(); for (int i = 0; buffer[i];) { @@ -108,7 +107,6 @@ std::wstring Translate(std::wstring text, std::wstring& translateFrom, std::wstr char buffer[10000] = {}; WinHttpReceiveResponse(request, NULL); WinHttpReadData(request, buffer, 10000, &bytesRead); - puts(buffer); wchar_t wbuffer[10000] = {}; MultiByteToWideChar(CP_UTF8, 0, buffer, -1, wbuffer, 10000); if (translateFrom.empty()) translateFrom = wbuffer;