mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-30 02:59:02 +08:00
gj_common: Fix Infer possible NULL_DEREFERENCE errors
These are quite unlikely, but we may as well check agains't them.
This commit is contained in:
@ -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,10 +64,17 @@ gj_error *gj_error_info(int err)
|
||||
{
|
||||
error->code = e->klass;
|
||||
error->message = (char *)malloc(strlen(e->message));
|
||||
if (error->message != NULL)
|
||||
{
|
||||
strcpy(error->message, e->message);
|
||||
error->message_allocated = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
error->message = "Unknown Error - Malloc Failed";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
error->code = 1000;
|
||||
error->message = "Unknown Message";
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user