From: Jorge Pereira Date: Tue, 20 Jun 2023 04:43:51 +0000 (-0300) Subject: Some dhcpv6 fixes (#5071) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aa8a990f8bc7bfd583221c080b8474e0ff5f18d8;p=thirdparty%2Ffreeradius-server.git Some dhcpv6 fixes (#5071) * dhcpv6: Fix potential memory leak * dhcpv6: Fix typo in default virtual server * dhcpv6: Don't crash if 'interface' is empty. It fixes: Mon Jun 19 23:40:31 2023: Bootstrapping proto_dhcpv4 "dhcp.dhcpv4" Mon Jun 19 23:40:31 2023: Bootstrapping proto_dhcpv6 "dhcpv6.all_dhcp_servers_and_relays" Process 73144 stopped * thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0) frame #0: 0x00000001a68c853c libsystem_platform.dylib`_platform_strcmp + 12 libsystem_platform.dylib`: -> 0x1a68c853c <+12>: ldrb w5, [x1], #0x1 0x1a68c8540 <+16>: subs x3, x4, x5 0x1a68c8544 <+20>: ccmp w4, #0x0, #0x4, eq 0x1a68c8548 <+24>: b.ne 0x1a68c8530 ; <+0> (lldb) bt * thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0) * frame #0: 0x00000001a68c853c libsystem_platform.dylib`_platform_strcmp + 12 frame #1: 0x0000000100368d60 libfreeradius-util.dylib`fr_interface_to_ethernet(interface=0x0000000000000000, ethernet=0x0000600003e041b0) at inet.c:1570:7 frame #2: 0x0000000100ed7c7c proto_dhcpv6_udp.dylib`mod_bootstrap(mctx=0x000000016fdfdd60) at proto_dhcpv6_udp.c:564:9 frame #3: 0x00000001002aecbc libfreeradius-io.dylib`mod_bootstrap(mctx=0x000000016fdfe100) at master.c:2610:41 frame #4: 0x0000000100b85260 proto_dhcpv6.dylib`mod_bootstrap(mctx=0x000000016fdfe890) at proto_dhcpv6.c:470:9 frame #5: 0x0000000100619bd8 libfreeradius-server.dylib`module_bootstrap(mi=0x0000000102214890) at module.c:778:7 frame #6: 0x0000000100619d0c libfreeradius-server.dylib`modules_bootstrap(ml=0x0000600002fa85e0) at module.c:811:7 frame #7: 0x000000010066c9b0 libfreeradius-server.dylib`virtual_servers_bootstrap(config=0x0000000100ff2c30) at virtual_servers.c:1301:6 frame #8: 0x00000001005ce87c libfreeradius-server.dylib`server_init(cs=0x0000000100ff2c30) at base.c:68:6 frame #9: 0x00000001000043a0 radiusd`main(argc=7, argv=0x000000016fdfecb8) at radiusd.c:788:6 --- diff --git a/src/listen/dhcpv6/proto_dhcpv6.c b/src/listen/dhcpv6/proto_dhcpv6.c index 608596081f3..45d716f5cf9 100644 --- a/src/listen/dhcpv6/proto_dhcpv6.c +++ b/src/listen/dhcpv6/proto_dhcpv6.c @@ -430,7 +430,7 @@ static int mod_bootstrap(module_inst_ctx_t const *mctx) /* * Ensure that the server CONF_SECTION is always set. */ - inst->io.server_cs = cf_item_to_section(cf_parent(mctx->inst->data)); + inst->io.server_cs = cf_item_to_section(cf_parent(mctx->inst->conf)); fr_assert(dict_dhcpv6 != NULL); fr_assert(attr_packet_type != NULL); diff --git a/src/listen/dhcpv6/proto_dhcpv6_udp.c b/src/listen/dhcpv6/proto_dhcpv6_udp.c index c1ae787fac9..5bf7683fa63 100644 --- a/src/listen/dhcpv6/proto_dhcpv6_udp.c +++ b/src/listen/dhcpv6/proto_dhcpv6_udp.c @@ -561,7 +561,7 @@ static int mod_bootstrap(module_inst_ctx_t const *mctx) * Get the MAC address associated with this interface. * It can be used to create a server ID. */ - (void) fr_interface_to_ethernet(inst->interface, &inst->ethernet); + if (inst->interface) fr_interface_to_ethernet(inst->interface, &inst->ethernet); if (inst->recv_buff_is_set) { FR_INTEGER_BOUND_CHECK("recv_buff", inst->recv_buff, >=, 32); diff --git a/src/protocols/dhcpv6/base.c b/src/protocols/dhcpv6/base.c index a079ec2290c..b20681ab435 100644 --- a/src/protocols/dhcpv6/base.c +++ b/src/protocols/dhcpv6/base.c @@ -583,8 +583,6 @@ ssize_t fr_dhcpv6_decode(TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *pa fr_pair_t *vp; fr_pair_list_t tmp; - fr_pair_list_init(&tmp); - if (packet_len < DHCPV6_HDR_LEN) return 0; /* protect access to packet[0] */ /* @@ -593,6 +591,7 @@ ssize_t fr_dhcpv6_decode(TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *pa vp = fr_pair_afrom_da(ctx, attr_packet_type); if (!vp) return -1; + fr_pair_list_init(&tmp); vp->vp_uint32 = packet[0]; fr_pair_append(&tmp, vp);