From 7ae5e14bbd7265cc67ec870c3bb0c8e197bb7ca9 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Tue, 18 Oct 2022 09:20:56 +0200 Subject: [PATCH] fw4: gracefully handle `null` return values from `fd.read("line")` Since ucode commit 4ae7072 "fs: use `getline()` for line wise read operations" a call to `fs.read("line")` will yield `null` instead of an empty string when encountering EOF, leading to an infinite loop when parsing loadfile entries. Solve this issue by checking both for `null` and empty string return values. Ref: https://forum.openwrt.org/t/x/139951/12 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 2a1e397..47e86cd 100644 --- a/root/usr/share/ucode/fw4.uc +++ b/root/usr/share/ucode/fw4.uc @@ -1785,9 +1785,9 @@ return { return; } - let line = null, count = 0; + let count = 0; - while ((line = fd.read("line")) !== "") { + for (let line = fd.read("line"); length(line); line = fd.read("line")) { line = trim(line); if (length(line) == 0 || ord(line) == 35) -- 2.30.2