[warnings] fix integer narrowing

fix function freerdp_tls_write_all
This commit is contained in:
akallabeth 2024-10-03 14:48:10 +02:00
parent 503b9f0bb7
commit f00d9c45e0
No known key found for this signature in database
GPG Key ID: A49454A3FC909FD5
5 changed files with 19 additions and 31 deletions

View File

@ -239,8 +239,6 @@ static BOOL arm_send_http_request(rdpArm* arm, rdpTls* tls, const char* method,
return FALSE; return FALSE;
const size_t sz = Stream_Length(s); const size_t sz = Stream_Length(s);
if (sz <= INT_MAX)
status = freerdp_tls_write_all(tls, Stream_Buffer(s), sz); status = freerdp_tls_write_all(tls, Stream_Buffer(s), sz);
Stream_Free(s, TRUE); Stream_Free(s, TRUE);

View File

@ -1238,17 +1238,13 @@ static BOOL rdg_auth_init(rdpRdg* rdg, rdpTls* tls, TCHAR* authPkg)
static BOOL rdg_send_http_request(rdpRdg* rdg, rdpTls* tls, const char* method, static BOOL rdg_send_http_request(rdpRdg* rdg, rdpTls* tls, const char* method,
TRANSFER_ENCODING transferEncoding) TRANSFER_ENCODING transferEncoding)
{ {
size_t sz = 0;
wStream* s = NULL;
int status = -1; int status = -1;
s = rdg_build_http_request(rdg, method, transferEncoding); wStream* s = rdg_build_http_request(rdg, method, transferEncoding);
if (!s) if (!s)
return FALSE; return FALSE;
sz = Stream_Length(s); const size_t sz = Stream_Length(s);
if (sz <= INT_MAX)
status = freerdp_tls_write_all(tls, Stream_Buffer(s), sz); status = freerdp_tls_write_all(tls, Stream_Buffer(s), sz);
Stream_Free(s, TRUE); Stream_Free(s, TRUE);

View File

@ -332,21 +332,15 @@ out:
static BOOL wst_send_http_request(rdpWst* wst, rdpTls* tls) static BOOL wst_send_http_request(rdpWst* wst, rdpTls* tls)
{ {
size_t sz = 0;
wStream* s = NULL;
int status = -1;
WINPR_ASSERT(wst); WINPR_ASSERT(wst);
WINPR_ASSERT(tls); WINPR_ASSERT(tls);
s = wst_build_http_request(wst); wStream* s = wst_build_http_request(wst);
if (!s) if (!s)
return FALSE; return FALSE;
sz = Stream_Length(s); const size_t sz = Stream_Length(s);
int status = freerdp_tls_write_all(tls, Stream_Buffer(s), sz);
if (sz <= INT_MAX)
status = freerdp_tls_write_all(tls, Stream_Buffer(s), sz);
Stream_Free(s, TRUE); Stream_Free(s, TRUE);
return (status >= 0); return (status >= 0);

View File

@ -1236,22 +1236,22 @@ BOOL freerdp_tls_send_alert(rdpTls* tls)
return TRUE; return TRUE;
} }
int freerdp_tls_write_all(rdpTls* tls, const BYTE* data, int length) int freerdp_tls_write_all(rdpTls* tls, const BYTE* data, size_t length)
{ {
WINPR_ASSERT(tls); WINPR_ASSERT(tls);
int offset = 0; size_t offset = 0;
BIO* bio = tls->bio; BIO* bio = tls->bio;
if (length > INT32_MAX)
return -1;
while (offset < length) while (offset < length)
{ {
ERR_clear_error(); ERR_clear_error();
const int rc = BIO_write(bio, &data[offset], length - offset); const int status = BIO_write(bio, &data[offset], (int)(length - offset));
if (rc < 0) if (status > 0)
return rc; offset += (size_t)status;
if (rc > 0)
offset += rc;
else else
{ {
if (!BIO_should_retry(bio)) if (!BIO_should_retry(bio))
@ -1259,8 +1259,8 @@ int freerdp_tls_write_all(rdpTls* tls, const BYTE* data, int length)
if (BIO_write_blocked(bio)) if (BIO_write_blocked(bio))
{ {
const long status = BIO_wait_write(bio, 100); const long rc = BIO_wait_write(bio, 100);
if (status < 0) if (rc < 0)
return -1; return -1;
} }
else if (BIO_read_blocked(bio)) else if (BIO_read_blocked(bio))
@ -1270,7 +1270,7 @@ int freerdp_tls_write_all(rdpTls* tls, const BYTE* data, int length)
} }
} }
return length; return (int)length;
} }
int freerdp_tls_set_alert_code(rdpTls* tls, int level, int description) int freerdp_tls_set_alert_code(rdpTls* tls, int level, int description)

View File

@ -115,7 +115,7 @@ extern "C"
FREERDP_LOCAL BOOL freerdp_tls_send_alert(rdpTls* tls); FREERDP_LOCAL BOOL freerdp_tls_send_alert(rdpTls* tls);
FREERDP_LOCAL int freerdp_tls_write_all(rdpTls* tls, const BYTE* data, int length); FREERDP_LOCAL int freerdp_tls_write_all(rdpTls* tls, const BYTE* data, size_t length);
FREERDP_LOCAL int freerdp_tls_set_alert_code(rdpTls* tls, int level, int description); FREERDP_LOCAL int freerdp_tls_set_alert_code(rdpTls* tls, int level, int description);