From cc87485942495f0d69010a193f51931abf4f0eec Mon Sep 17 00:00:00 2001
From: Thierry Fournier <thierry.fournier@ozon.io>
Date: Thu, 8 Mar 2018 09:59:02 +0100
Subject: [PATCH 2/3] BUG/MINOR: lua funtion hlua_socket_settimeout don't check
 negative values

Negatives timeouts doesn't have sense. A negative timeout doesn't cause
a crash, but the connection expires before the system try to extablish it.

This patch should be backported in all versions from 1.6
---
 src/hlua.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/hlua.c b/src/hlua.c
index b54f091..2d6ef43 100644
--- a/src/hlua.c
+++ b/src/hlua.c
@@ -2475,6 +2475,10 @@ __LJMP static int hlua_socket_settimeout(struct lua_State *L)
 	socket = MAY_LJMP(hlua_checksocket(L, 1));
 	tmout = MAY_LJMP(luaL_checkinteger(L, 2)) * 1000;
 
+	/* Check for negative values */
+	if (tmout < 0)
+		WILL_LJMP(luaL_error(L, "settimeout: cannot set negatives values"));
+
 	/* Check if we run on the same thread than the xreator thread.
 	 * We cannot access to the socket if the thread is different.
 	 */
-- 
2.10.1

