HAProxy crashes when one use a bogus mode with core.register_service().
The 2nd argument must be "http" or "tcp", but any other value crashes HAProxy
when it displays the error message.

To reproduce:

haproxy.cfg:

global
    lua-load crash.lua


crash.lua:
function f() end
core.register_service("lua_svc", "bogus_mode", f);


The fix is attached.

>From ad97c5d05a1cf06bca1a3e99a33d55c51035f6b5 Mon Sep 17 00:00:00 2001
From: Eric Salama <[email protected]>
Date: Thu, 21 Dec 2017 14:30:07 +0100
Subject: [PATCH] MINOR: lua: fix crash when using bogus mode in
 register_service()

When using an incorrect 'mode' as 2nd argument of core.register_service(),
HAProxy crashes while displaying the error message.
---
 src/hlua.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/hlua.c b/src/hlua.c
index 2c28e673..abd096d0 100644
--- a/src/hlua.c
+++ b/src/hlua.c
@@ -6871,7 +6871,7 @@ __LJMP static int hlua_register_service(lua_State *L)
 		akl->kw[0].parse = action_register_service_http;
 	else
 		WILL_LJMP(luaL_error(L, "lua service environment '%s' is unknown. "
-		                        "'tcp' or 'http' are expected."));
+		                        "'tcp' or 'http' are expected.", env));
 
 	akl->kw[0].match_pfx = 0;
 	akl->kw[0].private = fcn;
-- 
2.14.2

Reply via email to