Skip to content
  • Eric Blake's avatar
    5f66d060
    nbd: Fix server reply to NBD_OPT_EXPORT_NAME of older clients · 5f66d060
    Eric Blake authored
    
    
    A typo in commit 23e099c3 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: default avatarEric Blake <eblake@redhat.com>
    Message-Id: <20170717192635.17880-3-eblake@redhat.com>
    Reviewed-by: default avatarJohn Snow <jsnow@redhat.com>
    5f66d060
    nbd: Fix server reply to NBD_OPT_EXPORT_NAME of older clients
    Eric Blake authored
    
    
    A typo in commit 23e099c3 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: default avatarEric Blake <eblake@redhat.com>
    Message-Id: <20170717192635.17880-3-eblake@redhat.com>
    Reviewed-by: default avatarJohn Snow <jsnow@redhat.com>
Loading