Patch taken from 
https://github.com/lathiat/avahi/commit/a2696da2f2c50ac43b6c4903f72290d5c3fa9f6f
and modified to apply with the current version 0.7.

--- avahi-0.7/avahi-daemon/dbus-protocol.c.orig	2023-04-23 23:24:34.611460338 -0700
+++ avahi-0.7/avahi-daemon/dbus-protocol.c	2023-04-23 23:28:32.220077728 -0700
@@ -391,11 +391,14 @@
         }
 
         t = avahi_alternative_host_name(n);
-        avahi_dbus_respond_string(c, m, t);
-        avahi_free(t);
+        if (t) {
+            avahi_dbus_respond_string(c, m, t);
+            avahi_free(t);
+            return DBUS_HANDLER_RESULT_HANDLED;
+        } else {
+            return avahi_dbus_respond_error(c, m, AVAHI_ERR_NOT_FOUND, "Hostname not found");
+        }
 
-        return DBUS_HANDLER_RESULT_HANDLED;
-
     } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetAlternativeServiceName")) {
         char *n, *t;
 
@@ -405,11 +408,14 @@
         }
 
         t = avahi_alternative_service_name(n);
-        avahi_dbus_respond_string(c, m, t);
-        avahi_free(t);
+        if (t) {
+            avahi_dbus_respond_string(c, m, t);
+            avahi_free(t);
+            return DBUS_HANDLER_RESULT_HANDLED;
+        } else {
+            return avahi_dbus_respond_error(c, m, AVAHI_ERR_NOT_FOUND, "Service not found");
+        }
 
-        return DBUS_HANDLER_RESULT_HANDLED;
-
     } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "EntryGroupNew")) {
         Client *client;
         EntryGroupInfo *i;