Skip to content

Commit 6991357

Browse files
committed
fast-export --export-marks: fix off by one error
The export_marks() function iterated over a (potentially sparsely populated) hashtable, but it accessed it starting from offset 1 and one element beyond the end. Noticed by SungHyun Nam. Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 6cbf8b0 commit 6991357

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

builtin-fast-export.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -379,19 +379,19 @@ static void export_marks(char *file)
379379
if (!f)
380380
error("Unable to open marks file %s for writing", file);
381381

382-
for (i = 0; i < idnums.size; ++i) {
383-
deco++;
384-
if (deco && deco->base && deco->base->type == 1) {
382+
for (i = 0; i < idnums.size; i++) {
383+
if (deco->base && deco->base->type == 1) {
385384
mark = ptr_to_mark(deco->decoration);
386385
fprintf(f, ":%u %s\n", mark, sha1_to_hex(deco->base->sha1));
387386
}
387+
deco++;
388388
}
389389

390390
if (ferror(f) || fclose(f))
391391
error("Unable to write marks file %s.", file);
392392
}
393393

394-
static void import_marks(char * input_file)
394+
static void import_marks(char *input_file)
395395
{
396396
char line[512];
397397
FILE *f = fopen(input_file, "r");
@@ -407,7 +407,7 @@ static void import_marks(char * input_file)
407407
line_end = strchr(line, '\n');
408408
if (line[0] != ':' || !line_end)
409409
die("corrupt mark line: %s", line);
410-
*line_end = 0;
410+
*line_end = '\0';
411411

412412
mark = strtoumax(line + 1, &mark_end, 10);
413413
if (!mark || mark_end == line + 1

decorate.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ static void grow_decoration(struct decoration *n)
3737
{
3838
int i;
3939
int old_size = n->size;
40-
struct object_decoration *old_hash;
41-
42-
old_size = n->size;
43-
old_hash = n->hash;
40+
struct object_decoration *old_hash = n->hash;
4441

4542
n->size = (old_size + 1000) * 3 / 2;
4643
n->hash = xcalloc(n->size, sizeof(struct object_decoration));

0 commit comments

Comments
 (0)