Commit 32f52fe4 authored by Grigorii Demidov's avatar Grigorii Demidov

daemon: some minor coverity scan issues were fixed

parent ce28b173
......@@ -369,6 +369,7 @@ static int l_map(lua_State *L)
/* Read response */
uint32_t rlen = 0;
if (read(fd, &rlen, sizeof(rlen)) == sizeof(rlen)) {
expr_checked(rlen < UINT_MAX);
auto_free char *rbuf = malloc(rlen + 1);
expr_checked(rbuf != NULL);
expr_checked(read(fd, rbuf, rlen) == rlen);
......
......@@ -55,11 +55,19 @@ static void tty_read(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf)
/* Set output streams */
FILE *out = stdout, *outerr = stderr;
uv_os_fd_t stream_fd = 0;
uv_fileno((uv_handle_t *)stream, &stream_fd);
if (uv_fileno((uv_handle_t *)stream, &stream_fd)) {
uv_close((uv_handle_t *)stream, (uv_close_cb) free);
if (buf) {
free(buf->base);
}
return;
}
if (stream_fd != STDIN_FILENO) {
if (nread <= 0) { /* Close if disconnected */
uv_close((uv_handle_t *)stream, (uv_close_cb) free);
free(buf->base);
if (buf) {
free(buf->base);
}
return;
}
uv_os_fd_t dup_fd = dup(stream_fd);
......@@ -100,7 +108,9 @@ static void tty_read(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf)
lua_settop(L, 0);
}
fflush(out);
free(buf->base);
if (buf) {
free(buf->base);
}
/* Close if redirected */
if (stream_fd != STDIN_FILENO) {
fclose(out); /* outerr is the same */
......@@ -166,7 +176,12 @@ static void ipc_activity(uv_poll_t* handle, int status, int events)
/* Read expression from IPC pipe */
uint32_t len = 0;
if (ipc_readall(fd, (char *)&len, sizeof(len))) {
auto_free char *rbuf = malloc(len + 1);
auto_free char *rbuf = NULL;
if (len < UINT_MAX) {
rbuf = malloc(len + 1);
} else {
errno = EINVAL;
}
if (!rbuf) {
kr_log_error("[system] ipc: %s\n", strerror(errno));
engine_stop(engine); /* Panic and stop this fork. */
......
......@@ -29,7 +29,10 @@
uv_os_fd_t fd = 0; \
if (uv_fileno((uv_handle_t *)(handle), &fd) == 0) { \
int on = 1; \
setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &on, sizeof(on)); \
int ret = setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &on, sizeof(on)); \
if (ret) { \
return ret; \
} \
} \
} while (0)
/* libuv 1.7.0+ is able to assign fd immediately */
......
......@@ -454,6 +454,7 @@ static int process_answer(knot_pkt_t *pkt, struct kr_request *req)
/* Follow canonical name as next SNAME. */
if (!knot_dname_is_equal(cname, query->sname)) {
/* Check if target record has been already copied */
query->flags |= QUERY_CNAME;
if (is_final) {
const knot_pktsection_t *an = knot_pkt_section(req->answer, KNOT_ANSWER);
for (unsigned i = 0; i < an->count; ++i) {
......
......@@ -351,7 +351,8 @@ static int rrcache_stash(knot_layer_t *ctx, knot_pkt_t *pkt)
ret = stash_authority(qry, pkt, &stash, &req->pool);
}
/* Cache authority only if chasing referral/cname chain */
} else if (!is_auth || qry != array_tail(req->rplan.pending)) {
} else if (knot_pkt_section(pkt, KNOT_ANSWER)->count == 0 ||
qry->flags & QUERY_CNAME) {
ret = stash_authority(qry, pkt, &stash, &req->pool);
}
/* Cache DS records in referrals */
......
......@@ -47,7 +47,8 @@
X(DNSSEC_WEXPAND, 1 << 19) /**< Query response has wildcard expansion. */ \
X(PERMISSIVE, 1 << 20) /**< Permissive resolver mode. */ \
X(STRICT, 1 << 21) /**< Strict resolver mode. */ \
X(BADCOOKIE_AGAIN, 1 << 22) /**< Query again because bad cookie returned. */
X(BADCOOKIE_AGAIN, 1 << 22) /**< Query again because bad cookie returned. */ \
X(CNAME, 1 << 23) /**< Query response contains CNAME in answer section. */
/** Query flags */
enum kr_query_flag {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment