[BZ,#17596] mblen return code when n is zero
Commit Message
This patch adds a check to return -1 when n is zero in mblen(),
mbrlen(),mbrtowc() and mbrtoc16().
[BZ #17596]
* wcsmbs/mbrtowc.c (__mbrtowc): Add check for n=0.
* wcsmbs/mbrtoc16.c (mbrtoc16): Likewise.
---
NEWS | 2 +-
wcsmbs/mbrtoc16.c | 2 ++
wcsmbs/mbrtowc.c | 2 ++
3 files changed, 5 insertions(+), 1 deletion(-)
Comments
Rajalakshmi Srinivasaraghavan <raji@linux.vnet.ibm.com> writes:
> This patch adds a check to return -1 when n is zero in mblen(),
> mbrlen(),mbrtowc() and mbrtoc16().
A non-existing character is valid, no? Certainly not an invalid
character sequence.
Andreas.
Andreas Schwab wrote:
> A non-existing character is valid, no?
Yes, mbrtowc should return (size_t) -2 when given an empty input buffer.
@@ -34,7 +34,7 @@ Version 2.20
16966, 16967, 16977, 16978, 16984, 16990, 16996, 17009, 17022, 17031,
17042, 17048, 17050, 17058, 17061, 17062, 17069, 17075, 17078, 17079,
17084, 17086, 17088, 17092, 17097, 17125, 17135, 17137, 17150, 17153,
- 17187, 17213, 17259, 17261, 17262, 17263, 17319, 17325, 17354.
+ 17187, 17213, 17259, 17261, 17262, 17263, 17319, 17325, 17354, 17596.
* Optimized strchrnul implementation for AArch64. Contributed by ARM Ltd.
@@ -77,6 +77,8 @@ mbrtoc16 (char16_t *pc16, const char *s, size_t n, mbstate_t *ps)
n = 1;
}
+ if (n == 0)
+ goto ilseq;
/* Tell where we want the result. */
data.__outbuf = outbuf;
data.__outbufend = outbuf + sizeof (wchar_t);
@@ -59,6 +59,8 @@ __mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
n = 1;
}
+ if (n == 0)
+ goto ilseq;
/* Tell where we want the result. */
data.__outbuf = outbuf;
data.__outbufend = outbuf + sizeof (wchar_t);