From a93fdd980d2db5d453475c0aa2b39946bd6611bd Mon Sep 17 00:00:00 2001
From: Evgeny Vereshchagin <evvers@ya.ru>
Date: Wed, 1 Apr 2026 05:30:58 +0000
Subject: [PATCH] tests: make sure AVAHI_PUBLISH_USE_WIDE_AREA is refused

Upstream-Status: Backport [https://github.com/avahi/avahi/commit/a93fdd980d2db5d453475c0aa2b39946bd6611bd]
CVE: CVE-2026-34933
Signed-off-by: Vijay Anusuri <vanusuri@mvista.com>
---
 avahi-client/client-test.c | 25 +++++++++++++++++++++++++
 avahi-core/avahi-test.c    | 12 +++++++++++-
 2 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/avahi-client/client-test.c b/avahi-client/client-test.c
index 9a015d7..c80e12f 100644
--- a/avahi-client/client-test.c
+++ b/avahi-client/client-test.c
@@ -212,6 +212,28 @@ static void terminate(AVAHI_GCC_UNUSED AvahiTimeout *timeout, AVAHI_GCC_UNUSED v
     avahi_simple_poll_quit(simple_poll);
 }
 
+static void test_refuse_publish_flags(AvahiEntryGroup *g, AvahiPublishFlags flags, int expected) {
+    AvahiAddress a;
+    AvahiStringList *l = NULL;
+    int r;
+
+    r = avahi_entry_group_add_record(g, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, flags, "test.local", AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_CNAME, 120, "\0", 1);
+    assert(r == expected);
+
+    avahi_address_parse("224.0.0.251", AVAHI_PROTO_UNSPEC, &a);
+    r = avahi_entry_group_add_address(g, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, flags, "test.local", &a);
+    assert(r == expected);
+
+    r = avahi_entry_group_add_service_strlst(g, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, flags, "test", "_http._tcp", NULL, NULL, 80, l);
+    assert(r == expected);
+
+    r = avahi_entry_group_update_service_txt_strlst(g, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, flags, "test", "_http._tcp", NULL, l);
+    assert(r == expected);
+
+    r = avahi_entry_group_add_service_subtype(g, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, flags, "test", "_http._tcp", NULL, "_magic._sub._http._tcp");
+    assert(r == expected);
+}
+
 int main (AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) {
     AvahiClient *avahi;
     AvahiEntryGroup *group, *group2;
@@ -275,6 +297,9 @@ int main (AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) {
     error = avahi_entry_group_add_record (group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, "TestX", 0x01, 0x10, 120, "", 0);
     assert(error != AVAHI_OK);
 
+    test_refuse_publish_flags(group, AVAHI_PUBLISH_USE_WIDE_AREA, AVAHI_ERR_NOT_SUPPORTED);
+    test_refuse_publish_flags(group, AVAHI_PUBLISH_USE_WIDE_AREA|AVAHI_PUBLISH_USE_MULTICAST, AVAHI_ERR_INVALID_FLAGS);
+
     avahi_entry_group_commit (group);
 
     domain = avahi_domain_browser_new (avahi, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, NULL, AVAHI_DOMAIN_BROWSER_BROWSE, 0, avahi_domain_browser_callback, (char*) "omghai3u");
diff --git a/avahi-core/avahi-test.c b/avahi-core/avahi-test.c
index 2a7872b..2bae82b 100644
--- a/avahi-core/avahi-test.c
+++ b/avahi-core/avahi-test.c
@@ -30,6 +30,7 @@
 #include <netinet/in.h>
 #include <arpa/inet.h>
 
+#include <avahi-common/error.h>
 #include <avahi-common/malloc.h>
 #include <avahi-common/simple-watch.h>
 #include <avahi-common/alternative.h>
@@ -150,6 +151,7 @@ static void remove_entries(void) {
 static void create_entries(int new_name) {
     AvahiAddress a;
     AvahiRecord *r;
+    int error;
 
     remove_entries();
 
@@ -181,7 +183,15 @@ static void create_entries(int new_name) {
         goto fail;
     }
 
-    if (avahi_server_add_dns_server_address(server, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, NULL, AVAHI_DNS_SERVER_RESOLVE, avahi_address_parse("192.168.50.1", AVAHI_PROTO_UNSPEC, &a), 53) < 0) {
+    avahi_address_parse("192.168.50.1", AVAHI_PROTO_UNSPEC, &a);
+
+    error = avahi_server_add_dns_server_address(server, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, AVAHI_PUBLISH_USE_WIDE_AREA, NULL, AVAHI_DNS_SERVER_RESOLVE, &a, 53);
+    assert(error == AVAHI_ERR_NOT_SUPPORTED);
+
+    error = avahi_server_add_dns_server_address(server, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, AVAHI_PUBLISH_USE_WIDE_AREA|AVAHI_PUBLISH_USE_MULTICAST, NULL, AVAHI_DNS_SERVER_RESOLVE, &a, 53);
+    assert(error == AVAHI_ERR_INVALID_FLAGS);
+
+    if (avahi_server_add_dns_server_address(server, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, NULL, AVAHI_DNS_SERVER_RESOLVE, &a, 53) < 0) {
         avahi_log_error("Failed to add new DNS Server address");
         goto fail;
     }
-- 
2.43.0

