]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: compression: handle a possible strdup() failure
authorIlia Shipitsin <chipitsine@gmail.com>
Fri, 27 Dec 2024 20:45:32 +0000 (21:45 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 2 Jan 2025 13:31:07 +0000 (14:31 +0100)
This defect was found by the coccinelle script "unchecked-strdup.cocci".
It can be backported to all supported branches.

src/compression.c

index a4464e09b68d622ecc7a5ec71979fc778894dd6d..1fe5aec3bfdaa57de0f1384e3926237dfc554975 100644 (file)
@@ -116,12 +116,19 @@ int comp_append_type(struct comp_type **types, const char *type)
 
        comp_type = calloc(1, sizeof(*comp_type));
        if (!comp_type)
-               return 1;
+               goto fail;
        comp_type->name_len = strlen(type);
        comp_type->name = strdup(type);
+       if (!comp_type->name)
+               goto fail_free_comp_type;
        comp_type->next = *types;
        *types = comp_type;
        return 0;
+
+fail_free_comp_type:
+       free(comp_type);
+fail:
+       return 1;
 }
 
 /*