From 31708cd215bf4b7db200e75101a8626d0529ab8d Mon Sep 17 00:00:00 2001 From: ideal Date: Tue, 27 Oct 2015 09:25:17 +0800 Subject: [PATCH 1/4] fix error when check redis reply in redis backend --- redis/hiredis.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/redis/hiredis.c b/redis/hiredis.c index 28f83c9..7d4b584 100644 --- a/redis/hiredis.c +++ b/redis/hiredis.c @@ -78,7 +78,7 @@ int hiredis_odb_backend__read_header(size_t *len_p, git_otype *type_p, git_odb_b if (reply && reply->type == REDIS_REPLY_ARRAY) { if (reply->element[0]->type != REDIS_REPLY_NIL && - reply->element[0]->type != REDIS_REPLY_NIL) { + reply->element[1]->type != REDIS_REPLY_NIL) { *type_p = (git_otype) atoi(reply->element[0]->str); *len_p = (size_t) atoi(reply->element[1]->str); error = GIT_OK; From 4aea012913b8d5207028a6c921becf3f120d464a Mon Sep 17 00:00:00 2001 From: ideal Date: Tue, 27 Oct 2015 11:11:11 +0800 Subject: [PATCH 2/4] should return GIT_EINVALID instead of GITERR_INVALID if error occured --- redis/hiredis.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/redis/hiredis.c b/redis/hiredis.c index 7d4b584..209d8d1 100644 --- a/redis/hiredis.c +++ b/redis/hiredis.c @@ -155,7 +155,7 @@ int hiredis_odb_backend__read_prefix(git_oid *out_oid, /* TODO prefix */ giterr_set_str(GITERR_ODB, "Redis odb doesn't not implement oid prefix lookup"); - return GITERR_INVALID; + return GIT_EINVALID; } int hiredis_odb_backend__exists(git_odb_backend *_backend, const git_oid *oid) From 5685952b08710e9b11d6a11e2bd69df094baada3 Mon Sep 17 00:00:00 2001 From: ideal Date: Tue, 27 Oct 2015 18:16:30 +0800 Subject: [PATCH 3/4] remove duplicate call of git_reference_symbolic_target() --- redis/hiredis.c | 1 - 1 file changed, 1 deletion(-) diff --git a/redis/hiredis.c b/redis/hiredis.c index 209d8d1..d757be2 100644 --- a/redis/hiredis.c +++ b/redis/hiredis.c @@ -380,7 +380,6 @@ int hiredis_refdb_backend__write(git_refdb_backend *_backend, const git_referenc backend = (hiredis_refdb_backend *) _backend; target = git_reference_target(ref); - symbolic_target = git_reference_symbolic_target(ref); /* FIXME handle force correctly */ From 06a45b78234a03c5449601115f0e1bf50be4534f Mon Sep 17 00:00:00 2001 From: ideal Date: Tue, 27 Oct 2015 19:58:44 +0800 Subject: [PATCH 4/4] clean up resources if redis auth failed --- redis/hiredis.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/redis/hiredis.c b/redis/hiredis.c index d757be2..99e13c8 100644 --- a/redis/hiredis.c +++ b/redis/hiredis.c @@ -510,9 +510,12 @@ int git_odb_backend_hiredis(git_odb_backend **backend_out, const char* prefix, c return GIT_ERROR; } - if(password != NULL) { + if (password != NULL) { reply = redisCommand(sharedConnection, "AUTH %s", password); - if (reply->type == REDIS_REPLY_ERROR) { + if (reply == NULL || reply->type == REDIS_REPLY_ERROR) { + freeReplyObject(reply); + redisFree(sharedConnection); + free(backend); giterr_set_str(GITERR_REFERENCE, "Redis odb storage authentication with redis server failed"); return GIT_ERROR; } @@ -559,9 +562,12 @@ int git_refdb_backend_hiredis(git_refdb_backend **backend_out, const char* prefi return GIT_ERROR; } - if(password != NULL) { + if (password != NULL) { reply = redisCommand(sharedConnection, "AUTH %s", password); if (reply->type == REDIS_REPLY_ERROR) { + freeReplyObject(reply); + redisFree(sharedConnection); + free(backend); giterr_set_str(GITERR_REFERENCE, "Redis refdb storage authentication with redis server failed"); return GIT_ERROR; }