Module: wine Branch: master Commit: 60474096693b6f0ad0e31c09e57a393c3538f3e6 URL: https://source.winehq.org/git/wine.git/?a=commit;h=60474096693b6f0ad0e31c09e...
Author: Hans Leidekker hans@codeweavers.com Date: Thu Oct 28 20:19:28 2021 +0200
secur32: Fix error return for DTLS contexts in schan_InitializeSecurityContextW().
Signed-off-by: Hans Leidekker hans@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/secur32/schannel.c | 46 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 24 deletions(-)
diff --git a/dlls/secur32/schannel.c b/dlls/secur32/schannel.c index 5b1a910a361..895364a3fc7 100644 --- a/dlls/secur32/schannel.c +++ b/dlls/secur32/schannel.c @@ -880,6 +880,11 @@ static inline SIZE_T read_record_size(const BYTE *buf, SIZE_T header_size) return (buf[header_size - 2] << 8) | buf[header_size - 1]; }
+static inline BOOL is_dtls_context(const struct schan_context *ctx) +{ + return ctx->header_size == HEADER_SIZE_DTLS; +} + /*********************************************************************** * InitializeSecurityContextW */ @@ -985,35 +990,28 @@ static SECURITY_STATUS SEC_ENTRY schan_InitializeSecurityContextW( unsigned char *ptr;
if (!(ctx = schan_get_object(phContext->dwLower, SCHAN_HANDLE_CTX))) return SEC_E_INVALID_HANDLE; - if (pInput) - { - idx = schan_find_sec_buffer_idx(pInput, 0, SECBUFFER_TOKEN); - if (idx == -1) - return SEC_E_INCOMPLETE_MESSAGE; - - buffer = &pInput->pBuffers[idx]; - ptr = buffer->pvBuffer; - expected_size = 0; + if (!pInput) return is_dtls_context(ctx) ? SEC_E_INSUFFICIENT_MEMORY : SEC_E_INCOMPLETE_MESSAGE; + if ((idx = schan_find_sec_buffer_idx(pInput, 0, SECBUFFER_TOKEN)) == -1) return SEC_E_INCOMPLETE_MESSAGE;
- while (buffer->cbBuffer > expected_size + ctx->header_size) - { - record_size = ctx->header_size + read_record_size(ptr, ctx->header_size); + buffer = &pInput->pBuffers[idx]; + ptr = buffer->pvBuffer; + expected_size = 0;
- if (buffer->cbBuffer < expected_size + record_size) - break; + while (buffer->cbBuffer > expected_size + ctx->header_size) + { + record_size = ctx->header_size + read_record_size(ptr, ctx->header_size);
- expected_size += record_size; - ptr += record_size; - } + if (buffer->cbBuffer < expected_size + record_size) break; + expected_size += record_size; + ptr += record_size; + }
- if (!expected_size) - { - TRACE("Expected at least %lu bytes, but buffer only contains %u bytes.\n", - max(ctx->header_size + 1, record_size), buffer->cbBuffer); - return SEC_E_INCOMPLETE_MESSAGE; - } + if (!expected_size) + { + TRACE("Expected at least %lu bytes, but buffer only contains %u bytes.\n", + max(ctx->header_size + 1, record_size), buffer->cbBuffer); + return SEC_E_INCOMPLETE_MESSAGE; } - else return SEC_E_INCOMPLETE_MESSAGE;
TRACE("Using expected_size %lu.\n", expected_size); }