]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
net: Prevent overflows when allocating memory for arrays
authorLidong Chen <lidong.chen@oracle.com>
Wed, 22 Jan 2025 18:04:43 +0000 (18:04 +0000)
committerDaniel Kiper <daniel.kiper@oracle.com>
Thu, 13 Feb 2025 14:45:57 +0000 (15:45 +0100)
Use grub_calloc() when allocating memory for arrays to ensure proper
overflow checks are in place.

Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/net/dns.c
grub-core/net/net.c

index 39b0c46cf7108f3ed2e7f744ea9546dc28aae721..f20cd6f835c4042a8b4af2af0092ba02ac648457 100644 (file)
@@ -470,8 +470,8 @@ grub_net_dns_lookup (const char *name,
          && grub_get_time_ms () < dns_cache[h].limit_time)
        {
          grub_dprintf ("dns", "retrieved from cache\n");
-         *addresses = grub_malloc (dns_cache[h].naddresses
-                                   sizeof ((*addresses)[0]));
+         *addresses = grub_calloc (dns_cache[h].naddresses,
+                                   sizeof ((*addresses)[0]));
          if (!*addresses)
            return grub_errno;
          *naddresses = dns_cache[h].naddresses;
index 3ca7e0796dcb91c14b6886cd9b76be1a0dcee8de..1abdc097ffd1c7c25bfe7e0db374006fc3d0a121 100644 (file)
@@ -88,8 +88,8 @@ grub_net_link_layer_add_address (struct grub_net_card *card,
   /* Add sender to cache table.  */
   if (card->link_layer_table == NULL)
     {
-      card->link_layer_table = grub_zalloc (LINK_LAYER_CACHE_SIZE
-                                           sizeof (card->link_layer_table[0]));
+      card->link_layer_table = grub_calloc (LINK_LAYER_CACHE_SIZE,
+                                           sizeof (card->link_layer_table[0]));
       if (card->link_layer_table == NULL)
        return;
     }