summaryrefslogtreecommitdiff
path: root/src/stdio/snprintf.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2020-04-17 15:31:16 -0400
committerRich Felker <dalias@aerifal.cx>2020-04-17 15:55:17 -0400
commit086542fb5bc88f590547147365630b9a44df223b (patch)
tree49c4e2cab63a4a866ab28dbb832cbc5427ee98ef /src/stdio/snprintf.c
parentb287cd745c2243f8e5114331763a5a9813b5f6ee (diff)
downloadmusl-086542fb5bc88f590547147365630b9a44df223b.tar.gz
fix possible access to uninitialized memory in shgetc (via scanf)
shgetc sets up to be able to perform an "unget" operation without the caller having to remember and pass back the character value, and for this purpose used a conditional store idiom: if (f->rpos[-1] != c) f->rpos[-1] = c to make it safe to use with non-writable buffers (setup by the sh_fromstring macro or __string_read with sscanf). however, validity of this depends on the buffer space at rpos[-1] being initialized, which is not the case under some conditions (including at least unbuffered files and fmemopen ones). whenever data was read "through the buffer", the desired character value is already in place and does not need to be written. thus, rather than testing for the absence of the value, we can test for rpos<=buf, indicating that the last character read could not have come from the buffer, and thereby that we have a "real" buffer (possibly of zero length) with writable pushback (UNGET bytes) below it.
Diffstat (limited to 'src/stdio/snprintf.c')
0 files changed, 0 insertions, 0 deletions