musl: backport various post-1.1.15 fixes
[openwrt/openwrt.git] / toolchain / musl / patches / 066-fix-swprintf-internal-buffer-state-and-error-handling.patch
1 From 7442442ccc665641a8827177e8e7ed45bbbd6584 Mon Sep 17 00:00:00 2001
2 From: Rich Felker <dalias@aerifal.cx>
3 Date: Mon, 7 Nov 2016 20:39:59 -0500
4 Subject: fix swprintf internal buffer state and error handling
5
6 the swprintf write callback never reset its buffer pointers, so after
7 its 256-byte buffer filled up, it would keep repeating those bytes
8 over and over in the output until the destination buffer filled up. it
9 also failed to set the error indicator for the stream on EILSEQ,
10 potentially allowing output to continue after the error.
11 ---
12 src/stdio/vswprintf.c | 9 ++++++++-
13 1 file changed, 8 insertions(+), 1 deletion(-)
14
15 diff --git a/src/stdio/vswprintf.c b/src/stdio/vswprintf.c
16 index 7d237ba..6eb2f6a 100644
17 --- a/src/stdio/vswprintf.c
18 +++ b/src/stdio/vswprintf.c
19 @@ -24,7 +24,14 @@ static size_t sw_write(FILE *f, const unsigned char *s, size_t l)
20 c->ws++;
21 }
22 *c->ws = 0;
23 - return i<0 ? i : l0;
24 + if (i < 0) {
25 + f->wpos = f->wbase = f->wend = 0;
26 + f->flags |= F_ERR;
27 + return i;
28 + }
29 + f->wend = f->buf + f->buf_size;
30 + f->wpos = f->wbase = f->buf;
31 + return l0;
32 }
33
34 int vswprintf(wchar_t *restrict s, size_t n, const wchar_t *restrict fmt, va_list ap)
35 --
36 cgit v0.11.2