From cd8ea9aa7a078a5d19906bf5088a4fb50cea60ef Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 17 Sep 2017 12:16:55 +0900 Subject: [PATCH] gc: call fscanf() with %s, not %c, when reading hostname Earlier in this codepath, we (ab)used "%c" to read the hostname recorded in the lockfile into locking_host[HOST_NAME_MAX + 1] while substituting 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 "%s" instead. [jes: this is a backport of afe2fab72c3 (gc: call fscanf() with %s, not %c, when reading hostname, 2017-09-17) to the vs2017_vcpkg branch, as it turns out that MSVC's fscanf() is more correct than GNU libc's, and returns only 1 correctly scanned field instead of the 2 expected by Git, making t6500-gc.sh fail.] Helped-by: A. Wilcox Signed-off-by: Junio C Hamano Signed-off-by: Johannes Schindelin --- builtin/gc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/gc.c b/builtin/gc.c index 5e779662f2..0896c6f475 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -257,7 +257,7 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid) int should_exit; if (!scan_fmt) - scan_fmt = xstrfmt("%s %%%dc", "%"SCNuMAX, HOST_NAME_MAX); + scan_fmt = xstrfmt("%s %%%ds", "%"SCNuMAX, HOST_NAME_MAX); fp = fopen(pidfile_path, "r"); memset(locking_host, 0, sizeof(locking_host)); should_exit =