This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] [BZ #17596] mblen return code when n is zero
- From: Rajalakshmi Srinivasaraghavan <raji at linux dot vnet dot ibm dot com>
- To: libc-alpha at sourceware dot org
- Cc: Rajalakshmi Srinivasaraghavan <raji at linux dot vnet dot ibm dot com>
- Date: Thu, 13 Nov 2014 09:01:48 -0600
- Subject: [PATCH] [BZ #17596] mblen return code when n is zero
- Authentication-results: sourceware.org; auth=none
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(-)
diff --git a/NEWS b/NEWS
index 918b4a1..67e7359 100644
--- a/NEWS
+++ b/NEWS
@@ -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.
diff --git a/wcsmbs/mbrtoc16.c b/wcsmbs/mbrtoc16.c
index 69105ba..2df1516 100644
--- a/wcsmbs/mbrtoc16.c
+++ b/wcsmbs/mbrtoc16.c
@@ -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);
diff --git a/wcsmbs/mbrtowc.c b/wcsmbs/mbrtowc.c
index 8070bd8..7e07cde 100644
--- a/wcsmbs/mbrtowc.c
+++ b/wcsmbs/mbrtowc.c
@@ -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);
--
1.8.3.1