Hello guys,

Here is a small patch which should fix an issue with Lua StickTable support. This adds support for "dictionary" like values in the stick table dump, most often encountered when you use "stick on" to persist sessions:

backend BE_NAME

    stick-table type ip size 1k

    stick on src

Best regards,
Adis
--
Adis Nezirovic
Software Engineer
HAProxy Technologies - Powering your uptime!
375 Totten Pond Road, Suite 302 | Waltham, MA 02451, US
+1 (844) 222-4340 | https://www.haproxy.com
>From fe8c56ea3b9f34a7664d469f0bee0c69a3939bd7 Mon Sep 17 00:00:00 2001
From: Adis Nezirovic <aneziro...@haproxy.com>
Date: Tue, 5 May 2020 13:57:28 +0200
Subject: [PATCH] MEDIUM: lua: Fix dumping of stick table entries for
 STD_T_DICT

The issue can easily be reproduced with "stick on" statement

backend BE_NAME
    stick-table type ip size 1k
    stick on src

and calling dump() method on BE_NAME stick table from Lua

Before the fix, HAProxy would return 500 and log something like
the following:
  runtime error: attempt to index a string value from [C] method 'dump'

Where one would expect a Lua table like this:

{
    ["IP_ADDR"] = {
        ["server_id"] = 1,
        ["server_name"] = "srv1"
    }
}

This patch needs to backported to 1.9 and later releases.
---
 src/hlua_fcn.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/hlua_fcn.c b/src/hlua_fcn.c
index e6f4d7379..9d4f2a715 100644
--- a/src/hlua_fcn.c
+++ b/src/hlua_fcn.c
@@ -588,6 +588,9 @@ static void hlua_stktable_entry(lua_State *L, struct stktable *t, struct stksess
 			lua_pushinteger(L, read_freq_ctr_period(&stktable_data_cast(ptr, std_t_frqp),
 			                t->data_arg[dt].u));
 			break;
+		case STD_T_DICT:
+			lua_pushstring(L, (char *)(stktable_data_cast(ptr, std_t_dict))->value.key);
+			break;
 		}
 
 		lua_settable(L, -3);
-- 
2.26.2

Reply via email to