From f088a5c64913b3162edd87e6fbadba18ea8f0b55 Mon Sep 17 00:00:00 2001
From: Baptiste Assmann <bedis9@gmail.com>
Date: Mon, 2 Mar 2015 21:36:53 +0100
Subject: [PATCH 1/2] fix a segfault in txn.get_headers

When a lua script calls the function txn.get_headers in a proxy which is
not in HTTP mode, haproxy segfaults
---
 src/hlua.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/hlua.c b/src/hlua.c
index 35253fa..111a482 100644
--- a/src/hlua.c
+++ b/src/hlua.c
@@ -2410,6 +2410,11 @@ static int hlua_session_getheaders(lua_State *L)
 	const char *hn, *hv;
 	int hnl, hvl;
 
+	if ( (sess->fe && (sess->fe->mode != PR_MODE_HTTP)) ||
+			(sess->be && (sess->be->mode != PR_MODE_HTTP)) ) {
+		return 1;
+	}
+
 	/* Create the table. */
 	lua_newtable(L);
 
-- 
2.2.1

