mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Mark Winterrowd <markwinterrowd4@gmail.com>
To: musl@lists.openwall.com
Subject: Out of bounds memory read in src/stdio/vfprintf.c
Date: Thu, 28 Jun 2018 10:20:28 -0700	[thread overview]
Message-ID: <CANravCCmcn6wiKZnPc2nYkouFmjSVdD+u8x6EQGvy8qwdXDwkw@mail.gmail.com> (raw)

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

Hi all,

I believe I have found an out of bounds memory read in vfprintf.c

On line 509 in src/stdio/vfprintf.c in the current source tree head, you
can observe the following snippet of code:

/* Format specifier state machine */
st=0;
do {
if (OOB(*s)) goto inval;
ps=st;
st=states[st]S(*s++);
} while (st-1<STOP);
if (!st) goto inval;

Note that on line 99 the OOB macro expands to the following test whether
the argument falls outside of 'A' and 'z', written to use a single compare:

#define OOB(x) ((unsigned)(x)-'A' > 'z'-'A')
Unfortunately, the cast to unsigned binds tighter than the subtract
from 'A', so if x is less than 'A',
OOB will return false. This is common in the case of space, which has
an ascii value of 32

compared to 'A' 's value of 65.

This causes us to index into states with a negative value for its
second dimension, causing us to
index to an unpredictable location in states, possibly even off the beginning.
Hope this helps,
Mark Winterrowd

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

             reply	other threads:[~2018-06-28 17:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-28 17:20 Mark Winterrowd [this message]
2018-06-28 17:40 ` Rich Felker
2018-06-28 17:52   ` Mark Winterrowd

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=CANravCCmcn6wiKZnPc2nYkouFmjSVdD+u8x6EQGvy8qwdXDwkw@mail.gmail.com \
    --to=markwinterrowd4@gmail.com \
    --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).