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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
af49c6d091
commit
c1fd080917
@ -683,11 +683,12 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
|
|||||||
|
|
||||||
prepare_alt_odb();
|
prepare_alt_odb();
|
||||||
for (alt = alt_odb_list; alt; alt = alt->next) {
|
for (alt = alt_odb_list; alt; alt = alt->next) {
|
||||||
char namebuf[PATH_MAX];
|
/* directory name, minus trailing slash */
|
||||||
int namelen = alt->name - alt->base;
|
size_t namelen = alt->name - alt->base - 1;
|
||||||
memcpy(namebuf, alt->base, namelen);
|
struct strbuf name = STRBUF_INIT;
|
||||||
namebuf[namelen - 1] = 0;
|
strbuf_add(&name, alt->base, namelen);
|
||||||
fsck_object_dir(namebuf);
|
fsck_object_dir(name.buf);
|
||||||
|
strbuf_release(&name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user