From 5b1b77ba950f5de7337bf1eb18637630a55d4dc5 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Thu, 29 Mar 2018 02:26:37 +0200 Subject: [PATCH] api: fix possible issue on linux --- api.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api.cpp b/api.cpp index 87d3095..9014f3a 100644 --- a/api.cpp +++ b/api.cpp @@ -1252,7 +1252,7 @@ static void api() char *wskey = NULL; n = recv(c, &buf[0], SOCK_REC_BUFSZ, 0); - fail = SOCKETFAIL(n); + fail = SOCKETFAIL(n) || n < 0; if (fail) buf[0] = '\0'; else if (n > 0 && buf[n-1] == '\n') { @@ -1261,7 +1261,7 @@ static void api() if (n > 0 && buf[n-1] == '\r') buf[n-1] = '\0'; } - buf[n] = '\0'; + else buf[n] = '\0'; //if (opt_debug && opt_protocol && n > 0) // applog(LOG_DEBUG, "API: recv command: (%d) '%s'+char(%x)", n, buf, buf[n-1]);