From 2785544fb51ec0ee439510f070f769fe66ccfdc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Sun, 7 Jun 2015 10:45:39 +0200 Subject: [PATCH 1/3] remote: some error-handling issues from Coverity --- src/remote.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/remote.c b/src/remote.c index b7acbb9c1..63f6d3462 100644 --- a/src/remote.c +++ b/src/remote.c @@ -869,7 +869,7 @@ int git_remote_download(git_remote *remote, const git_strarray *refspecs, const { int error = -1; size_t i; - git_vector refs, specs, *to_active; + git_vector *to_active, specs = GIT_VECTOR_INIT, refs = GIT_VECTOR_INIT; const git_remote_callbacks *cbs = NULL; assert(remote); @@ -2451,7 +2451,8 @@ char *apply_insteadof(git_config *config, const char *url, int direction) suffix_length = strlen(SUFFIX_PUSH) + 1; } - git_config_iterator_glob_new(&iter, config, regexp); + if (git_config_iterator_glob_new(&iter, config, regexp) < 0) + return NULL; match_length = 0; while (git_config_next(&entry, iter) == 0) { From 81be2f467ce679e5e1a4b650ebdfc15ce3a9deb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Tue, 9 Jun 2015 16:01:29 +0200 Subject: [PATCH 2/3] ssh: move NULL check to the free function Let `ssh_stream_free()` take a NULL stream, as free functions should, and remove the check from the connection setup. The connection setup would not need the check anyhow, as we always have a stream by the time we reach this code. --- src/transports/ssh.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/transports/ssh.c b/src/transports/ssh.c index 5c8545fe1..83af137f8 100644 --- a/src/transports/ssh.c +++ b/src/transports/ssh.c @@ -177,11 +177,12 @@ static int ssh_stream_write( static void ssh_stream_free(git_smart_subtransport_stream *stream) { ssh_stream *s = (ssh_stream *)stream; - ssh_subtransport *t = OWNING_SUBTRANSPORT(s); - int ret; + ssh_subtransport *t; - GIT_UNUSED(ret); + if (!stream) + return; + t = OWNING_SUBTRANSPORT(s); t->current_stream = NULL; if (s->channel) { @@ -621,8 +622,7 @@ static int _git_ssh_setup_conn( done: if (error < 0) { - if (*stream) - ssh_stream_free(*stream); + ssh_stream_free(*stream); if (session) libssh2_session_free(session); From 02980bdca1c3398396466adff993746cac34fc08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Tue, 9 Jun 2015 16:53:07 +0200 Subject: [PATCH 3/3] Initialize a few variables Coverity complains about the git_rawobj ones because we use a loop in which we keep remembering the old version, and we end up copying our object as the base, so we want to have the data pointer be NULL. --- src/indexer.c | 2 +- src/odb_pack.c | 2 +- src/rebase.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/indexer.c b/src/indexer.c index e39345c71..ef2ac3cba 100644 --- a/src/indexer.c +++ b/src/indexer.c @@ -822,7 +822,7 @@ static int resolve_deltas(git_indexer *idx, git_transfer_progress *stats) progressed = 0; non_null = 0; git_vector_foreach(&idx->deltas, i, delta) { - git_rawobj obj; + git_rawobj obj = {NULL}; if (!delta) continue; diff --git a/src/odb_pack.c b/src/odb_pack.c index 1757cf920..735158d96 100644 --- a/src/odb_pack.c +++ b/src/odb_pack.c @@ -383,7 +383,7 @@ static int pack_backend__read_internal( git_odb_backend *backend, const git_oid *oid) { struct git_pack_entry e; - git_rawobj raw; + git_rawobj raw = {NULL}; int error; if ((error = pack_entry_find(&e, (struct pack_backend *)backend, oid)) < 0 || diff --git a/src/rebase.c b/src/rebase.c index b636e7951..8da7b4f7f 100644 --- a/src/rebase.c +++ b/src/rebase.c @@ -512,7 +512,7 @@ static int rebase_ensure_not_dirty( git_tree *head = NULL; git_index *index = NULL; git_diff *diff = NULL; - int error; + int error = 0; if (check_index) { if ((error = git_repository_head_tree(&head, repo)) < 0 ||