From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: Possible out of bounds memory write in initialization of xdigits in src/stdio/vfprintf.c
Date: Thu, 28 Jun 2018 13:48:59 -0400 [thread overview]
Message-ID: <20180628174859.GH1392@brightrain.aerifal.cx> (raw)
In-Reply-To: <CANravCDuLFZ8tV56ZKo7BpwiKS59a1nSOyuGL1-a9Pis7ZrhxQ@mail.gmail.com>
On Thu, Jun 28, 2018 at 10:31:55AM -0700, Mark Winterrowd wrote:
> Hi all,
>
> On line 148 of src/stdio/vfprintf.c in the source tree head, you can
> observe the following global initialization:
>
> static const char xdigits[16] = {
> "0123456789ABCDEF"
> };
>
> Note that while this xdigits array has a length of 16, the string it is
> being initialized to has a length of 17, due to the implicit null
> terminator. Thus, an additional '\0' will be written just past the end of
> this global. I believe this could cause unpredictable effects depending
> upon how the compiler and linker handle this situation.
There's no write here, just initialization, and there's no such thing
as initialization past/outside of the object. While I'm not sure in
general if over-long string initializers are a constraint violation
(if so, this would be a compile-time warning/error), this specific
type (non-null-terminated) definitely isn't. See 6.7.9 ¶14:
"An array of character type may be initialized by a character
string literal or UTF-8 string literal, optionally enclosed in
braces. Successive bytes of the string literal (including the
terminating null character if there is room or if the array is of
unknown size) initialize the elements of the array."
Rich
prev parent reply other threads:[~2018-06-28 17:48 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-28 17:31 Mark Winterrowd
2018-06-28 17:48 ` Rich Felker [this message]
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=20180628174859.GH1392@brightrain.aerifal.cx \
--to=dalias@libc.org \
--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).