mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH] mbsrtowcs: Fix bug when wn is a multiple of 4
@ 2013-09-27  8:54 Michael Forney
  2013-09-27 15:28 ` Rich Felker
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Forney @ 2013-09-27  8:54 UTC (permalink / raw)
  To: musl

If wn becomes 0 after processing a chunk of 4, mbsrtowcs currently
continues on, wrapping wn around to -1, causing the rest of the string
to be processed.

This resulted in buffer overruns if there was only space in ws for wn
wide characters.
---
Hi,

I found this bug while tracking down a SIGSEGV in bash when globbing a large
pattern.

 src/multibyte/mbsrtowcs.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/multibyte/mbsrtowcs.c b/src/multibyte/mbsrtowcs.c
index b9bbc33..c5a30de 100644
--- a/src/multibyte/mbsrtowcs.c
+++ b/src/multibyte/mbsrtowcs.c
@@ -66,6 +66,7 @@ resume0:
 				*ws++ = *s++;
 				wn -= 4;
 			}
+			if (!wn) continue;
 		}
 		if (*s-1u < 0x7f) {
 			*ws++ = *s++;
-- 
1.8.4



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-09-27 22:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-27  8:54 [PATCH] mbsrtowcs: Fix bug when wn is a multiple of 4 Michael Forney
2013-09-27 15:28 ` Rich Felker
2013-09-27 15:56   ` Rich Felker
2013-09-27 22:43     ` Michael Forney

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).