diff --git a/gj_common/common.c b/gj_common/common.c index dede87bb..1574652a 100644 --- a/gj_common/common.c +++ b/gj_common/common.c @@ -24,6 +24,11 @@ gj_error *gj_error_info(int err) return NULL; gj_error *error = (gj_error *)malloc(sizeof(gj_error)); + if (error == NULL) + { + gj_log_internal("Failed to allocate gj_error"); + return NULL; + } error->message_allocated = false; if (err <= GJ_ERR_FIRST && err >= GJ_ERR_LAST) { @@ -59,8 +64,15 @@ gj_error *gj_error_info(int err) { error->code = e->klass; error->message = (char *)malloc(strlen(e->message)); - strcpy(error->message, e->message); - error->message_allocated = true; + if (error->message != NULL) + { + strcpy(error->message, e->message); + error->message_allocated = true; + } + else + { + error->message = "Unknown Error - Malloc Failed"; + } } else { diff --git a/gj_common/gitjournal.c b/gj_common/gitjournal.c index 9d99352e..aa394a4b 100644 --- a/gj_common/gitjournal.c +++ b/gj_common/gitjournal.c @@ -65,6 +65,11 @@ int rm_match_cb(const char *path, const char *spec, void *payload) int full_path_length = strlen(git_base_path) + 1 + strlen(path); char *full_path = (char *)malloc(full_path_length); + if (full_path == NULL) + { + gj_log_internal("rm_match_cb: Malloc Failed"); + return 1; + } strcpy(full_path, git_base_path); strcat(full_path, "/"); // FIXME: Will not work on windows! strcat(full_path, path); @@ -395,6 +400,12 @@ int gj_git_push(const char *git_base_path) int name_length = strlen(base_name) + strlen(branch_name); name = (char *)malloc(name_length); + if (name == NULL) + { + gj_log_internal("gj_git_push: malloc string failed. Length: %d", name_length); + err = 5000; + goto cleanup; + } strcpy(name, base_name); strcat(name, branch_name); @@ -503,6 +514,12 @@ int gj_git_pull(const char *git_base_path, const char *author_name, const char * int name_length = strlen(base_name) + strlen(branch_name); name = (char *)malloc(name_length); + if (name == NULL) + { + gj_log_internal("gj_git_pull: malloc string failed. Length: %d", name_length); + err = 5000; + goto cleanup; + } strcpy(name, base_name); strcat(name, branch_name); diff --git a/gj_common/keygen.c b/gj_common/keygen.c index 09fc4aeb..c4733824 100644 --- a/gj_common/keygen.c +++ b/gj_common/keygen.c @@ -63,6 +63,12 @@ int write_rsa_public_key(RSA *pRsa, const char *file_path, const char *comment) // reading the public exponent int eLen = BN_num_bytes(pRsa_exp); eBytes = (unsigned char *)malloc(eLen); + if (eBytes == NULL) + { + gj_log_internal("write_rsa_public_key malloc failed. Length: %d", eLen); + ret = -1; + goto cleanup; + } ret = BN_bn2bin(pRsa_exp, eBytes); if (ret <= 0) goto cleanup;