From 72d86d498945f5c7bff2d1e5d75ed2fd2ba646a8 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 15 Apr 2021 19:56:59 +0000 Subject: [PATCH] smb2_server: change smbd_smb2_advance_incoming() to use iov_advance() In future we may use vectors with more elements, so we convert to a single element array now... Signed-off-by: Stefan Metzmacher Reviewed-by: Jeremy Allison --- source3/smbd/globals.h | 4 +++- source3/smbd/smb2_server.c | 47 +++++++++++++++++++++++++++++----------------- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/source3/smbd/globals.h b/source3/smbd/globals.h index db79d548035..fa10f00a2c1 100644 --- a/source3/smbd/globals.h +++ b/source3/smbd/globals.h @@ -461,7 +461,9 @@ struct smbXsrv_connection { struct { uint8_t nbt[NBT_HDR_SIZE]; } hdr; - struct iovec vector; + struct iovec _vector[1]; + struct iovec *vector; + int count; struct msghdr msg; bool doing_receivefile; size_t min_recv_size; diff --git a/source3/smbd/smb2_server.c b/source3/smbd/smb2_server.c index 3e47bc40425..1c15405373b 100644 --- a/source3/smbd/smb2_server.c +++ b/source3/smbd/smb2_server.c @@ -4589,10 +4589,14 @@ static NTSTATUS smbd_smb2_request_next_incoming(struct smbXsrv_connection *xconn *state = (struct smbd_smb2_request_read_state) { .req = req, .min_recv_size = lp_min_receive_file_size(), - .vector = (struct iovec) { - .iov_base = (void *)state->hdr.nbt, - .iov_len = NBT_HDR_SIZE, + ._vector = { + [0] = (struct iovec) { + .iov_base = (void *)state->hdr.nbt, + .iov_len = NBT_HDR_SIZE, + }, }, + .vector = state->_vector, + .count = 1, }; TEVENT_FD_READABLE(xconn->transport.fde); @@ -4879,7 +4883,7 @@ static NTSTATUS smbd_smb2_flush_send_queue(struct smbXsrv_connection *xconn) return NT_STATUS_OK; } -static NTSTATUS smbd_smb2_advance_incoming(struct smbXsrv_connection *xconn, int ret) +static NTSTATUS smbd_smb2_advance_incoming(struct smbXsrv_connection *xconn, size_t n) { struct smbd_server_connection *sconn = xconn->client->sconn; struct smbd_smb2_request_read_state *state = &xconn->smb2.request_read_state; @@ -4887,13 +4891,14 @@ static NTSTATUS smbd_smb2_advance_incoming(struct smbXsrv_connection *xconn, int size_t min_recvfile_size = UINT32_MAX; NTSTATUS status; NTTIME now; + bool ok; + + ok = iov_advance(&state->vector, &state->count, n); + if (!ok) { + return NT_STATUS_INTERNAL_ERROR; + } - if (ret < state->vector.iov_len) { - uint8_t *base; - base = (uint8_t *)state->vector.iov_base; - base += ret; - state->vector.iov_base = (void *)base; - state->vector.iov_len -= ret; + if (state->count > 0) { return NT_STATUS_PENDING; } @@ -4915,10 +4920,12 @@ static NTSTATUS smbd_smb2_advance_incoming(struct smbXsrv_connection *xconn, int return NT_STATUS_NO_MEMORY; } - state->vector = (struct iovec) { + state->_vector[0] = (struct iovec) { .iov_base = (void *)(state->pktbuf + ofs), .iov_len = (state->pktfull - ofs), }; + state->vector = state->_vector; + state->count = 1; state->pktlen = state->pktfull; return NT_STATUS_RETRY; @@ -4967,10 +4974,12 @@ static NTSTATUS smbd_smb2_advance_incoming(struct smbXsrv_connection *xconn, int return NT_STATUS_NO_MEMORY; } - state->vector = (struct iovec) { + state->_vector[0] = (struct iovec) { .iov_base = (void *)state->pktbuf, .iov_len = state->pktlen, }; + state->vector = state->_vector; + state->count = 1; return NT_STATUS_RETRY; @@ -4984,10 +4993,14 @@ got_full: *state = (struct smbd_smb2_request_read_state) { .req = req, .min_recv_size = lp_min_receive_file_size(), - .vector = (struct iovec) { - .iov_base = (void *)state->hdr.nbt, - .iov_len = NBT_HDR_SIZE, + ._vector = { + [0] = (struct iovec) { + .iov_base = (void *)state->hdr.nbt, + .iov_len = NBT_HDR_SIZE, + }, }, + .vector = state->_vector, + .count = 1, }; return NT_STATUS_RETRY; } @@ -5101,8 +5114,8 @@ static NTSTATUS smbd_smb2_io_handler(struct smbXsrv_connection *xconn, again: state->msg = (struct msghdr) { - .msg_iov = &state->vector, - .msg_iovlen = 1, + .msg_iov = state->vector, + .msg_iovlen = state->count, }; #ifdef MSG_NOSIGNAL -- 2.11.4.GIT