summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <carlosmn@github.com>2016-03-14 17:45:15 +0100
committerCarlos Martín Nieto <carlosmn@github.com>2016-03-14 17:45:15 +0100
commit4848dd326a98c5973b82f5a362a52362855a4fc5 (patch)
treebe3818990dfa00b817de402c5f5b66f6a1e5f57e
parentfa31ee6835873f3228c2206988c284ce705cd04b (diff)
parent2615d0d6949c9f52e988ab649f10cf7a80c45186 (diff)
downloadlibgit2-4848dd326a98c5973b82f5a362a52362855a4fc5.tar.gz
Merge pull request #3647 from pks-t/pks/coverity-fixes-round6
Coverity fixes round 6
-rwxr-xr-xscript/coverity.sh18
-rw-r--r--src/config_file.c5
-rw-r--r--src/describe.c3
-rw-r--r--src/diff_tform.c8
-rw-r--r--src/index.c12
-rw-r--r--src/object.c9
-rw-r--r--src/pack-objects.c4
-rw-r--r--src/submodule.c3
8 files changed, 45 insertions, 17 deletions
diff --git a/script/coverity.sh b/script/coverity.sh
index 8c826892f..7fe9eb4c7 100755
--- a/script/coverity.sh
+++ b/script/coverity.sh
@@ -49,10 +49,24 @@ COVERITY_UNSUPPORTED=1 \
# Upload results
tar czf libgit2.tgz cov-int
SHA=$(git rev-parse --short HEAD)
-curl \
+
+HTML="$(curl \
+ --silent \
+ --write-out "\n%{http_code}" \
--form token="$COVERITY_TOKEN" \
--form email=bs@github.com \
--form file=@libgit2.tgz \
--form version="$SHA" \
--form description="Travis build" \
- https://scan.coverity.com/builds?project=libgit2
+ https://scan.coverity.com/builds?project=libgit2)"
+# Body is everything up to the last line
+BODY="$(echo "$HTML" | head -n-1)"
+# Status code is the last line
+STATUS_CODE="$(echo "$HTML" | tail -n1)"
+
+echo "${BODY}"
+
+if [ "${STATUS_CODE}" != "201" ]; then
+ echo "Received error code ${STATUS_CODE} from Coverity"
+ exit 1
+fi
diff --git a/src/config_file.c b/src/config_file.c
index 5f5e309e0..65971b930 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -1032,6 +1032,11 @@ static int parse_section_header_ext(struct reader *reader, const char *line, con
*/
first_quote = strchr(line, '"');
+ if (first_quote == NULL) {
+ set_parse_error(reader, 0, "Missing quotation marks in section header");
+ return -1;
+ }
+
last_quote = strrchr(line, '"');
quoted_len = last_quote - first_quote;
diff --git a/src/describe.c b/src/describe.c
index 48f04e858..13ddad5be 100644
--- a/src/describe.c
+++ b/src/describe.c
@@ -582,7 +582,8 @@ static int describe(
best = (struct possible_tag *)git_vector_get(&all_matches, 0);
if (gave_up_on) {
- git_pqueue_insert(&list, gave_up_on);
+ if ((error = git_pqueue_insert(&list, gave_up_on)) < 0)
+ goto cleanup;
seen_commits--;
}
if ((error = finish_depth_computation(
diff --git a/src/diff_tform.c b/src/diff_tform.c
index 8577f06b8..6a6a62811 100644
--- a/src/diff_tform.c
+++ b/src/diff_tform.c
@@ -261,7 +261,7 @@ static int normalize_find_opts(
if (!given ||
(given->flags & GIT_DIFF_FIND_ALL) == GIT_DIFF_FIND_BY_CONFIG)
{
- if (diff->repo) {
+ if (cfg) {
char *rule =
git_config__get_string_force(cfg, "diff.renames", "true");
int boolval;
@@ -318,8 +318,10 @@ static int normalize_find_opts(
#undef USE_DEFAULT
if (!opts->rename_limit) {
- opts->rename_limit = git_config__get_int_force(
- cfg, "diff.renamelimit", DEFAULT_RENAME_LIMIT);
+ if (cfg) {
+ opts->rename_limit = git_config__get_int_force(
+ cfg, "diff.renamelimit", DEFAULT_RENAME_LIMIT);
+ }
if (opts->rename_limit <= 0)
opts->rename_limit = DEFAULT_RENAME_LIMIT;
diff --git a/src/index.c b/src/index.c
index b97f8091d..62aacf959 100644
--- a/src/index.c
+++ b/src/index.c
@@ -963,14 +963,20 @@ static int index_entry_reuc_init(git_index_reuc_entry **reuc_out,
*reuc_out = reuc = reuc_entry_alloc(path);
GITERR_CHECK_ALLOC(reuc);
- if ((reuc->mode[0] = ancestor_mode) > 0)
+ if ((reuc->mode[0] = ancestor_mode) > 0) {
+ assert(ancestor_oid);
git_oid_cpy(&reuc->oid[0], ancestor_oid);
+ }
- if ((reuc->mode[1] = our_mode) > 0)
+ if ((reuc->mode[1] = our_mode) > 0) {
+ assert(our_oid);
git_oid_cpy(&reuc->oid[1], our_oid);
+ }
- if ((reuc->mode[2] = their_mode) > 0)
+ if ((reuc->mode[2] = their_mode) > 0) {
+ assert(their_oid);
git_oid_cpy(&reuc->oid[2], their_oid);
+ }
return 0;
}
diff --git a/src/object.c b/src/object.c
index ebf77fb47..1d45f9f1b 100644
--- a/src/object.c
+++ b/src/object.c
@@ -12,6 +12,7 @@
#include "commit.h"
#include "tree.h"
#include "blob.h"
+#include "oid.h"
#include "tag.h"
bool git_object__strict_input_validation = true;
@@ -166,13 +167,9 @@ int git_object_lookup_prefix(
error = git_odb_read(&odb_obj, odb, id);
}
} else {
- git_oid short_oid;
+ git_oid short_oid = {{ 0 }};
- /* We copy the first len*4 bits from id and fill the remaining with 0s */
- memcpy(short_oid.id, id->id, (len + 1) / 2);
- if (len % 2)
- short_oid.id[len / 2] &= 0xF0;
- memset(short_oid.id + (len + 1) / 2, 0, (GIT_OID_HEXSZ - len) / 2);
+ git_oid__cpy_prefix(&short_oid, id, len);
/* If len < GIT_OID_HEXSZ (a strict short oid was given), we have
* 2 options :
diff --git a/src/pack-objects.c b/src/pack-objects.c
index 46fe8f3db..11e13f7d4 100644
--- a/src/pack-objects.c
+++ b/src/pack-objects.c
@@ -848,8 +848,10 @@ static int try_delta(git_packbuilder *pb, struct unpacked *trg,
git_packbuilder__cache_unlock(pb);
- if (overflow)
+ if (overflow) {
+ git__free(delta_buf);
return -1;
+ }
trg_object->delta_data = git__realloc(delta_buf, delta_size);
GITERR_CHECK_ALLOC(trg_object->delta_data);
diff --git a/src/submodule.c b/src/submodule.c
index 38db41529..3f39b9ef0 100644
--- a/src/submodule.c
+++ b/src/submodule.c
@@ -80,7 +80,8 @@ static kh_inline int str_equal_no_trailing_slash(const char *a, const char *b)
if (blen > 0 && b[blen - 1] == '/')
blen--;
- return (alen == blen && strncmp(a, b, alen) == 0);
+ return (alen == 0 && blen == 0) ||
+ (alen == blen && strncmp(a, b, alen) == 0);
}
__KHASH_IMPL(