]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: addons/51degrees: handle memory allocation failures
authorIlia Shipitsin <chipitsine@gmail.com>
Wed, 13 May 2026 16:12:02 +0000 (18:12 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 31 May 2026 08:26:41 +0000 (10:26 +0200)
Found via cppcheck  --force --enable=all --output-file=haproxy.log :
addons/51degrees/51d.c:130:3: warning: If memory allocation fails, then
  there is a possible null pointer dereference: name [nullPointerOutOfMemory]
addons/51degrees/51d.c:922:4: warning: If memory allocation fails, then
   there is a possible null pointer dereference: _51d_property_list [nullPointerOutOfMemory]

addons/51degrees/51d.c

index be2dc61bd596fdfd0bc9fcb5a989adb425113226..ad49db1dd7738935c7f39baf68007acda4a2ea06 100644 (file)
@@ -127,7 +127,16 @@ static int _51d_property_name_list(char **args, int section_type, struct proxy *
 
        while (*(args[cur_arg])) {
                name = calloc(1, sizeof(*name));
+               if (!name) {
+                       memprintf(err, "'%s' failed to allocate memory.", args[0]);
+                       return -1;
+               }
                name->name = strdup(args[cur_arg]);
+               if (!name->name) {
+                       free(name);
+                       memprintf(err, "'%s' failed to allocate memory.", args[0]);
+                       return -1;
+               }
                LIST_APPEND(&global_51degrees.property_names, &name->list);
                ++cur_arg;
        }
@@ -928,6 +937,10 @@ static int init_51degrees(void)
                list_for_each_entry(name, &global_51degrees.property_names, list)
                        ++i;
                _51d_property_list = calloc(i, sizeof(*_51d_property_list));
+               if (!_51d_property_list) {
+                       ha_alert("51Degrees: Failed to allocate property list.\n");
+                       return (ERR_FATAL | ERR_ALERT);
+               }
 
                i = 0;
                list_for_each_entry(name, &global_51degrees.property_names, list)