summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbdrewery <bdrewery@FreeBSD.org>2017-03-03 21:43:03 +0000
committerbdrewery <bdrewery@FreeBSD.org>2017-03-03 21:43:03 +0000
commit5c80c37a349e934e6330fe421920680822ccc17b (patch)
treed3a5240e109b4eec94a7854d456797627b38b8c8
parent8e06c99159d72efad4c4c5afe93392c9b80722d1 (diff)
downloadFreeBSD-src-5c80c37a349e934e6330fe421920680822ccc17b.zip
FreeBSD-src-5c80c37a349e934e6330fe421920680822ccc17b.tar.gz
MFC r309626,r309627,r309659:
r309626: strvis(3): Avoid internal state of multibyte functions being tainted. r309627: Remove unneeded hack fixed by r309626. r309659: Support spaces in group names.
-rw-r--r--contrib/libc-vis/vis.c11
-rw-r--r--contrib/netbsd-tests/lib/libc/locale/t_mbtowc.c6
-rw-r--r--lib/libc/tests/nss/getgr_test.c15
3 files changed, 18 insertions, 14 deletions
diff --git a/contrib/libc-vis/vis.c b/contrib/libc-vis/vis.c
index b4a5f32..aeae86c 100644
--- a/contrib/libc-vis/vis.c
+++ b/contrib/libc-vis/vis.c
@@ -353,12 +353,14 @@ makeextralist(int flags, const char *src)
wchar_t *dst, *d;
size_t len;
const wchar_t *s;
+ mbstate_t mbstate;
+ bzero(&mbstate, sizeof(mbstate));
len = strlen(src);
if ((dst = calloc(len + MAXEXTRAS, sizeof(*dst))) == NULL)
return NULL;
- if ((flags & VIS_NOLOCALE) || mbstowcs(dst, src, len) == (size_t)-1) {
+ if ((flags & VIS_NOLOCALE) || mbsrtowcs(dst, &src, len, &mbstate) == (size_t)-1) {
size_t i;
for (i = 0; i < len; i++)
dst[i] = (wchar_t)(u_char)src[i];
@@ -400,6 +402,7 @@ istrsenvisx(char **mbdstp, size_t *dlen, const char *mbsrc, size_t mblength,
int clen = 0, cerr, error = -1, i, shft;
char *mbdst, *mdst;
ssize_t mbslength, maxolen;
+ mbstate_t mbstate;
_DIAGASSERT(mbdstp != NULL);
_DIAGASSERT(mbsrc != NULL || mblength == 0);
@@ -456,10 +459,11 @@ istrsenvisx(char **mbdstp, size_t *dlen, const char *mbsrc, size_t mblength,
*/
if (mbslength == 1)
mbslength++;
+ bzero(&mbstate, sizeof(mbstate));
while (mbslength > 0) {
/* Convert one multibyte character to wchar_t. */
if (!cerr)
- clen = mbtowc(src, mbsrc, MB_LEN_MAX);
+ clen = mbrtowc(src, mbsrc, MB_LEN_MAX, &mbstate);
if (cerr || clen < 0) {
/* Conversion error, process as a byte instead. */
*src = (wint_t)(u_char)*mbsrc;
@@ -530,9 +534,10 @@ istrsenvisx(char **mbdstp, size_t *dlen, const char *mbsrc, size_t mblength,
len = wcslen(start);
maxolen = dlen ? *dlen : (wcslen(start) * MB_LEN_MAX + 1);
olen = 0;
+ bzero(&mbstate, sizeof(mbstate));
for (dst = start; len > 0; len--) {
if (!cerr)
- clen = wctomb(mbdst, *dst);
+ clen = wcrtomb(mbdst, *dst, &mbstate);
if (cerr || clen < 0) {
/*
* Conversion error, process as a byte(s) instead.
diff --git a/contrib/netbsd-tests/lib/libc/locale/t_mbtowc.c b/contrib/netbsd-tests/lib/libc/locale/t_mbtowc.c
index 7816260..2e57786 100644
--- a/contrib/netbsd-tests/lib/libc/locale/t_mbtowc.c
+++ b/contrib/netbsd-tests/lib/libc/locale/t_mbtowc.c
@@ -137,16 +137,10 @@ ATF_TC_BODY(mbtowc, tc)
h_mbtowc("ja_JP.ISO2022-JP", "\033$B", "\033$B$\"\033(B");
h_mbtowc("ja_JP.SJIS", "\202", "\202\240");
h_mbtowc("ja_JP.eucJP", "\244", "\244\242");
-#ifndef __FreeBSD__
/* Moved last as it fails */
h_mbtowc("zh_CN.GB18030", "\241", "\241\241");
-#endif
h_mbtowc("zh_TW.Big5", "\241", "\241@");
h_mbtowc("zh_TW.eucTW", "\241", "\241\241");
-#ifdef __FreeBSD__
- atf_tc_expect_fail("zh_CN.GB18030");
- h_mbtowc("zh_CN.GB18030", "\241", "\241\241");
-#endif
}
ATF_TP_ADD_TCS(tp)
diff --git a/lib/libc/tests/nss/getgr_test.c b/lib/libc/tests/nss/getgr_test.c
index d9851ef..81c1cd0 100644
--- a/lib/libc/tests/nss/getgr_test.c
+++ b/lib/libc/tests/nss/getgr_test.c
@@ -176,7 +176,7 @@ sdump_group(struct group *grp, char *buffer, size_t buflen)
char **cp;
int written;
- written = snprintf(buffer, buflen, "%s %s %d",
+ written = snprintf(buffer, buflen, "%s:%s:%d:",
grp->gr_name, grp->gr_passwd, grp->gr_gid);
buffer += written;
if (written > buflen)
@@ -186,7 +186,8 @@ sdump_group(struct group *grp, char *buffer, size_t buflen)
if (grp->gr_mem != NULL) {
if (*(grp->gr_mem) != '\0') {
for (cp = grp->gr_mem; *cp; ++cp) {
- written = snprintf(buffer, buflen, " %s",*cp);
+ written = snprintf(buffer, buflen, "%s%s",
+ cp == grp->gr_mem ? "" : ",", *cp);
buffer += written;
if (written > buflen)
return;
@@ -196,9 +197,9 @@ sdump_group(struct group *grp, char *buffer, size_t buflen)
return;
}
} else
- snprintf(buffer, buflen, " nomem");
+ snprintf(buffer, buflen, "nomem");
} else
- snprintf(buffer, buflen, " (null)");
+ snprintf(buffer, buflen, "(null)");
}
static int
@@ -206,6 +207,7 @@ group_read_snapshot_func(struct group *grp, char *line)
{
StringList *sl;
char *s, *ps, *ts;
+ const char *sep;
int i;
printf("1 line read from snapshot:\n%s\n", line);
@@ -213,8 +215,9 @@ group_read_snapshot_func(struct group *grp, char *line)
i = 0;
sl = NULL;
ps = line;
+ sep = ":";
memset(grp, 0, sizeof(struct group));
- while ((s = strsep(&ps, " ")) != NULL) {
+ while ((s = strsep(&ps, sep)) != NULL) {
switch (i) {
case 0:
grp->gr_name = strdup(s);
@@ -235,6 +238,8 @@ group_read_snapshot_func(struct group *grp, char *line)
grp->gr_passwd = NULL;
return (-1);
}
+ /* Change to parsing groups. */
+ sep = ",";
break;
default:
OpenPOWER on IntegriCloud