From 18aeb3a12ac8298920b52f9d7876a1c6c81b8421 Mon Sep 17 00:00:00 2001 From: Oleksii Shevchuk Date: Mon, 19 Aug 2019 22:57:48 +0300 Subject: [PATCH] client/windows: do not fail in buffer exhaused --- client/sources/pupy_load.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/client/sources/pupy_load.c b/client/sources/pupy_load.c index b347156a..57cba072 100644 --- a/client/sources/pupy_load.c +++ b/client/sources/pupy_load.c @@ -110,13 +110,16 @@ LPSTR* CommandLineToArgvA(INT *pNumArgs) return NULL; } - bufLen = storage - numArgs * sizeof(LPSTR); - buffer = ((LPSTR)result) + numArgs * sizeof(LPSTR); + bufLen = storage - (numArgs * sizeof(LPSTR)); + buffer = ((LPSTR)result) + (numArgs * sizeof(LPSTR)); for (i = 0; i < numArgs; ++ i) { BOOL lpUsedDefaultChar = FALSE; - assert(bufLen > 0); + if (bufLen < 0) { + dprint("Buflen exhaused, arg %d (%d/%d)\n", i, bufLen, storage); + break; + } retval = WideCharToMultiByte( CP_UTF8, 0, args[i], -1, buffer,