From: Oliver Kurth Date: Fri, 15 Sep 2017 18:23:00 +0000 (-0700) Subject: Hgfs Server: minor clean up of request header size X-Git-Tag: stable-10.2.0~571 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ce83118368eb727ef332e436b18ca667f194e5ce;p=thirdparty%2Fopen-vm-tools.git Hgfs Server: minor clean up of request header size Consistently use the correct function for determining the header size for the HGFS packet to be used. This is necessary due to the different protocol versions that exist, and originally the request and reply contained different protocol headers. --- diff --git a/open-vm-tools/lib/hgfsServer/hgfsServer.c b/open-vm-tools/lib/hgfsServer/hgfsServer.c index 5969e7d0f..eb987dc17 100644 --- a/open-vm-tools/lib/hgfsServer/hgfsServer.c +++ b/open-vm-tools/lib/hgfsServer/hgfsServer.c @@ -3090,12 +3090,12 @@ exit: /* *----------------------------------------------------------------------------- * - * HgfsServerGetRequestHeaderSize -- + * HgfsServerGetHeaderSize -- * - * Takes the Hgfs request input and finds the size of the header component. + * Takes the Hgfs input and finds the size of the header component. * * Results: - * Size of the HGFS protocol header used by this request and reply. + * Size of the HGFS protocol header used by this request or reply. * * Side effects: * None @@ -3104,22 +3104,26 @@ exit: */ static HgfsInternalStatus -HgfsServerGetRequestHeaderSize(HgfsInputParam *input) // IN: parameters +HgfsServerGetHeaderSize(Bool sessionEnabled, // IN: session based request + HgfsOp op, // IN: operation + Bool request) // IN: TRUE for request, FALSE for reply { size_t headerSize; /* * If the HGFS request is session enabled we must have the new header. + * Any V4 operation always must have the new header too. * Otherwise, starting from HGFS V3 the header is not included in the - * request itself, so we must return the size of the separate HgfsReply - * structure. Prior to V3 (so V1 and V2) there was no separate header - * from the request result structure so a zero size is returned for these - * operations. + * request itself, so we must return the size of the separate header + * structure, for requests this will be HgfsRequest and replies will be HgfsReply. + * Prior to V3 (so V1 and V2) there was no separate header from the request + * or reply structure for any given operation, so a zero size is returned for these. */ - if (input->sessionEnabled) { + if (sessionEnabled) { headerSize = sizeof (HgfsHeader); - } else if (input->op >= HGFS_OP_OPEN_V3) { - headerSize = sizeof (HgfsReply); + } else if (op < HGFS_OP_CREATE_SESSION_V4 && + op >= HGFS_OP_OPEN_V3) { + headerSize = (request ? sizeof (HgfsRequest) : sizeof (HgfsReply)); } else { headerSize = 0; } @@ -3127,6 +3131,56 @@ HgfsServerGetRequestHeaderSize(HgfsInputParam *input) // IN: parameters } +#if defined HGFS_SERVER_UNUSED +/* + *----------------------------------------------------------------------------- + * + * HgfsServerGetRequestHeaderSize -- + * + * Takes the Hgfs request input and finds the size of the header component. + * + * Results: + * Size of the HGFS protocol header used by this request and reply. + * + * Side effects: + * None + * + *----------------------------------------------------------------------------- + */ + +static HgfsInternalStatus +HgfsServerGetRequestHeaderSize(Bool sessionEnabled, // IN: session based request + HgfsOp op) // IN: operation +{ + return HgfsServerGetHeaderSize(sessionEnabled, op, TRUE); +} +#endif + + +/* + *----------------------------------------------------------------------------- + * + * HgfsServerGetReplyHeaderSize -- + * + * Takes the Hgfs reply input and finds the size of the header component. + * + * Results: + * Size of the HGFS protocol header used by this reply. + * + * Side effects: + * None + * + *----------------------------------------------------------------------------- + */ + +static HgfsInternalStatus +HgfsServerGetReplyHeaderSize(Bool sessionEnabled, // IN: session based request + HgfsOp op) // IN: operation +{ + return HgfsServerGetHeaderSize(sessionEnabled, op, FALSE); +} + + /* *----------------------------------------------------------------------------- * @@ -3165,7 +3219,8 @@ HgfsServerCompleteRequest(HgfsInternalStatus status, // IN: Status of the requ replySessionId = (NULL != input->session) ? input->session->sessionId : HGFS_INVALID_SESSION_ID; - replyHeaderSize = HgfsServerGetRequestHeaderSize(input); + replyHeaderSize = HgfsServerGetReplyHeaderSize(input->sessionEnabled, + input->op); if (replyHeaderSize != 0) { replySize = replyHeaderSize + replyPayloadSize; @@ -5963,7 +6018,7 @@ HgfsAllocInitReply(HgfsPacket *packet, // IN/OUT: Hgfs Packet void *replyData; /* - * XXX - this should be modified to use the common HgfsServerGetRequestHeaderSize + * XXX - this should be modified to use the common HgfsServerGetReplyHeaderSize * so that all requests and replies are handled consistently. */ if (HGFS_OP_NEW_HEADER == request->op) { @@ -6029,7 +6084,8 @@ HgfsServerValidateRead(HgfsInputParam *input, // IN: Input params Bool useMappedBuffer; useMappedBuffer = (input->transportSession->channelCbTable->getWriteVa != NULL); - replyReadHeaderSize = HgfsServerGetRequestHeaderSize(input); + replyReadHeaderSize = HgfsServerGetReplyHeaderSize(input->sessionEnabled, + input->op); switch (input->op) { case HGFS_OP_READ_FAST_V4: /* Data is packed into a separate buffer from the read results. */