Skip to content

Commit afe2fab

Browse files
committed
gc: call fscanf() with %<len>s, not %<len>c, when reading hostname
Earlier in this codepath, we (ab)used "%<len>c" to read the hostname recorded in the lockfile into locking_host[HOST_NAME_MAX + 1] while substituting <len> with the actual value of HOST_NAME_MAX. This turns out to be incorrect, as it is an instruction to read exactly the specified number of bytes. Because we are trying to read at most that many bytes, we should be using "%<len>s" instead. Helped-by: A. Wilcox <awilfox@adelielinux.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent da25bdb commit afe2fab

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

builtin/gc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
244244
int should_exit;
245245

246246
if (!scan_fmt)
247-
scan_fmt = xstrfmt("%s %%%dc", "%"SCNuMAX, HOST_NAME_MAX);
247+
scan_fmt = xstrfmt("%s %%%ds", "%"SCNuMAX, HOST_NAME_MAX);
248248
fp = fopen(pidfile_path, "r");
249249
memset(locking_host, 0, sizeof(locking_host));
250250
should_exit =

0 commit comments

Comments
 (0)