gc: call fscanf() with %<len>s, not %<len>c, when reading hostname
authorJunio C Hamano <gitster@pobox.com>
Sun, 17 Sep 2017 03:16:55 +0000 (12:16 +0900)
committerJunio C Hamano <gitster@pobox.com>
Sun, 17 Sep 2017 04:21:44 +0000 (13:21 +0900)
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>
builtin/gc.c
index 5befd518fd1616c606efef9e4be15d6283811530..22b35a627e60be8bf15f28624834ac1f913efcd8 100644 (file)
@@ -244,7 +244,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 =