You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Type-punning *(uint64_t*)(char[8]) is unsafe if the pointer is not
aligned per the requirements of the hardware (x86_64 has 1-byte
alignment, but other hardware exists that will give a SIGBUS). In
practice, it didn't matter - 'struct nbd_request' was already 64-bit
aligned for 'from' (even before the recent change in commit 739f712
to pack it), and 'struct nbd_reply' being packed means the compiler
emits code to deal with 1-byte alignment despite hardware. But since
the cookie is already opaque on the server side, we might as well
treat it as an 8-byte integer instead of a character array, with no
visible semantic changes to the client.
This patch does NOT perform endian swapping on the value. As long as
we are consistent (no swap when reading from the client, no swap when
writing back to the client), the client sees the same value. If we
were to log the cookie at any point in our local handling, then it
would be nice to obey the spec that all NBD values sent over the wire
are in network byte order (big-endian), so that what we log appears as
a 64-bit value with endianness matching whatever wireshark or the
client might be logging as well. But since we aren't logging the
cookie, skipping the byte-swaps doesn't hurt.
Signed-off-by: Eric Blake <[email protected]>
Message-Id: <[email protected]>
@@ -720,8 +720,8 @@ int read_packet_check_header(int sock, size_t datasize, long long int curcookie)
720
720
"Received package with incorrect reply_magic. Index of sent packages is %lld (0x%llX), received cookie is %lld (0x%llX). Received magic 0x%lX, expected 0x%lX",
721
721
(long long int)curcookie,
722
722
(long long unsigned int)curcookie,
723
-
(long long int)*((u64*) rep.cookie),
724
-
(long long unsigned int)*((u64*) rep.cookie),
723
+
(long long int)rep.cookie,
724
+
(long long unsigned int)rep.cookie,
725
725
(long unsigned int)rep.magic,
726
726
(long unsigned int)NBD_REPLY_MAGIC);
727
727
retval=-1;
@@ -731,8 +731,8 @@ int read_packet_check_header(int sock, size_t datasize, long long int curcookie)
731
731
snprintf(errstr, errstr_len,
732
732
"Received error from server: %ld (0x%lX). Cookie is %lld (0x%llX).",
0 commit comments