Skip to content

Commit c1fd080

Browse files
peffgitster
authored andcommitted
fsck: use strbuf to generate alternate directories
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent af49c6d commit c1fd080

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

builtin/fsck.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -683,11 +683,12 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
683683

684684
prepare_alt_odb();
685685
for (alt = alt_odb_list; alt; alt = alt->next) {
686-
char namebuf[PATH_MAX];
687-
int namelen = alt->name - alt->base;
688-
memcpy(namebuf, alt->base, namelen);
689-
namebuf[namelen - 1] = 0;
690-
fsck_object_dir(namebuf);
686+
/* directory name, minus trailing slash */
687+
size_t namelen = alt->name - alt->base - 1;
688+
struct strbuf name = STRBUF_INIT;
689+
strbuf_add(&name, alt->base, namelen);
690+
fsck_object_dir(name.buf);
691+
strbuf_release(&name);
691692
}
692693
}
693694

0 commit comments

Comments
 (0)