]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon/worker: simplify err handling in worker_submit()
authorTomas Krizek <tomas.krizek@nic.cz>
Tue, 8 Sep 2020 08:42:03 +0000 (10:42 +0200)
committerTomas Krizek <tomas.krizek@nic.cz>
Wed, 23 Sep 2020 11:08:12 +0000 (13:08 +0200)
If pkt was NULL, the function would return error from parse_packet(),
which would then have no effect besides returning an error code from
worker_submit(). There were also needless checks that pkt is indeed
not NULL in cases where it was no longer possible for it to be so.

This also removes assert(false) statements and simply return an error.

daemon/worker.c

index 97a2feeb858b5d220242cc810b1d4f0984b9c751..dc262003a15ea9078055d9d1d335430985358c54 100644 (file)
@@ -1571,17 +1571,12 @@ static int parse_packet(knot_pkt_t *query)
 
 int worker_submit(struct session *session, const struct sockaddr *peer, knot_pkt_t *pkt)
 {
-       if (!session) {
-               assert(false);
+       if (!session || !pkt)
                return kr_error(EINVAL);
-       }
 
        uv_handle_t *handle = session_get_handle(session);
-       bool OK = handle && handle->loop->data;
-       if (!OK) {
-               assert(false);
+       if (!handle || !handle->loop->data)
                return kr_error(EINVAL);
-       }
 
        int ret = parse_packet(pkt);
 
@@ -1590,7 +1585,7 @@ int worker_submit(struct session *session, const struct sockaddr *peer, knot_pkt
        /* Ignore badly formed queries. */
        if ((ret != kr_ok() && ret != kr_error(EMSGSIZE)) ||
            (is_query == is_outgoing)) {
-               if (pkt && !is_outgoing) the_worker->stats.dropped += 1;
+               if (!is_outgoing) the_worker->stats.dropped += 1;
                return kr_error(EILSEQ);
        }
 
@@ -1620,7 +1615,7 @@ int worker_submit(struct session *session, const struct sockaddr *peer, knot_pkt
                if (handle->type == UV_TCP && qr_task_register(task, session)) {
                        return kr_error(ENOMEM);
                }
-       } else if (pkt) { /* response from upstream */
+       } else { /* response from upstream */
                const uint16_t id = knot_wire_get_id(pkt->wire);
                task = session_tasklist_del_msgid(session, id);
                if (task == NULL) {