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

Skip to content

Commit 7284c10

Browse files
carlosmnvmg
authored andcommitted
Don't try to download the packfile too early
Make sure we only try to download the pack if we find the pack header in the stream, and not if the server takes a bit longer to send us the last NAK. Signed-off-by: Carlos Martín Nieto <[email protected]>
1 parent 441f57c commit 7284c10

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

src/transport_git.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,10 @@ static int store_pack(char **out, gitno_buffer *buf, git_repository *repo)
351351
strcat(path, suff);
352352
//memcpy(path + off, suff, GIT_PATH_MAX - off - STRLEN(suff) - 1);
353353

354+
if (memcmp(buf->data, "PACK", STRLEN("PACK"))) {
355+
return git__throw(GIT_ERROR, "The pack doesn't start with the signature");
356+
}
357+
354358
error = git_filebuf_open(&file, path, GIT_FILEBUF_TEMPORARY);
355359
if (error < GIT_SUCCESS)
356360
goto cleanup;
@@ -387,15 +391,15 @@ static int store_pack(char **out, gitno_buffer *buf, git_repository *repo)
387391
static int git_download_pack(char **out, git_transport *transport, git_repository *repo)
388392
{
389393
transport_git *t = (transport_git *) transport;
390-
int s = t->socket, error = GIT_SUCCESS, pack = 0;
394+
int s = t->socket, error = GIT_SUCCESS;
391395
gitno_buffer buf;
392396
char buffer[1024];
393397
git_pkt *pkt;
394398
const char *line_end, *ptr;
395399

396400
gitno_buffer_setup(&buf, buffer, sizeof(buffer), s);
397401
/*
398-
* First, we ignore any ACKs and wait for a NACK
402+
* For now, we ignore everything and wait for the pack
399403
*/
400404
while (1) {
401405
error = gitno_recv(&buf);
@@ -406,7 +410,7 @@ static int git_download_pack(char **out, git_transport *transport, git_repositor
406410

407411
ptr = buf.data;
408412
/* Whilst we're searching for the pack */
409-
while (!pack) {
413+
while (1) {
410414
if (buf.offset == 0)
411415
break;
412416
error = git_pkt_parse_line(&pkt, ptr, &line_end, buf.offset);
@@ -415,21 +419,14 @@ static int git_download_pack(char **out, git_transport *transport, git_repositor
415419
if (error < GIT_SUCCESS)
416420
return error;
417421

418-
gitno_consume(&buf, line_end);
419-
if (pkt->type == GIT_PKT_PACK)
420-
pack = 1;
422+
if (pkt->type == GIT_PKT_PACK) {
423+
return store_pack(out, &buf, repo);
424+
}
421425
/* For now we don't care about anything */
422426
free(pkt);
427+
gitno_consume(&buf, line_end);
423428
}
424-
425-
/*
426-
* No we have the packet, let's just put anything we get now
427-
* into a packfile
428-
*/
429-
return store_pack(out, &buf, repo);
430429
}
431-
432-
return error;
433430
}
434431

435432

0 commit comments

Comments
 (0)