]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: hlua: Lock pattern references to perform set/add/del operations
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 3 Jun 2020 16:39:16 +0000 (18:39 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 3 Jun 2020 17:08:35 +0000 (19:08 +0200)
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.

src/hlua.c

index f2b6620448b3a43f2d685940790cc02628c61c60..d7afb5817aa846f5edc448b3b74edfdfb8c0184c 100644 (file)
@@ -1258,7 +1258,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;
 }
 
@@ -1280,7 +1282,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;
 }
 
@@ -1302,8 +1306,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;
 }
 
@@ -1328,10 +1334,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;
 }