diff --git a/src/src_main/crypto_config.c b/src/src_main/crypto_config.c index 28a1f219..712cd0e4 100644 --- a/src/src_main/crypto_config.c +++ b/src/src_main/crypto_config.c @@ -211,11 +211,20 @@ int32_t Crypto_Config_MariaDB(char *mysql_username, char *mysql_password, char * { int32_t status = CRYPTO_LIB_SUCCESS; sadb_mariadb_config = (SadbMariaDBConfig_t *)calloc(1, SADB_MARIADB_CONFIG_SIZE); - sadb_mariadb_config->mysql_username = mysql_username; - sadb_mariadb_config->mysql_password = mysql_password; - sadb_mariadb_config->mysql_hostname = mysql_hostname; - sadb_mariadb_config->mysql_database = mysql_database; - sadb_mariadb_config->mysql_port = mysql_port; + if(sadb_mariadb_config != NULL) + { + sadb_mariadb_config->mysql_username = mysql_username; + sadb_mariadb_config->mysql_password = mysql_password; + sadb_mariadb_config->mysql_hostname = mysql_hostname; + sadb_mariadb_config->mysql_database = mysql_database; + sadb_mariadb_config->mysql_port = mysql_port; + } + else + { + // null returned, throw error and return + status = CRYPTO_LIB_ERR_NULL_BUFFER; + } + return status; } @@ -236,13 +245,22 @@ int32_t Crypto_Config_Add_Gvcid_Managed_Parameter(uint8_t tfvn, uint16_t scid, u if (gvcid_managed_parameters == NULL) { // case: Global Root Node not Set gvcid_managed_parameters = (GvcidManagedParameters_t *)calloc(1, GVCID_MANAGED_PARAMETERS_SIZE); - gvcid_managed_parameters->tfvn = tfvn; - gvcid_managed_parameters->scid = scid; - gvcid_managed_parameters->vcid = vcid; - gvcid_managed_parameters->has_fecf = has_fecf; - gvcid_managed_parameters->has_segmentation_hdr = has_segmentation_hdr; - gvcid_managed_parameters->next = NULL; - return status; + if(gvcid_managed_parameters != NULL) + { + gvcid_managed_parameters->tfvn = tfvn; + gvcid_managed_parameters->scid = scid; + gvcid_managed_parameters->vcid = vcid; + gvcid_managed_parameters->has_fecf = has_fecf; + gvcid_managed_parameters->has_segmentation_hdr = has_segmentation_hdr; + gvcid_managed_parameters->next = NULL; + return status; + } + else + { + // calloc failed - return error + status = CRYPTO_LIB_ERR_NULL_BUFFER; + return status; + } } else { // Recurse through nodes and add at end diff --git a/src/src_main/crypto_tc.c b/src/src_main/crypto_tc.c index 60496cc8..9cae55c7 100644 --- a/src/src_main/crypto_tc.c +++ b/src/src_main/crypto_tc.c @@ -78,6 +78,7 @@ int32_t Crypto_TC_ApplySecurity(const uint8_t *p_in_frame, const uint16_t in_fra { printf(KRED "ERROR: CryptoLib Configuration Not Set! -- CRYPTO_LIB_ERR_NO_CONFIG, Will Exit\n" RESET); status = CRYPTO_LIB_ERR_NO_CONFIG; + return status; // return immediately so a NULL crypto_config is not dereferenced later } // Primary Header diff --git a/support/ansible/cryptolib-centos.yml b/support/ansible/cryptolib-centos.yml index 57f4d8eb..0a5b53fc 100644 --- a/support/ansible/cryptolib-centos.yml +++ b/support/ansible/cryptolib-centos.yml @@ -42,6 +42,7 @@ - python3-devel - python3-pip - kernel-devel + - mysql-devel # add additional packages here - name: Install pycryptodome diff --git a/util/src_util/apply_security.c b/util/src_util/apply_security.c index 4ff2ec1c..ba082aee 100644 --- a/util/src_util/apply_security.c +++ b/util/src_util/apply_security.c @@ -25,7 +25,7 @@ int main(int argc, char *argv[]) { - char *buffer; + char *buffer = NULL; const char *filename; long buffer_size; char st[64]; @@ -48,6 +48,9 @@ int main(int argc, char *argv[]) return CRYPTO_LIB_ERROR; } buffer = c_read_file(filename, &buffer_size); + if(buffer == NULL) + return -1; + debug_printf("File buffer size:%lu\n", buffer_size); uint32_t buffer_size_i = (uint32_t)buffer_size; debug_printf("File buffer size int:%d\n", buffer_size_i); @@ -58,7 +61,7 @@ int main(int argc, char *argv[]) Crypto_Init(); uint8_t *ptr_enc_frame = NULL; - uint16_t enc_frame_len; + uint16_t enc_frame_len = 0; // Call ApplySecurity on buffer contents depending on type. if (strcmp(security_type, "tc") == 0)