Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

procd: make mDNS TXT record parsing more solid #15331

Merged
merged 1 commit into from Apr 29, 2024

Conversation

Ansuel
Copy link
Member

@Ansuel Ansuel commented Apr 29, 2024

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: b0d9dcf ("procd: update to latest git HEAD")
Reported-by: Paul Donald newtwen@gmail.com

@systemcrash
Copy link
Contributor

systemcrash commented Apr 29, 2024

Clean results here. Tested on v23.05.3.

Before you merge, could you also consider another commit to tackle pr 10715 - that's been waiting for years and is a really nice cosmetic fix in this code block also.

Edit: hang on... something isn't right

@Ansuel
Copy link
Member Author

Ansuel commented Apr 29, 2024

@systemcrash mh? tell me Also can you provide the combo you are using if it's ok to give?

@systemcrash
Copy link
Contributor

Sorry, false alarm. All is well. zero length entries are filtered out :D

Ansuel added a commit to Ansuel/openwrt that referenced this pull request Apr 29, 2024
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: b0d9dcf ("procd: update to latest git HEAD")
Reported-by: Paul Donald <newtwen@gmail.com>

Link: openwrt#15331
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
@Ansuel Ansuel force-pushed the improve-mdns-parsing branch 2 times, most recently from 8832c49 to 864346e Compare April 29, 2024 21:14
Ansuel added a commit to Ansuel/openwrt that referenced this pull request Apr 29, 2024
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: b0d9dcf ("procd: update to latest git HEAD")
Reported-by: Paul Donald <newtwen@gmail.com>
Link: openwrt#15331
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
Ansuel added a commit to Ansuel/openwrt that referenced this pull request Apr 29, 2024
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: b0d9dcf ("procd: update to latest git HEAD")
Reported-by: Paul Donald <newtwen@gmail.com>
Link: openwrt#15331
Link: openwrt#15331
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
@Ansuel Ansuel force-pushed the improve-mdns-parsing branch 2 times, most recently from 1bc03b5 to 864346e Compare April 29, 2024 21:24
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: b0d9dcf ("procd: update to latest git HEAD")
Reported-by: Paul Donald <newtwen@gmail.com>
Link: openwrt#15331
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
@openwrt-bot openwrt-bot merged commit 4b04304 into openwrt:main Apr 29, 2024
3 checks passed
openwrt-bot pushed a commit that referenced this pull request Apr 29, 2024
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: b0d9dcf ("procd: update to latest git HEAD")
Reported-by: Paul Donald <newtwen@gmail.com>
Link: #15331
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
(cherry picked from commit 4b04304)
openwrt-bot pushed a commit that referenced this pull request Apr 29, 2024
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: b0d9dcf ("procd: update to latest git HEAD")
Reported-by: Paul Donald <newtwen@gmail.com>
Link: #15331
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
(cherry picked from commit 4b04304)
@Ansuel
Copy link
Member Author

Ansuel commented Apr 29, 2024

Also backported to 23.05 and 22.03 :D

[ -z "$txt" ] && continue
txt_count=$((txt_count+1))
[ $txt_count -eq 1 ] && json_add_array txt
json_add_string "" "$txt"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pprindeville can you better explain?

@pprindeville
Copy link
Member

After the fact, but... LGTM

Vladdrako pushed a commit to Vladdrako/openwrt that referenced this pull request May 2, 2024
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: b0d9dcf ("procd: update to latest git HEAD")
Reported-by: Paul Donald <newtwen@gmail.com>
Link: openwrt#15331
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
@Ansuel
Copy link
Member Author

Ansuel commented May 2, 2024

@pprindeville sorry for not tagging :( i looked like a straight bug and a very safe fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core packages pull request/issue for core (in-tree) packages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants