Skip to content

Commit

Permalink
fsck: use strbuf to generate alternate directories
Browse files Browse the repository at this point in the history
When fsck-ing alternates, we make a copy of the alternate
directory in a fixed PATH_MAX buffer. We memcpy directly,
without any check whether we are overflowing the buffer.
This is OK if PATH_MAX is a true representation of the
maximum path on the system, because any path here will have
already been vetted by the alternates subsystem. But that is
not true on every system, so we should be more careful.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Sep 25, 2015
1 parent af49c6d commit c1fd080
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions builtin/fsck.c
Original file line number Diff line number Diff line change
Expand Up @@ -683,11 +683,12 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)

prepare_alt_odb();
for (alt = alt_odb_list; alt; alt = alt->next) {
char namebuf[PATH_MAX];
int namelen = alt->name - alt->base;
memcpy(namebuf, alt->base, namelen);
namebuf[namelen - 1] = 0;
fsck_object_dir(namebuf);
/* directory name, minus trailing slash */
size_t namelen = alt->name - alt->base - 1;
struct strbuf name = STRBUF_INIT;
strbuf_add(&name, alt->base, namelen);
fsck_object_dir(name.buf);
strbuf_release(&name);
}
}

Expand Down

0 comments on commit c1fd080

Please sign in to comment.