diff options
author | Vladimír Čunát <vladimir.cunat@nic.cz> | 2024-09-12 14:54:16 +0200 |
---|---|---|
committer | Vladimír Čunát <vladimir.cunat@nic.cz> | 2024-09-12 15:37:21 +0200 |
commit | e6681fdd4ab8b017a2827f7c690283aaa97d0928 (patch) | |
tree | 199788a175e1cd1b9712ff2aa1bd4e37e7f8da34 | |
parent | Merge !1512: datamodel: additional headers for json-schema (diff) | |
download | knot-resolver-e6681fdd4ab8b017a2827f7c690283aaa97d0928.tar.xz knot-resolver-e6681fdd4ab8b017a2827f7c690283aaa97d0928.zip |
daemon/session2: fix error handling in *wrap_after()
We need to check the "< 0" condition *before*
incrementing or decrementing the returned layer_ix.
Detected by Coverity :-)
-rw-r--r-- | daemon/session2.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/daemon/session2.c b/daemon/session2.c index 0d1a69f5..8980ec0d 100644 --- a/daemon/session2.c +++ b/daemon/session2.c @@ -1189,11 +1189,11 @@ int session2_unwrap_after(struct session2 *s, enum protolayer_type protocol, const struct comm_info *comm, protolayer_finished_cb cb, void *baton) { - ssize_t layer_ix = session2_get_protocol(s, protocol) + 1; + ssize_t layer_ix = session2_get_protocol(s, protocol); if (layer_ix < 0) return layer_ix; return session2_submit(s, PROTOLAYER_UNWRAP, - layer_ix, payload, comm, cb, baton); + layer_ix + 1, payload, comm, cb, baton); } int session2_wrap(struct session2 *s, struct protolayer_payload payload, @@ -1210,10 +1210,10 @@ int session2_wrap_after(struct session2 *s, enum protolayer_type protocol, const struct comm_info *comm, protolayer_finished_cb cb, void *baton) { - ssize_t layer_ix = session2_get_protocol(s, protocol) - 1; + ssize_t layer_ix = session2_get_protocol(s, protocol); if (layer_ix < 0) return layer_ix; - return session2_submit(s, PROTOLAYER_WRAP, layer_ix, + return session2_submit(s, PROTOLAYER_WRAP, layer_ix - 1, payload, comm, cb, baton); } |