Merge pull request #3647 from pks-t/pks/coverity-fixes-round6 Coverity fixes round 6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
diff --git a/script/coverity.sh b/script/coverity.sh
index 8c82689..7fe9eb4 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 5f5e309..65971b9 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 48f04e8..13ddad5 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 8577f06..6a6a628 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 b97f809..62aacf9 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 ebf77fb..1d45f9f 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 46fe8f3..11e13f7 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 38db415..3f39b9e 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(