diff --git a/include/freerdp/crypto/crypto.h b/include/freerdp/crypto/crypto.h index 6a82556d3..a022dde85 100644 --- a/include/freerdp/crypto/crypto.h +++ b/include/freerdp/crypto/crypto.h @@ -143,7 +143,7 @@ FREERDP_API int crypto_rsa_private_decrypt(const BYTE* input, int length, UINT32 FREERDP_API void crypto_reverse(BYTE* data, int length); FREERDP_API void crypto_nonce(BYTE* nonce, int size); -FREERDP_API char* crypto_base64_encode(BYTE* data, int length); -FREERDP_API void crypto_base64_decode(BYTE* enc_data, int length, BYTE** dec_data, int* res_length); +FREERDP_API char* crypto_base64_encode(const BYTE* data, int length); +FREERDP_API void crypto_base64_decode(const BYTE* enc_data, int length, BYTE** dec_data, int* res_length); #endif /* FREERDP_CRYPTO_H */ diff --git a/libfreerdp/core/certificate.c b/libfreerdp/core/certificate.c index 233ca8ff4..fcc3f01bf 100644 --- a/libfreerdp/core/certificate.c +++ b/libfreerdp/core/certificate.c @@ -717,13 +717,7 @@ void key_free(rdpRsaKey* key) rdpCertificate* certificate_new() { - rdpCertificate* certificate; - - certificate = (rdpCertificate*) calloc(1, sizeof(rdpCertificate)); - if (!certificate) - return NULL; - - return certificate; + return (rdpCertificate*) calloc(1, sizeof(rdpCertificate)); } /** diff --git a/libfreerdp/core/gcc.c b/libfreerdp/core/gcc.c index 9d8932aef..d9c6fe67a 100644 --- a/libfreerdp/core/gcc.c +++ b/libfreerdp/core/gcc.c @@ -982,37 +982,31 @@ BOOL gcc_read_server_security_data(wStream* s, rdpMcs* mcs) if (Stream_GetRemainingLength(s) < settings->ServerRandomLength + settings->ServerCertificateLength) return FALSE; - if (settings->ServerRandomLength > 0) - { - /* serverRandom */ - settings->ServerRandom = (BYTE*) malloc(settings->ServerRandomLength); - Stream_Read(s, settings->ServerRandom, settings->ServerRandomLength); - } - else - { + if ((settings->ServerRandomLength <= 0) || (settings->ServerCertificateLength <= 0)) return FALSE; - } - if (settings->ServerCertificateLength > 0) - { - /* serverCertificate */ - settings->ServerCertificate = (BYTE*) malloc(settings->ServerCertificateLength); - Stream_Read(s, settings->ServerCertificate, settings->ServerCertificateLength); - - certificate_free(settings->RdpServerCertificate); - settings->RdpServerCertificate = certificate_new(); - data = settings->ServerCertificate; - length = settings->ServerCertificateLength; - - if (certificate_read_server_certificate(settings->RdpServerCertificate, data, length) < 1) - return FALSE; - } - else - { + /* serverRandom */ + settings->ServerRandom = (BYTE*) malloc(settings->ServerRandomLength); + if (!settings->ServerRandom) return FALSE; - } + Stream_Read(s, settings->ServerRandom, settings->ServerRandomLength); - return TRUE; + + /* serverCertificate */ + settings->ServerCertificate = (BYTE*) malloc(settings->ServerCertificateLength); + if (!settings->ServerCertificate) + return FALSE; + Stream_Read(s, settings->ServerCertificate, settings->ServerCertificateLength); + + certificate_free(settings->RdpServerCertificate); + settings->RdpServerCertificate = certificate_new(); + if (!settings->RdpServerCertificate) + return FALSE; + + data = settings->ServerCertificate; + length = settings->ServerCertificateLength; + + return certificate_read_server_certificate(settings->RdpServerCertificate, data, length); } static const BYTE initial_signature[] = diff --git a/libfreerdp/crypto/base64.c b/libfreerdp/crypto/base64.c index be1285079..3f2b6170f 100644 --- a/libfreerdp/crypto/base64.c +++ b/libfreerdp/crypto/base64.c @@ -27,16 +27,18 @@ static const char base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; -char* crypto_base64_encode(BYTE* data, int length) +char* crypto_base64_encode(const BYTE* data, int length) { int c; - BYTE* q; + const BYTE* q; char* p; - char* str; + char* ret; int i = 0; q = data; - p = str = (char*) malloc((length + 3) * 4 / 3 + 1); + p = ret = (char*) malloc((length + 3) * 4 / 3 + 1); + if (!p) + return NULL; while (i < length) { @@ -68,7 +70,7 @@ char* crypto_base64_encode(BYTE* data, int length) *p = 0; - return str; + return ret; } static int base64_decode_char(char c) @@ -94,7 +96,7 @@ static int base64_decode_char(char c) return -1; } -static void* base64_decode(BYTE* s, int length, int* data_len) +static void* base64_decode(const BYTE* s, int length, int* data_len) { char* p; int n[4]; @@ -142,7 +144,7 @@ static void* base64_decode(BYTE* s, int length, int* data_len) return data; } -void crypto_base64_decode(BYTE* enc_data, int length, BYTE** dec_data, int* res_length) +void crypto_base64_decode(const BYTE* enc_data, int length, BYTE** dec_data, int* res_length) { *dec_data = base64_decode(enc_data, length, res_length); } diff --git a/winpr/include/winpr/print.h b/winpr/include/winpr/print.h index 96328e60f..c7ffecd5c 100644 --- a/winpr/include/winpr/print.h +++ b/winpr/include/winpr/print.h @@ -33,10 +33,10 @@ extern "C" { #endif -WINPR_API void winpr_HexDump(BYTE* data, int length); -WINPR_API void winpr_CArrayDump(BYTE* data, int length, int width); +WINPR_API void winpr_HexDump(const BYTE* data, int length); +WINPR_API void winpr_CArrayDump(const BYTE* data, int length, int width); -WINPR_API char* winpr_BinToHexString(BYTE* data, int length, BOOL space); +WINPR_API char* winpr_BinToHexString(const BYTE* data, int length, BOOL space); WINPR_API int wprintfx(const char *fmt, ...); WINPR_API int wvprintfx(const char *fmt, va_list args); diff --git a/winpr/libwinpr/utils/print.c b/winpr/libwinpr/utils/print.c index 450f13a79..9b0d6942b 100644 --- a/winpr/libwinpr/utils/print.c +++ b/winpr/libwinpr/utils/print.c @@ -30,9 +30,9 @@ #include "trio.h" -void winpr_HexDump(BYTE* data, int length) +void winpr_HexDump(const BYTE* data, int length) { - BYTE* p = data; + const BYTE* p = data; int i, line, offset = 0; while (offset < length) @@ -60,9 +60,9 @@ void winpr_HexDump(BYTE* data, int length) } } -void winpr_CArrayDump(BYTE* data, int length, int width) +void winpr_CArrayDump(const BYTE* data, int length, int width) { - BYTE* p = data; + const BYTE* p = data; int i, line, offset = 0; while (offset < length) @@ -86,7 +86,7 @@ void winpr_CArrayDump(BYTE* data, int length, int width) printf("\n"); } -char* winpr_BinToHexString(BYTE* data, int length, BOOL space) +char* winpr_BinToHexString(const BYTE* data, int length, BOOL space) { int i; int n;