mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "A. Wilcox" <awilfox@adelielinux.org>
Cc: musl@lists.openwall.com, Jeff King <peff@peff.net>,
	Kevin Daudt <me@ikke.info>,
	git@vger.kernel.org
Subject: Re: Git 2.14.1: t6500: error during test on musl libc
Date: Sun, 17 Sep 2017 12:16:55 +0900	[thread overview]
Message-ID: <xmqq60ciui8o.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <59BDD6AF.5090604@adelielinux.org> (A. Wilcox's message of "Sat, 16 Sep 2017 20:58:07 -0500")

"A. Wilcox" <awilfox@adelielinux.org> writes:

>> I did a quick scan for substring "scanf" and read through the 
>> output, and it seems that this is the only one that wants to do
>> the this many characters, e.g. "%42c", conversion.
>> So it seems to me that a real fix has to read the file ourselves
>> and parse up to our HOST_NAME_MAX+1 to see if the hostname refers
>> to us, and fscanf that cannot take "slurp up to this many bytes" is
>> not useful tool to implementing that parsing.
> ...
> Except that is *exactly* *what* *s* *does* (quoting C11 §7.21.6.2):
>
> 9   An input item is defined as the longest sequence of input
>     characters which does not exceed any specified field width

Ah, sorry, I completely misread what you meant.

I thought you were suggesting to replace "%<length>c" with just an
unadorned "%s".  You meant that we can use "%<length>s" instead.
And that solution makes sense.  Yes, it is exactly what %<len>s
does.

So something like the following would be a sufficient fix, I guess?

Thanks.

-- >8 --
Subject: 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 an instruction to read exactly
the specified number of bytes.  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 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/builtin/gc.c b/builtin/gc.c
index 3c78fcb9b1..bb2d6c1fb2 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -258,7 +258,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 =


  reply	other threads:[~2017-09-17  3:16 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <59BB3E40.7020804@adelielinux.org>
     [not found] ` <20170915063740.GB21499@alpha.vpn.ikke.info>
     [not found]   ` <20170915113011.emko6q5utb7x4bvu@sigill.intra.peff.net>
2017-09-16  4:58     ` A. Wilcox
2017-09-16 16:13       ` Rich Felker
2017-09-17  0:36       ` Junio C Hamano
2017-09-17  1:17         ` Szabolcs Nagy
2017-09-17  1:58         ` A. Wilcox
2017-09-17  3:16           ` Junio C Hamano [this message]
2017-09-17  3:38             ` A. Wilcox

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqq60ciui8o.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox.com \
    --cc=awilfox@adelielinux.org \
    --cc=git@vger.kernel.org \
    --cc=me@ikke.info \
    --cc=musl@lists.openwall.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).