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

--- avahi-0.8/avahi-daemon/dbus-protocol.c.~1~	2020-02-17 05:41:02.384380713 +0200
+++ avahi-0.8/avahi-daemon/dbus-protocol.c	2025-04-19 23:47:16.591834861 +0300
@@ -375,10 +375,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;
 }
 
 static DBusHandlerResult dbus_get_alternative_service_name(DBusConnection *c, DBusMessage *m, DBusError *error) {
@@ -389,10 +393,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;
 }
 
 static DBusHandlerResult dbus_create_new_entry_group(DBusConnection *c, DBusMessage *m, DBusError *error) {