fix rejection of dns responses with pointers past 512 byte offset
[musl] / src / multibyte / mbtowc.c
index ec9e54a..c191bb0 100644 (file)
@@ -1,26 +1,20 @@
-/* 
- * This code was written by Rich Felker in 2010; no copyright is claimed.
- * This code is in the public domain. Attribution is appreciated but
- * unnecessary.
- */
-
 #include <stdlib.h>
-#include <inttypes.h>
 #include <wchar.h>
 #include <errno.h>
-
 #include "internal.h"
-#include <stdio.h>
+
 int mbtowc(wchar_t *restrict wc, const char *restrict src, size_t n)
 {
        unsigned c;
        const unsigned char *s = (const void *)src;
+       wchar_t dummy;
 
        if (!s) return 0;
        if (!n) goto ilseq;
-       if (!wc) wc = (void *)&wc;
+       if (!wc) wc = &dummy;
 
        if (*s < 0x80) return !!(*wc = *s);
+       if (MB_CUR_MAX==1) return (*wc = CODEUNIT(*s)), 1;
        if (*s-SA > SB-SA) goto ilseq;
        c = bittab[*s++-SA];