]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
libsystemd-network: refuse too large raw_size
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 4 May 2022 06:45:13 +0000 (15:45 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 4 May 2022 06:46:19 +0000 (15:46 +0900)
Closes #23258.

src/libsystemd-network/lldp-neighbor.c
src/libsystemd-network/ndisc-router.c

index b05601998996d193b2dca1c30d27d0e14031bb60..f8394c4374a4030377577516d557f3e22b500213 100644 (file)
@@ -116,6 +116,9 @@ sd_lldp_neighbor *lldp_neighbor_unlink(sd_lldp_neighbor *n) {
 sd_lldp_neighbor *lldp_neighbor_new(size_t raw_size) {
         sd_lldp_neighbor *n;
 
+        if (raw_size > SIZE_MAX - ALIGN(sizeof(sd_lldp_neighbor)))
+                return NULL;
+
         n = malloc0(ALIGN(sizeof(sd_lldp_neighbor)) + raw_size);
         if (!n)
                 return NULL;
index 464b002c2f0cd686f90261ef3fb698f0229729f8..26615ac666e1edbc568d46ea8ac9a08771b182b6 100644 (file)
@@ -21,6 +21,9 @@ DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(sd_ndisc_router, sd_ndisc_router, mfree);
 sd_ndisc_router *ndisc_router_new(size_t raw_size) {
         sd_ndisc_router *rt;
 
+        if (raw_size > SIZE_MAX - ALIGN(sizeof(sd_ndisc_router)))
+                return NULL;
+
         rt = malloc0(ALIGN(sizeof(sd_ndisc_router)) + raw_size);
         if (!rt)
                 return NULL;