Skip to content

Commit b840855

Browse files
committed
Merge remote-tracking branch 'origin/master' into no-pkt-pack
2 parents 895a668 + 967da2c commit b840855

File tree

9 files changed

+112
-57
lines changed

9 files changed

+112
-57
lines changed

deps/http-parser/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
FILE(GLOB SRC_HTTP "*.c" "*.h")
22

33
ADD_LIBRARY(http-parser OBJECT ${SRC_HTTP})
4+
5+
ENABLE_WARNINGS(implicit-fallthrough=1)

src/config_file.c

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -876,10 +876,8 @@ static char *escape_value(const char *ptr)
876876
ptr++;
877877
}
878878

879-
if (git_buf_oom(&buf)) {
880-
git_buf_dispose(&buf);
879+
if (git_buf_oom(&buf))
881880
return NULL;
882-
}
883881

884882
return git_buf_detach(&buf);
885883
}
@@ -1022,33 +1020,33 @@ static int parse_conditional_include(git_config_parser *reader,
10221020
static int read_on_variable(
10231021
git_config_parser *reader,
10241022
const char *current_section,
1025-
char *var_name,
1026-
char *var_value,
1023+
const char *var_name,
1024+
const char *var_value,
10271025
const char *line,
10281026
size_t line_len,
10291027
void *data)
10301028
{
10311029
diskfile_parse_state *parse_data = (diskfile_parse_state *)data;
10321030
git_buf buf = GIT_BUF_INIT;
10331031
git_config_entry *entry;
1032+
const char *c;
10341033
int result = 0;
10351034

10361035
GIT_UNUSED(line);
10371036
GIT_UNUSED(line_len);
10381037

1039-
git__strtolower(var_name);
1040-
git_buf_printf(&buf, "%s.%s", current_section, var_name);
1041-
git__free(var_name);
1038+
git_buf_puts(&buf, current_section);
1039+
git_buf_putc(&buf, '.');
1040+
for (c = var_name; *c; c++)
1041+
git_buf_putc(&buf, git__tolower(*c));
10421042

1043-
if (git_buf_oom(&buf)) {
1044-
git__free(var_value);
1043+
if (git_buf_oom(&buf))
10451044
return -1;
1046-
}
10471045

10481046
entry = git__calloc(1, sizeof(git_config_entry));
10491047
GITERR_CHECK_ALLOC(entry);
10501048
entry->name = git_buf_detach(&buf);
1051-
entry->value = var_value;
1049+
entry->value = var_value ? git__strdup(var_value) : NULL;
10521050
entry->level = parse_data->level;
10531051
entry->include_depth = parse_data->depth;
10541052

@@ -1065,7 +1063,6 @@ static int read_on_variable(
10651063
result = parse_conditional_include(reader, parse_data,
10661064
entry->name, entry->value);
10671065

1068-
10691066
return result;
10701067
}
10711068

@@ -1249,8 +1246,8 @@ static int write_on_section(
12491246
static int write_on_variable(
12501247
git_config_parser *reader,
12511248
const char *current_section,
1252-
char *var_name,
1253-
char *var_value,
1249+
const char *var_name,
1250+
const char *var_value,
12541251
const char *line,
12551252
size_t line_len,
12561253
void *data)
@@ -1279,9 +1276,6 @@ static int write_on_variable(
12791276
if (has_matched && write_data->preg != NULL)
12801277
has_matched = (regexec(write_data->preg, var_value, 0, NULL, 0) == 0);
12811278

1282-
git__free(var_name);
1283-
git__free(var_value);
1284-
12851279
/* If this isn't the name/value we're looking for, simply dump the
12861280
* existing data back out and continue on.
12871281
*/

src/config_parse.c

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -404,22 +404,21 @@ static int parse_name(
404404
static int parse_variable(git_config_parser *reader, char **var_name, char **var_value)
405405
{
406406
const char *value_start = NULL;
407-
char *line;
408-
int quote_count;
407+
char *line = NULL, *name = NULL, *value = NULL;
408+
int quote_count, error;
409409
bool multiline;
410410

411+
*var_name = NULL;
412+
*var_value = NULL;
413+
411414
git_parse_advance_ws(&reader->ctx);
412415
line = git__strndup(reader->ctx.line, reader->ctx.line_len);
413-
if (line == NULL)
414-
return -1;
416+
GITERR_CHECK_ALLOC(line);
415417

416418
quote_count = strip_comments(line, 0);
417419

418-
/* If there is no value, boolean true is assumed */
419-
*var_value = NULL;
420-
421-
if (parse_name(var_name, &value_start, reader, line) < 0)
422-
goto on_error;
420+
if ((error = parse_name(&name, &value_start, reader, line)) < 0)
421+
goto out;
423422

424423
/*
425424
* Now, let's try to parse the value
@@ -428,30 +427,34 @@ static int parse_variable(git_config_parser *reader, char **var_name, char **var
428427
while (git__isspace(value_start[0]))
429428
value_start++;
430429

431-
if (unescape_line(var_value, &multiline, value_start, 0) < 0)
432-
goto on_error;
430+
if ((error = unescape_line(&value, &multiline, value_start, 0)) < 0)
431+
goto out;
433432

434433
if (multiline) {
435434
git_buf multi_value = GIT_BUF_INIT;
436-
git_buf_attach(&multi_value, *var_value, 0);
435+
git_buf_attach(&multi_value, value, 0);
437436

438437
if (parse_multiline_variable(reader, &multi_value, quote_count) < 0 ||
439-
git_buf_oom(&multi_value)) {
438+
git_buf_oom(&multi_value)) {
439+
error = -1;
440440
git_buf_dispose(&multi_value);
441-
goto on_error;
441+
goto out;
442442
}
443443

444-
*var_value = git_buf_detach(&multi_value);
444+
value = git_buf_detach(&multi_value);
445445
}
446446
}
447447

448-
git__free(line);
449-
return 0;
448+
*var_name = name;
449+
*var_value = value;
450+
name = NULL;
451+
value = NULL;
450452

451-
on_error:
452-
git__free(*var_name);
453+
out:
454+
git__free(name);
455+
git__free(value);
453456
git__free(line);
454-
return -1;
457+
return error;
455458
}
456459

457460
int git_config_parse(
@@ -463,7 +466,7 @@ int git_config_parse(
463466
void *data)
464467
{
465468
git_parse_ctx *ctx;
466-
char *current_section = NULL, *var_name, *var_value;
469+
char *current_section = NULL, *var_name = NULL, *var_value = NULL;
467470
int result = 0;
468471

469472
ctx = &parser->ctx;
@@ -508,7 +511,10 @@ int git_config_parse(
508511
default: /* assume variable declaration */
509512
if ((result = parse_variable(parser, &var_name, &var_value)) == 0 && on_variable) {
510513
result = on_variable(parser, current_section, var_name, var_value, line_start, line_len, data);
514+
git__free(var_name);
515+
git__free(var_value);
511516
}
517+
512518
break;
513519
}
514520

src/config_parse.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ typedef int (*git_config_parser_section_cb)(
3636
typedef int (*git_config_parser_variable_cb)(
3737
git_config_parser *parser,
3838
const char *current_section,
39-
char *var_name,
40-
char *var_value,
39+
const char *var_name,
40+
const char *var_value,
4141
const char *line,
4242
size_t line_len,
4343
void *data);

src/revwalk.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ static int get_revision(git_commit_list_node **out, git_revwalk *walk, git_commi
455455
*/
456456
if (!walk->limited) {
457457
if ((error = add_parents_to_list(walk, commit, list)) < 0)
458-
return error;
458+
return error;
459459
}
460460

461461
*out = commit;
@@ -678,7 +678,7 @@ void git_revwalk_sorting(git_revwalk *walk, unsigned int sort_mode)
678678
walk->enqueue = &revwalk_enqueue_unsorted;
679679
}
680680

681-
if (sort_mode != GIT_SORT_NONE)
681+
if (walk->sorting != GIT_SORT_NONE)
682682
walk->limited = 1;
683683
}
684684

@@ -737,6 +737,7 @@ void git_revwalk_reset(git_revwalk *walk)
737737
walk->walking = 0;
738738
walk->limited = 0;
739739
walk->did_push = walk->did_hide = 0;
740+
walk->sorting = GIT_SORT_NONE;
740741
}
741742

742743
int git_revwalk_add_hide_cb(

src/transports/smart.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,10 @@ int git_smart__update_heads(transport_smart *t, git_vector *symrefs)
167167
git_vector_foreach(symrefs, j, spec) {
168168
git_buf_clear(&buf);
169169
if (git_refspec_src_matches(spec, ref->head.name) &&
170-
!(error = git_refspec_transform(&buf, spec, ref->head.name)))
170+
!(error = git_refspec_transform(&buf, spec, ref->head.name))) {
171+
git__free(ref->head.symref_target);
171172
ref->head.symref_target = git_buf_detach(&buf);
173+
}
172174
}
173175

174176
git_buf_dispose(&buf);
@@ -266,14 +268,21 @@ static int git_smart__connect(
266268
/* We now have loaded the refs. */
267269
t->have_refs = 1;
268270

269-
first = (git_pkt_ref *)git_vector_get(&t->refs, 0);
271+
pkt = (git_pkt *)git_vector_get(&t->refs, 0);
272+
if (pkt && GIT_PKT_REF != pkt->type) {
273+
giterr_set(GITERR_NET, "invalid response");
274+
return -1;
275+
}
276+
first = (git_pkt_ref *)pkt;
270277

271278
if ((error = git_vector_init(&symrefs, 1, NULL)) < 0)
272279
return error;
273280

274281
/* Detect capabilities */
275-
if (git_smart__detect_caps(first, &t->caps, &symrefs) < 0)
282+
if (git_smart__detect_caps(first, &t->caps, &symrefs) < 0) {
283+
free_symrefs(&symrefs);
276284
return -1;
285+
}
277286

278287
/* If the only ref in the list is capabilities^{} with OID_ZERO, remove it */
279288
if (1 == t->refs.length && !strcmp(first->head.name, "capabilities^{}") &&

src/transports/smart_pkt.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ static int ref_pkt(git_pkt **out, const char *line, size_t len)
203203
git_pkt_ref *pkt;
204204
size_t alloclen;
205205

206+
if (len < GIT_OID_HEXSZ + 1) {
207+
giterr_set(GITERR_NET, "error parsing pkt-line");
208+
return -1;
209+
}
210+
206211
pkt = git__malloc(sizeof(git_pkt_ref));
207212
GITERR_CHECK_ALLOC(pkt);
208213

@@ -470,6 +475,9 @@ int git_pkt_parse_line(
470475

471476
void git_pkt_free(git_pkt *pkt)
472477
{
478+
if (pkt == NULL) {
479+
return;
480+
}
473481
if (pkt->type == GIT_PKT_REF) {
474482
git_pkt_ref *p = (git_pkt_ref *) pkt;
475483
git__free(p->head.name);

src/transports/smart_protocol.c

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ int git_smart__store_refs(transport_smart *t, int flushes)
7070
return -1;
7171
}
7272

73+
if (pkt->type == GIT_PKT_PACK) {
74+
giterr_set(GITERR_NET, "unexpected packfile");
75+
git__free(pkt);
76+
return -1;
77+
}
78+
7379
if (pkt->type != GIT_PKT_FLUSH && git_vector_insert(refs, pkt) < 0)
7480
return -1;
7581

@@ -317,27 +323,30 @@ static int fetch_setup_walk(git_revwalk **out, git_repository *repo)
317323
static int wait_while_ack(gitno_buffer *buf)
318324
{
319325
int error;
320-
git_pkt_ack *pkt = NULL;
326+
git_pkt *pkt = NULL;
327+
git_pkt_ack *ack = NULL;
321328

322329
while (1) {
323-
git__free(pkt);
330+
git_pkt_free(pkt);
324331

325-
if ((error = recv_pkt((git_pkt **)&pkt, NULL, buf)) < 0)
332+
if ((error = recv_pkt(&pkt, NULL, buf)) < 0)
326333
return error;
327334

328335
if (pkt->type == GIT_PKT_NAK)
329336
break;
337+
if (pkt->type != GIT_PKT_ACK)
338+
continue;
330339

331-
if (pkt->type == GIT_PKT_ACK &&
332-
(pkt->status != GIT_ACK_CONTINUE &&
333-
pkt->status != GIT_ACK_COMMON &&
334-
pkt->status != GIT_ACK_READY)) {
335-
git__free(pkt);
336-
return 0;
340+
ack = (git_pkt_ack*)pkt;
341+
342+
if (ack->status != GIT_ACK_CONTINUE &&
343+
ack->status != GIT_ACK_COMMON &&
344+
ack->status != GIT_ACK_READY) {
345+
break;
337346
}
338347
}
339348

340-
git__free(pkt);
349+
git_pkt_free(pkt);
341350
return 0;
342351
}
343352

@@ -615,7 +624,8 @@ int git_smart__download_pack(
615624
}
616625
}
617626

618-
git__free(pkt);
627+
git_pkt_free(pkt);
628+
619629
if (error < 0)
620630
goto done;
621631

tests/revwalk/basic.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,31 @@ void test_revwalk_basic__push_head(void)
197197
cl_assert_equal_i(i, 7);
198198
}
199199

200+
void test_revwalk_basic__sorted_after_reset(void)
201+
{
202+
int i = 0;
203+
git_oid oid;
204+
205+
revwalk_basic_setup_walk(NULL);
206+
207+
git_oid_fromstr(&oid, commit_head);
208+
209+
/* push, sort, and test the walk */
210+
cl_git_pass(git_revwalk_push(_walk, &oid));
211+
git_revwalk_sorting(_walk, GIT_SORT_TIME);
212+
213+
cl_git_pass(test_walk_only(_walk, commit_sorting_time, 2));
214+
215+
/* reset, push, and test again - we should see all entries */
216+
git_revwalk_reset(_walk);
217+
cl_git_pass(git_revwalk_push(_walk, &oid));
218+
219+
while (git_revwalk_next(&oid, _walk) == 0)
220+
i++;
221+
222+
cl_assert_equal_i(i, commit_count);
223+
}
224+
200225
void test_revwalk_basic__push_head_hide_ref(void)
201226
{
202227
int i = 0;

0 commit comments

Comments
 (0)