Commit c8f0723d authored by Hanno Böck's avatar Hanno Böck Committed by Guillem Jover

Fix heap buffer overflow in fgetwln()

In the function fgetwln() there's a 4 byte heap overflow.

There is a while loop that has this check to see whether there's still
enough space in the buffer:

		if (!fb->len || wused > fb->len) {

If this is true more memory gets allocated. However this test won't be
true if wused == fb->len, but at that point wused already points out
of the buffer. Some lines later there's a write to the buffer:

		fb->wbuf[wused++] = wc;

This bug was found with the help of address sanitizer.

Warned-by: ASAN
Fixes: Guillem Jover's avatarGuillem Jover <>
parent 008316aa
......@@ -60,7 +60,7 @@ fgetwln(FILE *stream, size_t *lenp)
fb->fp = stream;
while ((wc = fgetwc(stream)) != WEOF) {
if (!fb->len || wused > fb->len) {
if (!fb->len || wused >= fb->len) {
wchar_t *wp;
if (fb->len)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment