cLib: Forward openssl errors properly

This commit is contained in:
Vishesh Handa
2019-05-29 14:27:33 +02:00
parent c3d9d653f7
commit 6afb5fbaac
3 changed files with 16 additions and 4 deletions

View File

@ -2,10 +2,12 @@
#include <stdarg.h>
#include <errno.h>
#include <git2.h>
#include <stdio.h>
#include <string.h>
#include <git2.h>
#include <openssl/err.h>
void gj_log_internal(const char *format, ...)
{
char buffer[1024];
@ -23,7 +25,7 @@ gj_error *gj_error_info(int err)
gj_error *error = (gj_error *)malloc(sizeof(gj_error));
error->message_allocated = false;
if (err >= GJ_ERR_FIRST && err <= GJ_ERR_LAST)
if (err <= GJ_ERR_FIRST && err >= GJ_ERR_LAST)
{
switch (err)
{
@ -36,6 +38,13 @@ gj_error *gj_error_info(int err)
error->code = err;
error->message = "GitPull Invalid State";
break;
case GJ_ERR_OPENSSL:
error->code = ERR_peek_last_error();
error->message_allocated = true;
error->message = (char *)malloc(256);
ERR_error_string(error->code, error->message);
break;
}
return error;
}

View File

@ -41,6 +41,7 @@ int gj_generate_ssh_keys(const char *private_key_path,
#define GJ_ERR_FIRST -954
#define GJ_ERR_EMPTY_COMMIT -954
#define GJ_ERR_PULL_INVALID_STATE -955
#define GJ_ERR_LAST -955
#define GJ_ERR_OPENSSL -956
#define GJ_ERR_LAST -956
#endif

View File

@ -148,5 +148,7 @@ cleanup:
RSA_free(rsa);
BN_free(bne);
return (ret == 1);
if (ret != 1)
return GJ_ERR_OPENSSL;
return 0;
}