mailing list of musl libc
 help / color / mirror / code / Atom feed
* Possible out of bounds memory write in initialization of xdigits in src/stdio/vfprintf.c
@ 2018-06-28 17:31 Mark Winterrowd
  2018-06-28 17:48 ` Rich Felker
  0 siblings, 1 reply; 2+ messages in thread
From: Mark Winterrowd @ 2018-06-28 17:31 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 688 bytes --]

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.

The fix is simple, just write out a list of comma separated characters to
eliminate the null terminator or make xdigits have a length of 17.

Thanks,
Mark Winterrowd

[-- Attachment #2: Type: text/html, Size: 830 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Possible out of bounds memory write in initialization of xdigits in src/stdio/vfprintf.c
  2018-06-28 17:31 Possible out of bounds memory write in initialization of xdigits in src/stdio/vfprintf.c Mark Winterrowd
@ 2018-06-28 17:48 ` Rich Felker
  0 siblings, 0 replies; 2+ messages in thread
From: Rich Felker @ 2018-06-28 17:48 UTC (permalink / raw)
  To: musl

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-06-28 17:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-28 17:31 Possible out of bounds memory write in initialization of xdigits in src/stdio/vfprintf.c Mark Winterrowd
2018-06-28 17:48 ` Rich Felker

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).