query_name: always return with NAK if service handle invalid
authorDavin McCall <davmac@davmac.org>
Mon, 23 Dec 2019 03:44:22 +0000 (13:44 +1000)
committerDavin McCall <davmac@davmac.org>
Mon, 23 Dec 2019 03:44:22 +0000 (13:44 +1000)
Existing code looks like a copy-pasto: returns ACK (not NAK?) and falls
through to a potential null-pointer dereference if the service handle
can't be found.

src/control.cc

index f9354c55b53717f52c084fe5f58b0a564fca09cc..ec8217da580c2d9dcf513238fca2fdf18b9f27db 100644 (file)
@@ -755,8 +755,8 @@ bool control_conn_t::process_query_name()
 
     service_record *service = find_service_for_key(handle);
     if (service == nullptr || service->get_name().length() > std::numeric_limits<uint16_t>::max()) {
-        char ack_rep[] = { DINIT_RP_ACK };
-        if (! queue_packet(ack_rep, 1)) return false;
+        char nak_rep[] = { DINIT_RP_NAK };
+        return queue_packet(nak_rep, 1);
     }
 
     std::vector<char> reply;