Merge pull request #3614 from pks-t/pks/coverity-fixes Coverity fixes
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
diff --git a/script/user_nodefs.h b/script/user_nodefs.h
index 110f768..3d25d92 100644
--- a/script/user_nodefs.h
+++ b/script/user_nodefs.h
@@ -6,3 +6,22 @@
*/
#nodef GITERR_CHECK_ALLOC(ptr) if (ptr == NULL) { __coverity_panic__(); }
+
+#nodef GITERR_CHECK_ALLOC_ADD(out, one, two) \
+ if (GIT_ADD_SIZET_OVERFLOW(out, one, two)) { __coverity_panic__(); }
+
+#nodef GITERR_CHECK_ALLOC_ADD3(out, one, two, three) \
+ if (GIT_ADD_SIZET_OVERFLOW(out, one, two) || \
+ GIT_ADD_SIZET_OVERFLOW(out, *(out), three)) { __coverity_panic__(); }
+
+#nodef GITERR_CHECK_ALLOC_ADD4(out, one, two, three, four) \
+ if (GIT_ADD_SIZET_OVERFLOW(out, one, two) || \
+ GIT_ADD_SIZET_OVERFLOW(out, *(out), three) || \
+ GIT_ADD_SIZET_OVERFLOW(out, *(out), four)) { __coverity_panic__(); }
+
+#nodef GITERR_CHECK_ALLOC_MULTIPLY(out, nelem, elsize) \
+ if (GIT_MULTIPLY_SIZET_OVERFLOW(out, nelem, elsize)) { __coverity_panic__(); }
+
+#nodef GITERR_CHECK_VERSION(S,V,N) if (giterr__check_version(S,V,N) < 0) { __coverity_panic__(); }
+
+#nodef LOOKS_LIKE_DRIVE_PREFIX(S) (strlen(S) >= 2 && git__isalpha((S)[0]) && (S)[1] == ':')
diff --git a/src/netops.c b/src/netops.c
index 5e80755..c424198 100644
--- a/src/netops.c
+++ b/src/netops.c
@@ -261,6 +261,10 @@ int gitno_extract_url_parts(
*path = git__substrdup(_path, u.field_data[UF_PATH].len);
GITERR_CHECK_ALLOC(*path);
} else {
+ git__free(*port);
+ *port = NULL;
+ git__free(*host);
+ *host = NULL;
giterr_set(GITERR_NET, "invalid url, missing path");
return GIT_EINVALIDSPEC;
}
diff --git a/src/signature.c b/src/signature.c
index 109476e..d07c933 100644
--- a/src/signature.c
+++ b/src/signature.c
@@ -79,10 +79,9 @@ int git_signature_new(git_signature **sig_out, const char *name, const char *ema
GITERR_CHECK_ALLOC(p);
p->name = extract_trimmed(name, strlen(name));
+ GITERR_CHECK_ALLOC(p->name);
p->email = extract_trimmed(email, strlen(email));
-
- if (p->name == NULL || p->email == NULL)
- return -1; /* oom */
+ GITERR_CHECK_ALLOC(p->email);
if (p->name[0] == '\0' || p->email[0] == '\0') {
git_signature_free(p);
diff --git a/src/transports/smart_pkt.c b/src/transports/smart_pkt.c
index a6ae55d..870f084 100644
--- a/src/transports/smart_pkt.c
+++ b/src/transports/smart_pkt.c
@@ -271,6 +271,7 @@ static int ok_pkt(git_pkt **out, const char *line, size_t len)
line += 3; /* skip "ok " */
if (!(ptr = strchr(line, '\n'))) {
giterr_set(GITERR_NET, "Invalid packet line");
+ git__free(pkt);
return -1;
}
len = ptr - line;
@@ -314,6 +315,8 @@ static int ng_pkt(git_pkt **out, const char *line, size_t len)
line = ptr + 1;
if (!(ptr = strchr(line, '\n'))) {
giterr_set(GITERR_NET, "Invalid packet line");
+ git__free(pkt->ref);
+ git__free(pkt);
return -1;
}
len = ptr - line;
diff --git a/src/transports/smart_protocol.c b/src/transports/smart_protocol.c
index 1d46d4b..6363378 100644
--- a/src/transports/smart_protocol.c
+++ b/src/transports/smart_protocol.c
@@ -108,6 +108,7 @@ static int append_symref(const char **out, git_vector *symrefs, const char *ptr)
if (giterr_last()->klass != GITERR_NOMEMORY)
goto on_invalid;
+ git__free(mapping);
return error;
}
@@ -120,6 +121,7 @@ static int append_symref(const char **out, git_vector *symrefs, const char *ptr)
on_invalid:
giterr_set(GITERR_NET, "remote sent invalid symref");
git_refspec__free(mapping);
+ git__free(mapping);
return -1;
}