]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: map/lua: Return an error if a map is loaded during runtime
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 5 Aug 2020 21:23:37 +0000 (23:23 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 7 Aug 2020 12:18:27 +0000 (14:18 +0200)
In sample_load_map() function, the global mode is now tested to be sure to be in
the starting mode. If not, an error is returned.

At first glance, this patch may seem useless because maps are loaded during the
configuration parsing. But in fact, it is possible to load a map from the lua,
using Map:new() method. And, there is nothing to forbid to call this method at
runtime, during a script execution. It must never be done because it may perform
an filesystem access for unknown maps or allocation for known ones. So at
runtime, it means a blocking call or a memroy leak. Note it is still possible to
load a map from the lua, but in the global part of a script only. This part is
executed during the configuration parsing.

This patch must be backported in all stable versions.

src/map.c

index 405a84b54c6b765b793c51511f66430865ec9851..3e9aa41b2b21d2e9894f4b990e21a78efbc88c95 100644 (file)
--- a/src/map.c
+++ b/src/map.c
@@ -98,6 +98,11 @@ int sample_load_map(struct arg *arg, struct sample_conv *conv,
 {
        struct map_descriptor *desc;
 
+       if (!(global.mode & MODE_STARTING)) {
+               memprintf(err, "map: cannot load map at runtime");
+               return 0;
+       }
+
        /* create new map descriptor */
        desc = map_create_descriptor(conv);
        if (!desc) {