Commit 6ae6491e by Etienne Samson

smart: don't dereference a NULL pkt pointer

By clarifying what detect_caps returns on empty/missing packet, we can
be sure there are actually refs to process. The old code could blindly
dereference `first`, which might have been NULL.

Reported by Coverity, CID 1393614
parent 68c7480a
...@@ -280,20 +280,23 @@ static int git_smart__connect( ...@@ -280,20 +280,23 @@ static int git_smart__connect(
/* Detect capabilities */ /* Detect capabilities */
if ((error = git_smart__detect_caps(first, &t->caps, &symrefs)) == 0) { if ((error = git_smart__detect_caps(first, &t->caps, &symrefs)) == 0) {
goto cleanup; /* If the only ref in the list is capabilities^{} with OID_ZERO, remove it */
} if (1 == t->refs.length && !strcmp(first->head.name, "capabilities^{}") &&
git_oid_iszero(&first->head.oid)) {
git_vector_clear(&t->refs);
git_pkt_free((git_pkt *)first);
}
/* If the only ref in the list is capabilities^{} with OID_ZERO, remove it */ /* Keep a list of heads for _ls */
if (1 == t->refs.length && !strcmp(first->head.name, "capabilities^{}") && git_smart__update_heads(t, &symrefs);
git_oid_iszero(&first->head.oid)) { } else if (error == GIT_ENOTFOUND) {
git_vector_clear(&t->refs); /* There was no ref packet received, or the cap list was empty */
git_pkt_free((git_pkt *)first); error = 0;
} else {
giterr_set(GITERR_NET, "invalid response");
goto cleanup;
} }
/* Keep a list of heads for _ls */
git_smart__update_heads(t, &symrefs);
if (t->rpc && (error = git_smart__reset_stream(t, false)) < 0) if (t->rpc && (error = git_smart__reset_stream(t, false)) < 0)
goto cleanup; goto cleanup;
......
...@@ -142,7 +142,7 @@ int git_smart__detect_caps(git_pkt_ref *pkt, transport_smart_caps *caps, git_vec ...@@ -142,7 +142,7 @@ int git_smart__detect_caps(git_pkt_ref *pkt, transport_smart_caps *caps, git_vec
/* No refs or capabilites, odd but not a problem */ /* No refs or capabilites, odd but not a problem */
if (pkt == NULL || pkt->capabilities == NULL) if (pkt == NULL || pkt->capabilities == NULL)
return 0; return GIT_ENOTFOUND;
ptr = pkt->capabilities; ptr = pkt->capabilities;
while (ptr != NULL && *ptr != '\0') { while (ptr != NULL && *ptr != '\0') {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment