From: Szabolcs Nagy <nsz@port70.net>
To: musl@lists.openwall.com
Subject: Re: segfault on sscanf
Date: Thu, 14 Mar 2019 19:19:19 +0100 [thread overview]
Message-ID: <20190314181919.GJ26605@port70.net> (raw)
In-Reply-To: <20190314165335.GJ28106@voyager>
* Markus Wichmann <nullplan@gmx.net> [2019-03-14 17:53:35 +0100]:
> The input is just "0". So inside this if-clause, shgetc() will return
> EOF and set the FILE's shend to 0. The shunget() therefore does nothing.
> Then we continue on to decfloat(). decfloat() will call shget() at least
> once. Unfortunately, this is shget()s definition:
>
> #define shgetc(f) (((f)->rpos != (f)->shend) ? *(f)->rpos++ : __shgetc(f))
>
> Since f->shend == 0, but f->rpos == "0"+1, this will start dereferencing
> uncharted territory. But it will probably not crash immediately. That's
> what the %c parser is for. For %c it will keep parsing forever,
> eventually reaching unmapped memory and segfaulting.
>
> Bonus: Since now f->rpos > f->rend, __shlim() does nothing to prevent
> this issue.
>
> Maybe the EOF status should be sticky. Like this? (Line break because
> e-mail).
>
> #define shgetc(f) (!(f)->shend ? EOF : \
> (f)->rpos != (f)->shend ? *(f)->rpos++ : __shgetc(f))
i think __shgetc should ensure f->rpos == f->shend on EOF
next prev parent reply other threads:[~2019-03-14 18:19 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-14 9:46 Marian Buschsieweke
2019-03-14 12:44 ` A. Wilcox
2019-03-14 13:29 ` Szabolcs Nagy
2019-03-14 14:34 ` Pascal Cuoq
2019-03-14 16:28 ` Markus Wichmann
2019-03-14 16:53 ` Markus Wichmann
2019-03-14 18:19 ` Szabolcs Nagy [this message]
2019-03-14 18:38 ` Markus Wichmann
2019-03-14 19:49 ` Szabolcs Nagy
2019-03-14 20:15 ` Szabolcs Nagy
2019-03-14 22:34 ` Rich Felker
2019-03-14 22:43 ` Szabolcs Nagy
2019-03-14 22:52 ` Rich Felker
2019-03-15 1:54 ` Rich Felker
2019-03-14 22:40 ` Rich Felker
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=20190314181919.GJ26605@port70.net \
--to=nsz@port70.net \
--cc=musl@lists.openwall.com \
/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).