diff options
author | Rich Felker <dalias@aerifal.cx> | 2020-11-19 17:12:43 -0500 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2020-11-19 17:12:43 -0500 |
commit | 3ab2a4e02682df1382955071919d8aa3c3ec40d4 (patch) | |
tree | d670f11797f39d9b018ab74313ca05f7421125c2 /src/fcntl/open.c | |
parent | 233bb6972d84e9cb908ff038f78d97e487082225 (diff) | |
download | musl-3ab2a4e02682df1382955071919d8aa3c3ec40d4.tar.gz musl-3ab2a4e02682df1382955071919d8aa3c3ec40d4.tar.xz musl-3ab2a4e02682df1382955071919d8aa3c3ec40d4.zip |
rewrite wcsnrtombs to fix buffer overflow and other bugs
the original wcsnrtombs implementation, which has been largely untouched since 0.5.0, attempted to build input-length-limiting conversion on top of wcsrtombs, which only limits output length. as best I recall, this choice was made out of a mix of disdain over having yet another variant function to implement (added in POSIX 2008; not standard C) and preference not to switch things around and implement the wcsrtombs in terms of the more general new function, probably over namespace issues. the strategy employed was to impose output limits that would ensure the input limit wasn't exceeded, then finish up the tail character-at-a-time. unfortunately, none of that worked correctly. first, the logic in the wcsrtombs loop was wrong in that it could easily get stuck making no forward progress, by imposing an output limit too small to convert even one character. the character-at-a-time loop that followed was even worse. it made no effort to ensure that the converted multibyte character would fit in the remaining output space, only that there was a nonzero amount of output space remaining. it also employed an incorrect interpretation of wcrtomb's interface contract for converting the null character, thereby failing to act on end of input, and remaining space accounting was subject to unsigned wrap-around. together these errors allow unbounded overflow of the destination buffer, controlled by input length limit and input wchar_t string contents. given the extent to which this function was broken, it's plausible that most applications that would have been rendered exploitable were sufficiently broken not to be usable in the first place. however, it's also plausible that common (especially ASCII-only) inputs succeeded in the wcsrtombs loop, which mostly worked, while leaving the wildly erroneous code in the second loop exposed to particular non-ASCII inputs. CVE-2020-28928 has been assigned for this issue.
Diffstat (limited to 'src/fcntl/open.c')
0 files changed, 0 insertions, 0 deletions