Openwall GNU/*/Linux - a small security-enhanced Linux distro for servers
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date: Thu, 28 Jun 2018 13:48:59 -0400
From: Rich Felker <dalias@...c.org>
To: musl@...ts.openwall.com
Subject: Re: Possible out of bounds memory write in initialization of
 xdigits in src/stdio/vfprintf.c

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

Powered by blists - more mailing lists

Your e-mail address:

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.