diff --git a/thirdparty/vschannel/vschannel.c b/thirdparty/vschannel/vschannel.c index 3a484c7a83..5ce118f825 100644 --- a/thirdparty/vschannel/vschannel.c +++ b/thirdparty/vschannel/vschannel.c @@ -134,7 +134,7 @@ void vschannel_init() { tls_ctx.creds_initialized = TRUE; } -INT request(INT iport, CHAR *host, CHAR *req, CHAR *out) +INT request(INT iport, CHAR *host, CHAR *req, CHAR **out) { SecBuffer ExtraData; SECURITY_STATUS Status; @@ -201,7 +201,6 @@ INT request(INT iport, CHAR *host, CHAR *req, CHAR *out) return resp_length; } - // Send a close_notify alert to the server and // close down the connection. if(disconnect_from_server()) { @@ -774,7 +773,7 @@ static SECURITY_STATUS client_handshake_loop(BOOL fDoInitialRead, SecBuffer *pEx } -static SECURITY_STATUS https_make_request(CHAR *req, CHAR *out, int *length) { +static SECURITY_STATUS https_make_request(CHAR *req, CHAR **out, int *length) { SecPkgContext_StreamSizes Sizes; SECURITY_STATUS scRet; SecBufferDesc Message; @@ -860,6 +859,7 @@ static SECURITY_STATUS https_make_request(CHAR *req, CHAR *out, int *length) { } // Read data from server until done. + INT buff_size = vsc_init_resp_buff_size; cbIoBuffer = 0; while(TRUE){ // Read some data. @@ -936,10 +936,20 @@ static SECURITY_STATUS https_make_request(CHAR *req, CHAR *out, int *length) { } } + // increase buffer size if we need + int required_length = *length+(int)pDataBuffer->cbBuffer; + if( required_length > buff_size ) { + CHAR *a = realloc(*out, required_length); + if( a == NULL ) { + scRet = SEC_E_INTERNAL_ERROR; + return scRet; + } + *out = a; + buff_size = required_length; + } // Copy the decrypted data to our output buffer + memcpy(*out+*length, pDataBuffer->pvBuffer, (int)pDataBuffer->cbBuffer); *length += (int)pDataBuffer->cbBuffer; - memcpy(out, pDataBuffer->pvBuffer, (int)pDataBuffer->cbBuffer); - out += (int)pDataBuffer->cbBuffer; // Move any "extra" data to the input buffer. if(pExtraBuffer) { diff --git a/thirdparty/vschannel/vschannel.h b/thirdparty/vschannel/vschannel.h index b990f86615..4e6febafbe 100644 --- a/thirdparty/vschannel/vschannel.h +++ b/thirdparty/vschannel/vschannel.h @@ -11,6 +11,8 @@ #include #include +#define vsc_init_resp_buff_size 44000 + #define IO_BUFFER_SIZE 0x10000 #define TLS_MAX_BUFSIZ 32768 @@ -25,10 +27,10 @@ static void vschannel_init(); static void vschannel_cleanup(); -static INT request(INT iport, CHAR *host, CHAR *req, CHAR *out); +static INT request(INT iport, CHAR *host, CHAR *req, CHAR **out); static SECURITY_STATUS https_make_request( - CHAR *req, CHAR *out, int *length); + CHAR *req, CHAR **out, int *length); static INT connect_to_server(CHAR *host, INT port_number); diff --git a/vlib/http/backend_win.v b/vlib/http/backend_win.v index 2d123b9a46..42054bebd8 100644 --- a/vlib/http/backend_win.v +++ b/vlib/http/backend_win.v @@ -18,12 +18,10 @@ fn init_module() {} fn (req &Request) ssl_do(port int, method, host_name, path string) Response { C.vschannel_init() - // TODO: joe-c - // dynamically increase in vschannel.c if needed - mut buff := malloc(44000) + mut buff := malloc(C.vsc_init_resp_buff_size) addr := host_name sdata := req.build_request_headers(method, host_name, path) - length := int(C.request(port, addr.str, sdata.str, buff)) + length := int(C.request(port, addr.str, sdata.str, &buff)) C.vschannel_cleanup() return parse_response(string(buff, length))