Fix RPC response length calculation - include header size
This commit is contained in:
parent
83e04ecc7e
commit
b555251a96
|
|
@ -231,7 +231,7 @@ static void respond(rpc_message_t *request, rpc_message_t *response) {
|
|||
response->value[value_length] = '\0';
|
||||
pdbg_logf(D_WARNING, "Response message truncated to fit buffer");
|
||||
}
|
||||
response->length = value_length + 1;
|
||||
response->length = offsetof(rpc_message_t, value) + value_length + 1;
|
||||
}
|
||||
|
||||
void prpc_main_loop() {
|
||||
|
|
|
|||
|
|
@ -143,9 +143,12 @@ int RpcClient::readResponse(int fd, char **out, size_t *out_size) {
|
|||
msg->length < header_size ||
|
||||
msg->length > (uint64_t)total_read ||
|
||||
msg->length > POVERLAY_BUFSIZE) {
|
||||
const char *error_msg = "Invalid response length";
|
||||
*out = strdup(error_msg);
|
||||
*out_size = strlen(error_msg) + 1;
|
||||
char error_buf[256];
|
||||
snprintf(error_buf, sizeof(error_buf),
|
||||
"Invalid response length: total_read=%zd header_size=%zu msg->length=%lu BUFSIZE=%d",
|
||||
total_read, header_size, (unsigned long)msg->length, POVERLAY_BUFSIZE);
|
||||
*out = strdup(error_buf);
|
||||
*out_size = strlen(error_buf) + 1;
|
||||
return POVERLAY_READ_INVALID_RESPONSE;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue