From 700a925fd9c1f1ff404e6b125cd5347ad7c45668 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Tue, 29 Nov 2022 11:44:15 +0100 Subject: [PATCH] fw4: prevent null access when no ipsets are defined When rules are configured which reference ipsets and no ipsets are declared at all, fw4 crashed with a null reference exception while validating the rule. Solve the issue by using the optional chaining operator on the potentially null filter result. Ref: https://forum.openwrt.org/t/x/144176 Signed-off-by: Jo-Philipp Wich --- root/usr/share/ucode/fw4.uc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/root/usr/share/ucode/fw4.uc b/root/usr/share/ucode/fw4.uc index 47e86cd..5dce90d 100644 --- a/root/usr/share/ucode/fw4.uc +++ b/root/usr/share/ucode/fw4.uc @@ -2305,7 +2305,7 @@ return { let ipset; if (rule.ipset) { - ipset = filter(this.state.ipsets, s => (s.name == rule.ipset.name))[0]; + ipset = filter(this.state.ipsets, s => (s.name == rule.ipset.name))?.[0]; if (!ipset) { this.warn_section(data, `references unknown set '${rule.ipset.name}'`); @@ -2605,7 +2605,7 @@ return { let ipset; if (redir.ipset) { - ipset = filter(this.state.ipsets, s => (s.name == redir.ipset.name))[0]; + ipset = filter(this.state.ipsets, s => (s.name == redir.ipset.name))?.[0]; if (!ipset) { this.warn_section(data, `references unknown set '${redir.ipset.name}'`); -- 2.30.2