@@ -479,9 +479,15 @@ static int32_t cryptography_encrypt(uint8_t *data_out, size_t len_data_out, uint
479479
480480 /* JSON Response Handling End */
481481
482- uint8_t * ciphertext_decoded = malloc ((len_data_out )* 2 + 1 );
482+ uint16_t decoded_buffer_size = (len_data_out )* 2 + 1 ;
483+ uint8_t * ciphertext_decoded = malloc (decoded_buffer_size );
483484 size_t ciphertext_decoded_len = 0 ;
484- base64Decode (ciphertext_base64 , strlen (ciphertext_base64 ), ciphertext_decoded , & ciphertext_decoded_len );
485+ if (base64Decode (ciphertext_base64 , strlen (ciphertext_base64 ), ciphertext_decoded , decoded_buffer_size , & ciphertext_decoded_len ) != 0 )
486+ {
487+ free (chunk_write );
488+ free (ciphertext_decoded );
489+ return CRYPTOGRAHPY_KMC_BASE64_DECRYPT_ERROR ;
490+ }
485491#ifdef DEBUG
486492 printf ("Decoded Cipher Text Length: %ld\n" , ciphertext_decoded_len );
487493 printf ("Decoded Cipher Text: \n" );
@@ -685,9 +691,15 @@ static int32_t cryptography_decrypt(uint8_t *data_out, size_t len_data_out, uint
685691
686692 /* JSON Response Handling End */
687693
688- uint8_t * cleartext_decoded = malloc ((len_data_out )* 2 + 1 );
694+ uint16_t decoded_buffer_size = (len_data_out )* 2 + 1 ;
695+ uint8_t * cleartext_decoded = malloc (decoded_buffer_size );
689696 size_t cleartext_decoded_len = 0 ;
690- base64Decode (cleartext_base64 , strlen (cleartext_base64 ), cleartext_decoded , & cleartext_decoded_len );
697+ if (base64Decode (cleartext_base64 , strlen (cleartext_base64 ), cleartext_decoded , decoded_buffer_size , & cleartext_decoded_len ) != 0 )
698+ {
699+ free (chunk_write );
700+ free (cleartext_decoded );
701+ return CRYPTOGRAHPY_KMC_BASE64_DECRYPT_ERROR ;
702+ }
691703#ifdef DEBUG
692704 printf ("Decoded Cipher Text Length: %ld\n" , cleartext_decoded_len );
693705 printf ("Decoded Cipher Text: \n" );
@@ -1528,9 +1540,15 @@ static int32_t cryptography_aead_encrypt(uint8_t *data_out, size_t len_data_out,
15281540
15291541 /* JSON Response Handling End */
15301542
1543+ uint16_t decoded_buffer_size = (len_data_out + mac_size + aad_len ) * 2 + 1 ;
15311544 uint8_t * ciphertext_decoded = malloc ((len_data_out + mac_size + aad_len ) * 2 + 1 );
15321545 size_t ciphertext_decoded_len = 0 ;
1533- base64Decode (ciphertext_base64 , strlen (ciphertext_base64 ), ciphertext_decoded , & ciphertext_decoded_len );
1546+ if (base64Decode (ciphertext_base64 , strlen (ciphertext_base64 ), ciphertext_decoded , decoded_buffer_size , & ciphertext_decoded_len ) != 0 )
1547+ {
1548+ free (chunk_write );
1549+ free (ciphertext_base64 );
1550+ return CRYPTOGRAHPY_KMC_BASE64_DECRYPT_ERROR ;
1551+ }
15341552#ifdef DEBUG
15351553 printf ("Mac size: %d\n" , mac_size );
15361554 printf ("Decoded Cipher Text Length: %ld\n" , ciphertext_decoded_len );
@@ -1836,9 +1854,15 @@ static int32_t cryptography_aead_decrypt(uint8_t *data_out, size_t len_data_out,
18361854
18371855 /* JSON Response Handling End */
18381856
1857+ uint16_t decoded_buffer_size = (len_data_out + mac_size + aad_len ) * 2 + 1 ;
18391858 uint8_t * cleartext_decoded = malloc ((len_data_out + mac_size + aad_len ) * 2 + 1 );
18401859 size_t cleartext_decoded_len = 0 ;
1841- base64Decode (cleartext_base64 , strlen (cleartext_base64 ), cleartext_decoded , & cleartext_decoded_len );
1860+ if (base64Decode (cleartext_base64 , strlen (cleartext_base64 ), cleartext_decoded , decoded_buffer_size , & cleartext_decoded_len ) != 0 )
1861+ {
1862+ free (chunk_write );
1863+ free (cleartext_base64 );
1864+ return CRYPTOGRAHPY_KMC_BASE64_DECRYPT_ERROR ;
1865+ }
18421866#ifdef DEBUG
18431867 printf ("Decoded Cipher Text Length: %ld\n" , cleartext_decoded_len );
18441868 printf ("Decoded Cipher Text: \n" );
0 commit comments