nbd: Fix server reply to NBD_OPT_EXPORT_NAME of older clients
commit5f66d060dbc37214c9d70305710c3e34c4531d7c
authorEric Blake <eblake@redhat.com>
Mon, 17 Jul 2017 19:26:35 +0000 (17 14:26 -0500)
committerEric Blake <eblake@redhat.com>
Mon, 17 Jul 2017 22:06:46 +0000 (17 17:06 -0500)
treedb1d77cf9eb572c8639396f6c4ffc6aeada816cd
parent48000eb3ecfc91f6588dfafba51d57e7f8f28b7e
nbd: Fix server reply to NBD_OPT_EXPORT_NAME of older clients

A typo in commit 23e099c set the size of buf[] used in response
to NBD_OPT_EXPORT_NAME according to the length needed for old-style
negotiation (4 bytes of flag information) instead of the intended
2 bytes used in new style.  If the client doesn't enable
NBD_FLAG_C_NO_ZEROES, then the server sends two bytes too many,
and is then out of sync in response to the client's next command
(the bug is masked when modern qemu is the client, since we enable
the no zeroes flag).

While touching this code, add some more defines to nbd_internal.h
rather than having quite so many magic numbers in the .c; also,
use "" initialization rather than memset(), and tweak the oldstyle
negotiation to better match the spec description of the layout
(since the spec is big-endian, skipping two bytes as 0 followed by
writing a 2-byte flag is the same as writing a zero-extended 4-byte
flag), to make it a bit easier to follow compared to the spec.

[checkpatch.pl has some false positives in the comments]

Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <20170717192635.17880-3-eblake@redhat.com>
Reviewed-by: John Snow <jsnow@redhat.com>
nbd/nbd-internal.h
nbd/server.c