This increases the size of struct nbd_handle from about 700 bytes to instead being just under 5k; that's not too bad of a cost, and future patches will reuse same storage for logging any error messages during handshake. --- generator/states-reply-structured.c | 10 +++++++--- lib/internal.h | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/generator/states-reply-structured.c b/generator/states-reply-structured.c index 399f5e2..694c282 100644 --- a/generator/states-reply-structured.c +++ b/generator/states-reply-structured.c @@ -156,14 +156,14 @@ case 0: length = be32toh (h->sbuf.sr.structured_reply.length); msglen = be16toh (h->sbuf.sr.payload.error.len); - if (msglen > length - sizeof h->sbuf.sr.payload.error) { + if (msglen > length - sizeof h->sbuf.sr.payload.error || + msglen > sizeof h->sbuf.sr.err_msg) { SET_NEXT_STATE (%.DEAD); set_error (0, "error message length too large"); return -1; } - /* We skip the human readable error for now. XXX */ - h->rbuf = NULL; + h->rbuf = h->sbuf.sr.err_msg; h->rlen = msglen; SET_NEXT_STATE (%RECV_ERROR_MESSAGE); } @@ -182,6 +182,10 @@ length -= sizeof h->sbuf.sr.payload.error - msglen; + if (msglen) + debug (h, "structured error server message: %.*s", (int) msglen, + h->sbuf.sr.err_msg); + /* Special case two specific errors; ignore the tail for all others */ h->rbuf = NULL; h->rlen = length; diff --git a/lib/internal.h b/lib/internal.h index f5b1f95..6750938 100644 --- a/lib/internal.h +++ b/lib/internal.h @@ -138,6 +138,7 @@ struct nbd_handle { struct nbd_structured_reply_offset_hole offset_hole; struct nbd_structured_reply_error error; } payload; + char err_msg[NBD_MAX_STRING]; } __attribute__((packed)) sr; uint32_t cflags; uint32_t len; -- 2.20.1