1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

http: allocate memory dynamically on Windows

This commit is contained in:
joe-conigliaro
2019-08-26 04:27:12 +10:00
committed by Alexander Medvednikov
parent ec4ff6e811
commit 836cc32d78
3 changed files with 21 additions and 11 deletions

View File

@ -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) {