Commit 3f2baa8a authored by Olaf Hering's avatar Olaf Hering Committed by Greg Kroah-Hartman

Tools: hv: update buffer handling in hv_fcopy_daemon

Currently this warning is triggered when compiling hv_fcopy_daemon:

hv_fcopy_daemon.c:216:4: warning: dereferencing type-punned pointer will break
strict-aliasing rules [-Wstrict-aliasing]
    kernel_modver = *(__u32 *)buffer;

Convert the send/receive buffer to a union and pass individual members as
needed. This also gives the correct size for the buffer.
Signed-off-by: default avatarOlaf Hering <olaf@aepfle.de>
Signed-off-by: default avatarK. Y. Srinivasan <kys@microsoft.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 3619350c
...@@ -138,14 +138,17 @@ void print_usage(char *argv[]) ...@@ -138,14 +138,17 @@ void print_usage(char *argv[])
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int fcopy_fd, len; int fcopy_fd;
int error; int error;
int daemonize = 1, long_index = 0, opt; int daemonize = 1, long_index = 0, opt;
int version = FCOPY_CURRENT_VERSION; int version = FCOPY_CURRENT_VERSION;
char *buffer[4096 * 2]; union {
struct hv_fcopy_hdr *in_msg; struct hv_fcopy_hdr hdr;
int in_handshake = 1; struct hv_start_fcopy start;
struct hv_do_fcopy copy;
__u32 kernel_modver; __u32 kernel_modver;
} buffer = { };
int in_handshake = 1;
static struct option long_options[] = { static struct option long_options[] = {
{"help", no_argument, 0, 'h' }, {"help", no_argument, 0, 'h' },
...@@ -195,32 +198,31 @@ int main(int argc, char *argv[]) ...@@ -195,32 +198,31 @@ int main(int argc, char *argv[])
* In this loop we process fcopy messages after the * In this loop we process fcopy messages after the
* handshake is complete. * handshake is complete.
*/ */
len = pread(fcopy_fd, buffer, (4096 * 2), 0); ssize_t len;
len = pread(fcopy_fd, &buffer, sizeof(buffer), 0);
if (len < 0) { if (len < 0) {
syslog(LOG_ERR, "pread failed: %s", strerror(errno)); syslog(LOG_ERR, "pread failed: %s", strerror(errno));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (in_handshake) { if (in_handshake) {
if (len != sizeof(kernel_modver)) { if (len != sizeof(buffer.kernel_modver)) {
syslog(LOG_ERR, "invalid version negotiation"); syslog(LOG_ERR, "invalid version negotiation");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
kernel_modver = *(__u32 *)buffer;
in_handshake = 0; in_handshake = 0;
syslog(LOG_INFO, "kernel module version: %d", syslog(LOG_INFO, "kernel module version: %u",
kernel_modver); buffer.kernel_modver);
continue; continue;
} }
in_msg = (struct hv_fcopy_hdr *)buffer; switch (buffer.hdr.operation) {
switch (in_msg->operation) {
case START_FILE_COPY: case START_FILE_COPY:
error = hv_start_fcopy((struct hv_start_fcopy *)in_msg); error = hv_start_fcopy(&buffer.start);
break; break;
case WRITE_TO_FILE: case WRITE_TO_FILE:
error = hv_copy_data((struct hv_do_fcopy *)in_msg); error = hv_copy_data(&buffer.copy);
break; break;
case COMPLETE_FCOPY: case COMPLETE_FCOPY:
error = hv_copy_finished(); error = hv_copy_finished();
...@@ -231,7 +233,7 @@ int main(int argc, char *argv[]) ...@@ -231,7 +233,7 @@ int main(int argc, char *argv[])
default: default:
syslog(LOG_ERR, "Unknown operation: %d", syslog(LOG_ERR, "Unknown operation: %d",
in_msg->operation); buffer.hdr.operation);
} }
......
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