diff --git a/pclsync/prpc.c b/pclsync/prpc.c index bbe94a6..221be7a 100644 --- a/pclsync/prpc.c +++ b/pclsync/prpc.c @@ -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() { diff --git a/rpcclient.cpp b/rpcclient.cpp index 9c2013e..c8b78c0 100644 --- a/rpcclient.cpp +++ b/rpcclient.cpp @@ -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; }