procd: make mDNS TXT record parsing more solid openwrt-22.03
authorChristian Marangi <ansuelsmth@gmail.com>
Mon, 29 Apr 2024 19:17:31 +0000 (21:17 +0200)
committerChristian Marangi <ansuelsmth@gmail.com>
Mon, 29 Apr 2024 21:30:57 +0000 (23:30 +0200)
commitebb3faf31f7c34d71e8ffbf3e8d94bf92086188e
tree3ff5434503c91bd7fe2fd1b3f49483fec0434fcd
parent5f07510cdc3e4712e7be3f9c4e99c8bb43522a9f
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@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/15331
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
(cherry picked from commit 4b043047132de0b3d90619d538f103af6153fa5a)
package/system/procd/files/procd.sh