[openwrt/openwrt] procd: make mDNS TXT record parsing more solid
LEDE Commits
lede-commits at lists.infradead.org
Mon Apr 29 14:31:03 PDT 2024
ansuel pushed a commit to openwrt/openwrt.git, branch openwrt-22.03:
https://git.openwrt.org/ebb3faf31f7c34d71e8ffbf3e8d94bf92086188e
commit ebb3faf31f7c34d71e8ffbf3e8d94bf92086188e
Author: Christian Marangi <ansuelsmth at gmail.com>
AuthorDate: Mon Apr 29 21:17:31 2024 +0200
procd: make mDNS TXT record parsing more solid
mDNS broadcast can't accept empty TXT record and would fail
registration.
Current procd_add_mdns_service checks only if the first passed arg is
empty but don't make any verification on the other args permittins
insertion of empty values in TXT record.
Example:
procd_add_mdns "blah" \
"tcp" "50" \
"1" \
"" \
"3"
Produce:
{ "blah_50": { "service": "_blah._tcp.local", "port": 50, "txt": [ "1", "", "3" ] } }
The middle empty TXT record should never be included as it's empty.
This can happen with scripts that make fragile parsing and include
variables even if they are empty.
Prevent this and make the TXT record more solid by checking every
provided TXT record and include only the non-empty ones.
The fixed JSON is the following:
{ "blah_50": { "service": "_blah._tcp.local", "port": 50, "txt": [ "1", "3" ] } }
Fixes: b0d9dcf84dd0 ("procd: update to latest git HEAD")
Reported-by: Paul Donald <newtwen at gmail.com>
Link: https://github.com/openwrt/openwrt/pull/15331
Signed-off-by: Christian Marangi <ansuelsmth at gmail.com>
(cherry picked from commit 4b043047132de0b3d90619d538f103af6153fa5a)
---
package/system/procd/files/procd.sh | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/package/system/procd/files/procd.sh b/package/system/procd/files/procd.sh
index 5148b2f03c..d834fa601a 100644
--- a/package/system/procd/files/procd.sh
+++ b/package/system/procd/files/procd.sh
@@ -570,18 +570,21 @@ _procd_set_config_changed() {
}
procd_add_mdns_service() {
- local service proto port
+ local service proto port txt_count=0
service=$1; shift
proto=$1; shift
port=$1; shift
json_add_object "${service}_$port"
json_add_string "service" "_$service._$proto.local"
json_add_int port "$port"
- [ -n "$1" ] && {
- json_add_array txt
- for txt in "$@"; do json_add_string "" "$txt"; done
- json_select ..
- }
+ for txt in "$@"; do
+ [ -z "$txt" ] && continue
+ txt_count=$((txt_count+1))
+ [ $txt_count -eq 1 ] && json_add_array txt
+ json_add_string "" "$txt"
+ done
+ [ $txt_count -gt 0 ] && json_select ..
+
json_select ..
}
More information about the lede-commits
mailing list