BUG/MINOR: proxy: Missing calloc return value check in proxy_defproxy_cpy
authorRemi Tricot-Le Breton <rlebreton@haproxy.com>
Wed, 12 May 2021 16:07:27 +0000 (18:07 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 31 May 2021 13:30:35 +0000 (15:30 +0200)
A memory allocation failure happening in proxy_defproxy_cpy while
copying the default compression options would have resulted in a crash.
This function is called for every new proxy found while parsing the
configuration.

It was raised in GitHub issue #1233.
It could be backported to all stable branches.

(cherry picked from commit 18a82ba690a6ff4adbf9702cefa6dc89eb36372d)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 4d8e20f83cc07c08c1d562e6afc5b4d3a54f4058)
[Cf: Patch applied on cfgparse-listen.c]
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>

src/cfgparse-listen.c

index 01360fe..d5359ff 100644 (file)
@@ -449,6 +449,11 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                /* default compression options */
                if (defproxy.comp != NULL) {
                        curproxy->comp = calloc(1, sizeof(*curproxy->comp));
+                       if (!curproxy->comp) {
+                               ha_alert("parsing [%s:%d] : out of memory for default compression options", file, linenum);
+                               err_code |= ERR_ALERT | ERR_ABORT;
+                               goto out;
+                       }
                        curproxy->comp->algos = defproxy.comp->algos;
                        curproxy->comp->types = defproxy.comp->types;
                }