Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid copying error message to limited size buffer to log #642

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions src/proto/nc_redis.c
Original file line number Diff line number Diff line change
Expand Up @@ -3206,26 +3206,21 @@ redis_swallow_msg(struct conn *conn, struct msg *pmsg, struct msg *msg)
{
if (pmsg != NULL && pmsg->type == MSG_REQ_REDIS_SELECT &&
msg != NULL && redis_error(msg)) {
struct server* conn_server;
struct server_pool* conn_pool;
struct mbuf* rsp_buffer;
uint8_t message[128];
size_t copy_len;
const struct server* conn_server;
const struct server_pool* conn_pool;
const struct mbuf* rsp_buffer;

/*
* Get a substring from the message so that the initial - and the trailing
* \r\n is removed.
*/
conn_server = (struct server*)conn->owner;
conn_pool = conn_server->owner;
rsp_buffer = STAILQ_LAST(&msg->mhdr, mbuf, next);
copy_len = MIN(mbuf_length(rsp_buffer) - 3, sizeof(message) - 1);

nc_memcpy(message, &rsp_buffer->start[1], copy_len);
message[copy_len] = 0;

log_warn("SELECT %d failed on %s | %s: %s",
/*
* Get a substring from the message so that the initial - and the trailing
* \r\n is removed.
*/
log_warn("SELECT %d failed on %s | %s: %.*s",
conn_pool->redis_db, conn_pool->name.data,
conn_server->name.data, message);
conn_server->name.data,
MAX((int)mbuf_length(rsp_buffer) - 3, 0), &rsp_buffer->start[1]);
}
}