Skip to content

Commit

Permalink
#69 - Missed some pointer fixes;
Browse files Browse the repository at this point in the history
  • Loading branch information
jlucas9 committed Feb 3, 2022
1 parent dcd1132 commit 1e2d42f
Show file tree
Hide file tree
Showing 18 changed files with 302 additions and 302 deletions.
18 changes: 9 additions & 9 deletions include/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@
extern int32_t Crypto_Config_CryptoLib(uint8_t sadb_type, uint8_t cryptography_type, uint8_t crypto_create_fecf, uint8_t process_sdls_pdus,
uint8_t has_pus_hdr, uint8_t ignore_sa_state, uint8_t ignore_anti_replay,
uint8_t unique_sa_per_mapid, uint8_t crypto_check_fecf, uint8_t vcid_bitmask);
extern int32_t Crypto_Config_MariaDB(char *mysql_hostname, char *mysql_database, uint16_t mysql_port,
extern int32_t Crypto_Config_MariaDB(char* mysql_hostname, char* mysql_database, uint16_t mysql_port,
uint8_t mysql_require_secure_transport, uint8_t mysql_tls_verify_server,
char *mysql_tls_ca, char *mysql_tls_capath, char *mysql_mtls_cert,
char *mysql_mtls_key,
char *mysql_mtls_client_key_password, char *mysql_username, char *mysql_password);
extern int32_t Crypto_Config_Kmc_Crypto_Service(char *protocol, char *kmc_crypto_hostname, uint16_t kmc_crypto_port,
char *kmc_crypto_app, char *kmc_tls_ca_bundle, char *kmc_tls_ca_path,
uint8_t kmc_ignore_ssl_hostname_validation, char *mtls_client_cert_path,
char *mtls_client_cert_type, char *mtls_client_key_path,
char *mtls_client_key_pass, char *mtls_issuer_cert);
char* mysql_tls_ca, char* mysql_tls_capath, char* mysql_mtls_cert,
char* mysql_mtls_key,
char* mysql_mtls_client_key_password, char* mysql_username, char* mysql_password);
extern int32_t Crypto_Config_Kmc_Crypto_Service(char* protocol, char* kmc_crypto_hostname, uint16_t kmc_crypto_port,
char* kmc_crypto_app, char* kmc_tls_ca_bundle, char* kmc_tls_ca_path,
uint8_t kmc_ignore_ssl_hostname_validation, char* mtls_client_cert_path,
char* mtls_client_cert_type, char* mtls_client_key_path,
char* mtls_client_key_pass, char* mtls_issuer_cert);
extern int32_t Crypto_Config_Add_Gvcid_Managed_Parameter(uint8_t tfvn, uint16_t scid, uint8_t vcid, uint8_t has_fecf,
uint8_t has_segmentation_hdr);

Expand Down
8 changes: 4 additions & 4 deletions include/crypto_config_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ struct _GvcidManagedParameters_t
*/
typedef struct
{
char *mysql_username;
char *mysql_password;
char *mysql_hostname;
char *mysql_database;
char* mysql_username;
char* mysql_password;
char* mysql_hostname;
char* mysql_database;
uint16_t mysql_port;
char* mysql_mtls_cert;
char* mysql_mtls_key;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ static int32_t cryptography_aead_decrypt(uint8_t* data_out, size_t len_data_out,
// libcurl call back and support function declarations
static void configure_curl_connect_opts(CURL* curl);
static size_t write_callback(void* data, size_t size, size_t nmemb, void* userp);
static size_t read_callback(char *dest, size_t size, size_t nmemb, void* userp);
static size_t read_callback(char* dest, size_t size, size_t nmemb, void* userp);
static char* int_to_str(uint32_t int_src, uint32_t* converted_str_length);
static int jsoneq(const char *json, jsmntok_t* tok, const char *s);
static int jsoneq(const char* json, jsmntok_t* tok, const char* s);


/*
Expand Down Expand Up @@ -106,12 +106,12 @@ static const char* AES_CMAC_TRANSFORMATION="AESCMAC";

// libcurl call-back response handling Structures
typedef struct {
char *response;
char* response;
size_t size;
} memory_write;
#define MEMORY_WRITE_SIZE (sizeof(memory_write))
typedef struct {
char *response;
char* response;
size_t size;
} memory_read;
#define MEMORY_READ_SIZE (sizeof(memory_read))
Expand Down Expand Up @@ -1088,7 +1088,7 @@ static size_t write_callback(void* data, size_t size, size_t nmemb, void* userp)
size_t realsize = size * nmemb;
memory_write *mem = (memory_write *)userp;

char *ptr;
char* ptr;
if(mem->response != NULL)
{
ptr = realloc(mem->response, mem->size + realsize + 1);
Expand All @@ -1109,7 +1109,7 @@ static size_t write_callback(void* data, size_t size, size_t nmemb, void* userp)
return realsize;
}

static size_t read_callback(char *dest, size_t size, size_t nmemb, void* userp)
static size_t read_callback(char* dest, size_t size, size_t nmemb, void* userp)
{
memory_read *wt = (memory_read *)userp;
size_t buffer_size = size*nmemb;
Expand Down Expand Up @@ -1183,7 +1183,7 @@ static char* int_to_str(uint32_t int_src, uint32_t* converted_str_length)

// JSON local functions

static int jsoneq(const char *json, jsmntok_t* tok, const char *s)
static int jsoneq(const char* json, jsmntok_t* tok, const char* s)
{
if (tok->type == JSMN_STRING && (int)strlen(s) == tok->end - tok->start &&
strncmp(json + tok->start, s, tok->end - tok->start) == 0) {
Expand Down
8 changes: 4 additions & 4 deletions src/src_cryptography/src_kmc_crypto_service/jsmn.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ JSMN_API void jsmn_init(jsmn_parser *parser);
* describing
* a single JSON object.
*/
JSMN_API int jsmn_parse(jsmn_parser *parser, const char *js, const size_t len,
JSMN_API int jsmn_parse(jsmn_parser *parser, const char* js, const size_t len,
jsmntok_t* tokens, const unsigned int num_tokens);

#ifndef JSMN_HEADER
Expand Down Expand Up @@ -132,7 +132,7 @@ static void jsmn_fill_token(jsmntok_t* token, const jsmntype_t type,
/**
* Fills next available token with JSON primitive.
*/
static int jsmn_parse_primitive(jsmn_parser *parser, const char *js,
static int jsmn_parse_primitive(jsmn_parser *parser, const char* js,
const size_t len, jsmntok_t* tokens,
const size_t num_tokens) {
jsmntok_t* token;
Expand Down Expand Up @@ -190,7 +190,7 @@ static int jsmn_parse_primitive(jsmn_parser *parser, const char *js,
/**
* Fills next token with JSON string.
*/
static int jsmn_parse_string(jsmn_parser *parser, const char *js,
static int jsmn_parse_string(jsmn_parser *parser, const char* js,
const size_t len, jsmntok_t* tokens,
const size_t num_tokens) {
jsmntok_t* token;
Expand Down Expand Up @@ -265,7 +265,7 @@ static int jsmn_parse_string(jsmn_parser *parser, const char *js,
/**
* Parse JSON string and fill tokens.
*/
JSMN_API int jsmn_parse(jsmn_parser *parser, const char *js, const size_t len,
JSMN_API int jsmn_parse(jsmn_parser *parser, const char* js, const size_t len,
jsmntok_t* tokens, const unsigned int num_tokens) {
int r;
int i;
Expand Down
16 changes: 8 additions & 8 deletions src/src_main/crypto_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,10 @@ int32_t Crypto_Config_CryptoLib(uint8_t sadb_type, uint8_t cryptography_type, ui
* @return int32: Success/Failure
**/
/*set parameters for an encrypted TLS connection*/
int32_t Crypto_Config_MariaDB(char *mysql_hostname, char *mysql_database, uint16_t mysql_port,
int32_t Crypto_Config_MariaDB(char* mysql_hostname, char* mysql_database, uint16_t mysql_port,
uint8_t mysql_require_secure_transport, uint8_t mysql_tls_verify_server,
char *mysql_tls_ca, char *mysql_tls_capath, char *mysql_mtls_cert, char *mysql_mtls_key,
char *mysql_mtls_client_key_password, char *mysql_username, char *mysql_password)
char* mysql_tls_ca, char* mysql_tls_capath, char* mysql_mtls_cert, char* mysql_mtls_key,
char* mysql_mtls_client_key_password, char* mysql_username, char* mysql_password)
{
int32_t status = CRYPTO_LIB_ERROR;
sadb_mariadb_config = (SadbMariaDBConfig_t*)calloc(1, SADB_MARIADB_CONFIG_SIZE);
Expand All @@ -293,11 +293,11 @@ int32_t Crypto_Config_MariaDB(char *mysql_hostname, char *mysql_database, uint16
return status;
}

extern int32_t Crypto_Config_Kmc_Crypto_Service(char *protocol, char *kmc_crypto_hostname, uint16_t kmc_crypto_port,
char *kmc_crypto_app, char *kmc_tls_ca_bundle, char *kmc_tls_ca_path,
uint8_t kmc_ignore_ssl_hostname_validation, char *mtls_client_cert_path,
char *mtls_client_cert_type, char *mtls_client_key_path,
char *mtls_client_key_pass, char *mtls_issuer_cert)
extern int32_t Crypto_Config_Kmc_Crypto_Service(char* protocol, char* kmc_crypto_hostname, uint16_t kmc_crypto_port,
char* kmc_crypto_app, char* kmc_tls_ca_bundle, char* kmc_tls_ca_path,
uint8_t kmc_ignore_ssl_hostname_validation, char* mtls_client_cert_path,
char* mtls_client_cert_type, char* mtls_client_key_path,
char* mtls_client_key_pass, char* mtls_issuer_cert)
{
int32_t status = CRYPTO_LIB_SUCCESS;
cryptography_kmc_crypto_config = (CryptographyKmcCryptoServiceConfig_t* )calloc(1, CRYPTOGRAPHY_KMC_CRYPTO_SERVICE_CONFIG_SIZE);
Expand Down
36 changes: 18 additions & 18 deletions src/src_mysql/sadb_routine_mariadb.template.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,25 @@ static int32_t sadb_sa_delete(void);
// MySQL local functions
static int32_t finish_with_error(MYSQL *con, int err);
// MySQL Queries
static const char *SQL_SADB_GET_SA_BY_SPI =
static const char* SQL_SADB_GET_SA_BY_SPI =
"SELECT "
"spi,ekid,akid,sa_state,tfvn,scid,vcid,mapid,lpid,est,ast,shivf_len,shsnf_len,shplf_len,stmacf_len,ecs_len,HEX(ecs)"
",HEX(iv),acs_len,acs,abm_len,HEX(abm),arc_len,HEX(arc),arcw_len,HEX(arcw)"
" FROM security_associations WHERE spi='%d'";
static const char *SQL_SADB_GET_SA_BY_GVCID =
static const char* SQL_SADB_GET_SA_BY_GVCID =
"SELECT "
"spi,ekid,akid,sa_state,tfvn,scid,vcid,mapid,lpid,est,ast,shivf_len,shsnf_len,shplf_len,stmacf_len,ecs_len,HEX(ecs)"
",HEX(iv),acs_len,acs,abm_len,HEX(abm),arc_len,HEX(arc),arcw_len,HEX(arcw)"
" FROM security_associations WHERE tfvn='%d' AND scid='%d' AND vcid='%d' AND mapid='%d' AND sa_state='%d'";
static const char *SQL_SADB_UPDATE_IV_ARC_BY_SPI =
static const char* SQL_SADB_UPDATE_IV_ARC_BY_SPI =
"UPDATE security_associations"
" SET iv=X'%s', arc=X'%s'"
" WHERE spi='%d' AND tfvn='%d' AND scid='%d' AND vcid='%d' AND mapid='%d'";

// sadb_routine mariaDB private helper functions
static int32_t parse_sa_from_mysql_query(char *query, SecurityAssociation_t* *security_association);
static int32_t convert_hexstring_to_byte_array(char *hexstr, uint8_t* byte_array);
static char *convert_byte_array_to_hexstring(void* src_buffer, size_t buffer_length);
static int32_t parse_sa_from_mysql_query(char* query, SecurityAssociation_t* *security_association);
static int32_t convert_hexstring_to_byte_array(char* hexstr, uint8_t* byte_array);
static char* convert_byte_array_to_hexstring(void* src_buffer, size_t buffer_length);

/*
** Global Variables
Expand Down Expand Up @@ -272,7 +272,7 @@ static int32_t sadb_sa_delete(void)
}

// sadb_routine private helper functions
static int32_t parse_sa_from_mysql_query(char *query, SecurityAssociation_t* *security_association)
static int32_t parse_sa_from_mysql_query(char* query, SecurityAssociation_t* *security_association)
{
int32_t status = CRYPTO_LIB_SUCCESS;
SecurityAssociation_t* sa = malloc(sizeof(SecurityAssociation_t));
Expand Down Expand Up @@ -307,14 +307,14 @@ static int32_t parse_sa_from_mysql_query(char *query, SecurityAssociation_t* *se
MYSQL_ROW row;
MYSQL_FIELD *field;

char *field_names[num_fields]; //[64]; 64 == max length of column name in MySQL
char* field_names[num_fields]; //[64]; 64 == max length of column name in MySQL

// TODO -- Need to store mysql query hex string and then malloc sa->iv according to size.
// TODO -- IV && arc && abm as uint8_t* instead of uint8[]!!!
char *iv_byte_str;
char *arc_byte_str;
char *abm_byte_str;
char *ecs_byte_str;
char* iv_byte_str;
char* arc_byte_str;
char* abm_byte_str;
char* ecs_byte_str;
while ((row = mysql_fetch_row(result)))
{
for (int i = 0; i < num_fields; i++)
Expand Down Expand Up @@ -498,10 +498,10 @@ static int32_t parse_sa_from_mysql_query(char *query, SecurityAssociation_t* *se

return status;
}
static int32_t convert_hexstring_to_byte_array(char *source_str, uint8_t* dest_buffer)
static int32_t convert_hexstring_to_byte_array(char* source_str, uint8_t* dest_buffer)
{ // https://stackoverflow.com/questions/3408706/hexadecimal-string-to-byte-array-in-c/56247335#56247335
char *line = source_str;
char *data = line;
char* line = source_str;
char* data = line;
int offset;
unsigned int read_byte;
uint32_t data_len = 0;
Expand All @@ -514,15 +514,15 @@ static int32_t convert_hexstring_to_byte_array(char *source_str, uint8_t* dest_b
return data_len;
}

static char *convert_byte_array_to_hexstring(void* src_buffer, size_t buffer_length)
static char* convert_byte_array_to_hexstring(void* src_buffer, size_t buffer_length)
{
if (buffer_length == 0)
{ // Return empty string (with null char!) if buffer is empty
return "";
}

unsigned char *bytes = src_buffer;
char *hexstr = malloc(buffer_length * 2 + 1);
unsigned char* bytes = src_buffer;
char* hexstr = malloc(buffer_length * 2 + 1);

if (src_buffer == NULL)
return NULL;
Expand Down
10 changes: 5 additions & 5 deletions util/include/shared_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ extern "C"

#include "crypto_error.h"

char *c_read_file(const char *f_name, long *f_size);
char* c_read_file(const char* f_name, long *f_size);

void debug_printf(const char *format, ...);
void debug_hexprintf(const char *bin_data, int size_bin_data);
void debug_printf(const char* format, ...);
void debug_hexprintf(const char* bin_data, int size_bin_data);

void hex_conversion(char *buffer_h, char **buffer_b, int *buffer_b_length);
int convert_hexstring_to_byte_array(char *source_str, char *dest_buffer);
void hex_conversion(char* buffer_h, char* *buffer_b, int *buffer_b_length);
int convert_hexstring_to_byte_array(char* source_str, char* dest_buffer);

#ifdef __cplusplus
} /* Close scope of 'extern "C"' declaration which encloses file. */
Expand Down
38 changes: 19 additions & 19 deletions util/include/utest.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ typedef void (*utest_testcase_t)(int *, size_t);
struct utest_test_state_s {
utest_testcase_t func;
size_t index;
char *name;
char* name;
};

struct utest_state_s {
Expand Down Expand Up @@ -799,9 +799,9 @@ utest_type_printer(long long unsigned int i) {
} \
UTEST_INITIALIZER(utest_register_##SET##_##NAME) { \
const size_t index = utest_state.tests_length++; \
const char *name_part = #SET "." #NAME; \
const char* name_part = #SET "." #NAME; \
const size_t name_size = strlen(name_part) + 1; \
char *name = UTEST_PTR_CAST(char *, malloc(name_size)); \
char* name = UTEST_PTR_CAST(char* , malloc(name_size)); \
utest_state.tests = UTEST_PTR_CAST( \
struct utest_test_state_s *, \
utest_realloc(UTEST_PTR_CAST(void* , utest_state.tests), \
Expand Down Expand Up @@ -841,9 +841,9 @@ utest_type_printer(long long unsigned int i) {
} \
UTEST_INITIALIZER(utest_register_##FIXTURE##_##NAME) { \
const size_t index = utest_state.tests_length++; \
const char *name_part = #FIXTURE "." #NAME; \
const char* name_part = #FIXTURE "." #NAME; \
const size_t name_size = strlen(name_part) + 1; \
char *name = UTEST_PTR_CAST(char *, malloc(name_size)); \
char* name = UTEST_PTR_CAST(char* , malloc(name_size)); \
utest_state.tests = UTEST_PTR_CAST( \
struct utest_test_state_s *, \
utest_realloc(UTEST_PTR_CAST(void* , utest_state.tests), \
Expand Down Expand Up @@ -883,9 +883,9 @@ utest_type_printer(long long unsigned int i) {
utest_uint64_t iUp; \
for (i = 0; i < (INDEX); i++) { \
const size_t index = utest_state.tests_length++; \
const char *name_part = #FIXTURE "." #NAME; \
const char* name_part = #FIXTURE "." #NAME; \
const size_t name_size = strlen(name_part) + 32; \
char *name = UTEST_PTR_CAST(char *, malloc(name_size)); \
char* name = UTEST_PTR_CAST(char* , malloc(name_size)); \
utest_state.tests = UTEST_PTR_CAST( \
struct utest_test_state_s *, \
utest_realloc(UTEST_PTR_CAST(void* , utest_state.tests), \
Expand All @@ -902,13 +902,13 @@ utest_type_printer(long long unsigned int i) {
struct FIXTURE *utest_fixture)

UTEST_WEAK
int utest_should_filter_test(const char *filter, const char *testcase);
UTEST_WEAK int utest_should_filter_test(const char *filter,
const char *testcase) {
int utest_should_filter_test(const char* filter, const char* testcase);
UTEST_WEAK int utest_should_filter_test(const char* filter,
const char* testcase) {
if (filter) {
const char *filter_cur = filter;
const char *testcase_cur = testcase;
const char *filter_wildcard = UTEST_NULL;
const char* filter_cur = filter;
const char* testcase_cur = testcase;
const char* filter_wildcard = UTEST_NULL;

while (('\0' != *filter_cur) && ('\0' != *testcase_cur)) {
if ('*' == *filter_cur) {
Expand Down Expand Up @@ -969,7 +969,7 @@ UTEST_WEAK int utest_should_filter_test(const char *filter,
return 0;
}

static UTEST_INLINE FILE *utest_fopen(const char *filename, const char *mode) {
static UTEST_INLINE FILE *utest_fopen(const char* filename, const char* mode) {
#ifdef _MSC_VER
FILE *file;
if (0 == fopen_s(&file, filename, mode)) {
Expand All @@ -982,19 +982,19 @@ static UTEST_INLINE FILE *utest_fopen(const char *filename, const char *mode) {
#endif
}

static UTEST_INLINE int utest_main(int argc, const char *const argv[]);
int utest_main(int argc, const char *const argv[]) {
static UTEST_INLINE int utest_main(int argc, const char* const argv[]);
int utest_main(int argc, const char* const argv[]) {
utest_uint64_t failed = 0;
size_t index = 0;
size_t* failed_testcases = UTEST_NULL;
size_t failed_testcases_length = 0;
const char *filter = UTEST_NULL;
const char* filter = UTEST_NULL;
utest_uint64_t ran_tests = 0;

enum colours { U_RESET, U_GREEN, U_RED };

const int use_colours = UTEST_COLOUR_OUTPUT();
const char *colours[] = {"\033[0m", "\033[32m", "\033[31m"};
const char* colours[] = {"\033[0m", "\033[32m", "\033[31m"};

if (!use_colours) {
for (index = 0; index < sizeof colours / sizeof colours[0]; index++) {
Expand Down Expand Up @@ -1149,7 +1149,7 @@ int utest_main(int argc, const char *const argv[]) {
*/
#define UTEST_MAIN() \
UTEST_STATE(); \
int main(int argc, const char *const argv[]) { \
int main(int argc, const char* const argv[]) { \
return utest_main(argc, argv); \
}

Expand Down
Loading

0 comments on commit 1e2d42f

Please sign in to comment.