From: Christopher Faulet Date: Wed, 3 Jun 2020 16:39:16 +0000 (+0200) Subject: BUG/MEDIUM: hlua: Lock pattern references to perform set/add/del operations X-Git-Tag: v2.1.6~8 X-Git-Url: http://git.haproxy.org/?a=commitdiff_plain;h=1a97b5edef00991377ae2a6a97caa1b16b715dc1;p=haproxy-2.1.git BUG/MEDIUM: hlua: Lock pattern references to perform set/add/del operations The pattern references lock must be hold to perform set/add/del operations. Unfortunately, it is not true for the lua functions manipulating acl and map files. This patch should fix the issue #664. It must be backported as far as 1.8. (cherry picked from commit 5cf2dfc5fd08b7ff8d27d6293e2aaa8ec18fc607) Signed-off-by: Christopher Faulet --- diff --git a/src/hlua.c b/src/hlua.c index c632ed9..74f0f5f 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -1259,7 +1259,9 @@ __LJMP static int hlua_del_acl(lua_State *L) if (!ref) WILL_LJMP(luaL_error(L, "'del_acl': unknown acl file '%s'", name)); + HA_SPIN_LOCK(PATREF_LOCK, &ref->lock); pat_ref_delete(ref, key); + HA_SPIN_UNLOCK(PATREF_LOCK, &ref->lock); return 0; } @@ -1281,7 +1283,9 @@ static int hlua_del_map(lua_State *L) if (!ref) WILL_LJMP(luaL_error(L, "'del_map': unknown acl file '%s'", name)); + HA_SPIN_LOCK(PATREF_LOCK, &ref->lock); pat_ref_delete(ref, key); + HA_SPIN_UNLOCK(PATREF_LOCK, &ref->lock); return 0; } @@ -1303,8 +1307,10 @@ static int hlua_add_acl(lua_State *L) if (!ref) WILL_LJMP(luaL_error(L, "'add_acl': unknown acl file '%s'", name)); + HA_SPIN_LOCK(PATREF_LOCK, &ref->lock); if (pat_ref_find_elt(ref, key) == NULL) pat_ref_add(ref, key, NULL, NULL); + HA_SPIN_UNLOCK(PATREF_LOCK, &ref->lock); return 0; } @@ -1329,10 +1335,12 @@ static int hlua_set_map(lua_State *L) if (!ref) WILL_LJMP(luaL_error(L, "'set_map': unknown map file '%s'", name)); + HA_SPIN_LOCK(PATREF_LOCK, &ref->lock); if (pat_ref_find_elt(ref, key) != NULL) pat_ref_set(ref, key, value, NULL); else pat_ref_add(ref, key, value, NULL); + HA_SPIN_UNLOCK(PATREF_LOCK, &ref->lock); return 0; }