]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: acme: check acme-vars allocation during escaping 20250918-acme-vars
authorWilliam Lallemand <wlallemand@haproxy.com>
Fri, 19 Sep 2025 15:13:24 +0000 (17:13 +0200)
committerWilliam Lallemand <wlallemand@haproxy.com>
Fri, 19 Sep 2025 16:11:50 +0000 (18:11 +0200)
Handle allocation properly during acme-vars parsing.
Check if we have a allocation failure in both the malloc and the
realloc and emits an error if that's the case.

src/acme.c

index bc16ced4be915dcfeafa9551b662e501555d688d..7fb270a901e053b695abd9cbbd1cc6501ea13db8 100644 (file)
@@ -455,20 +455,29 @@ static int cfg_parse_acme_kws(char **args, int section_type, struct proxy *curpx
                        goto out;
 
                len = strlen(src);
-               dst = realloc(dst, len + 1);
+               dst = malloc(len + 1);
+               if (!dst)
+                       goto vars_end;
 
                /* escape the " character */
                while (*src) {
                        if (*src == '"') {
+                               char *dst2 = NULL;
+
                                len++;
-                               dst = realloc(dst, len + 1);
+                               dst2 = realloc(dst, len + 1);
+                               if (!dst2) {
+                                       ha_free(&dst);
+                                       goto vars_end;
+                               }
+                               dst = dst2;
                                dst[i++] = '\\'; /* add escaping */
                        }
                        dst[i++] = *src;
                        src++;
                }
                dst[i] = '\0';
-
+vars_end:
                cur_acme->vars = dst;
                if (!cur_acme->vars) {
                        err_code |= ERR_ALERT | ERR_FATAL;