Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b643501

Browse files
committed
Merge pull request libgit2#3614 from pks-t/pks/coverity-fixes
Coverity fixes
2 parents c1b75f0 + 8a62bf1 commit b643501

File tree

5 files changed

+30
-3
lines changed

5 files changed

+30
-3
lines changed

script/user_nodefs.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,22 @@
66
*/
77

88
#nodef GITERR_CHECK_ALLOC(ptr) if (ptr == NULL) { __coverity_panic__(); }
9+
10+
#nodef GITERR_CHECK_ALLOC_ADD(out, one, two) \
11+
if (GIT_ADD_SIZET_OVERFLOW(out, one, two)) { __coverity_panic__(); }
12+
13+
#nodef GITERR_CHECK_ALLOC_ADD3(out, one, two, three) \
14+
if (GIT_ADD_SIZET_OVERFLOW(out, one, two) || \
15+
GIT_ADD_SIZET_OVERFLOW(out, *(out), three)) { __coverity_panic__(); }
16+
17+
#nodef GITERR_CHECK_ALLOC_ADD4(out, one, two, three, four) \
18+
if (GIT_ADD_SIZET_OVERFLOW(out, one, two) || \
19+
GIT_ADD_SIZET_OVERFLOW(out, *(out), three) || \
20+
GIT_ADD_SIZET_OVERFLOW(out, *(out), four)) { __coverity_panic__(); }
21+
22+
#nodef GITERR_CHECK_ALLOC_MULTIPLY(out, nelem, elsize) \
23+
if (GIT_MULTIPLY_SIZET_OVERFLOW(out, nelem, elsize)) { __coverity_panic__(); }
24+
25+
#nodef GITERR_CHECK_VERSION(S,V,N) if (giterr__check_version(S,V,N) < 0) { __coverity_panic__(); }
26+
27+
#nodef LOOKS_LIKE_DRIVE_PREFIX(S) (strlen(S) >= 2 && git__isalpha((S)[0]) && (S)[1] == ':')

src/netops.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,10 @@ int gitno_extract_url_parts(
261261
*path = git__substrdup(_path, u.field_data[UF_PATH].len);
262262
GITERR_CHECK_ALLOC(*path);
263263
} else {
264+
git__free(*port);
265+
*port = NULL;
266+
git__free(*host);
267+
*host = NULL;
264268
giterr_set(GITERR_NET, "invalid url, missing path");
265269
return GIT_EINVALIDSPEC;
266270
}

src/signature.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,9 @@ int git_signature_new(git_signature **sig_out, const char *name, const char *ema
7979
GITERR_CHECK_ALLOC(p);
8080

8181
p->name = extract_trimmed(name, strlen(name));
82+
GITERR_CHECK_ALLOC(p->name);
8283
p->email = extract_trimmed(email, strlen(email));
83-
84-
if (p->name == NULL || p->email == NULL)
85-
return -1; /* oom */
84+
GITERR_CHECK_ALLOC(p->email);
8685

8786
if (p->name[0] == '\0' || p->email[0] == '\0') {
8887
git_signature_free(p);

src/transports/smart_pkt.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ static int ok_pkt(git_pkt **out, const char *line, size_t len)
271271
line += 3; /* skip "ok " */
272272
if (!(ptr = strchr(line, '\n'))) {
273273
giterr_set(GITERR_NET, "Invalid packet line");
274+
git__free(pkt);
274275
return -1;
275276
}
276277
len = ptr - line;
@@ -314,6 +315,8 @@ static int ng_pkt(git_pkt **out, const char *line, size_t len)
314315
line = ptr + 1;
315316
if (!(ptr = strchr(line, '\n'))) {
316317
giterr_set(GITERR_NET, "Invalid packet line");
318+
git__free(pkt->ref);
319+
git__free(pkt);
317320
return -1;
318321
}
319322
len = ptr - line;

src/transports/smart_protocol.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ static int append_symref(const char **out, git_vector *symrefs, const char *ptr)
108108
if (giterr_last()->klass != GITERR_NOMEMORY)
109109
goto on_invalid;
110110

111+
git__free(mapping);
111112
return error;
112113
}
113114

@@ -120,6 +121,7 @@ static int append_symref(const char **out, git_vector *symrefs, const char *ptr)
120121
on_invalid:
121122
giterr_set(GITERR_NET, "remote sent invalid symref");
122123
git_refspec__free(mapping);
124+
git__free(mapping);
123125
return -1;
124126
}
125127

0 commit comments

Comments
 (0)