luaclient: fix result buffer overflow

Origin commit data
------------------
Branch: ni/coolstream
Commit: b568f26b95
Author: Jacek Jendrzej <overx300@gmail.com>
Date: 2019-06-11 (Tue, 11 Jun 2019)


------------------
No further description and justification available within origin commit message!

------------------
This commit was generated by Migit
This commit is contained in:
Jacek Jendrzej
2019-06-11 13:12:57 +02:00
committed by vanhofen
parent 5832fccfd0
commit bc6f49f68f

View File

@@ -76,7 +76,7 @@ int main(int argc, char** argv)
int res = -1;
const char *fun = NULL;
char *resp = NULL;
char result[size];
char *result = NULL;
if (!client.Send(data, size)) {
fun = "Send failed";
@@ -86,7 +86,10 @@ int main(int argc, char** argv)
fun = "Recv (1) failed";
goto fail;
}
if (!client.Recv(result, size)) {
if(size)
result = (char*) malloc(size);
if (result && !client.Recv(result, size)) {
fun = "Recv (2) failed";
goto fail;
}
@@ -102,8 +105,12 @@ int main(int argc, char** argv)
resp += strlen(resp) + 1;
if (resp < result + size)
fprintf(stderr, "%s", resp);
if(result)
free(result);
exit(res);
fail:
if(result)
free(result);
if (fun)
fprintf(stderr, "luaclient: %s.\n", fun);
exit(-1);