svn commit: r314634 - in stable/11: contrib/libc-vis contrib/netbsd-tests/lib/libc/locale lib/libc/tests/nss
Bryan Drewery
bdrewery at FreeBSD.org
Fri Mar 3 21:43:05 UTC 2017
Author: bdrewery
Date: Fri Mar 3 21:43:03 2017
New Revision: 314634
URL: https://svnweb.freebsd.org/changeset/base/314634
Log:
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.
Modified:
stable/11/contrib/libc-vis/vis.c
stable/11/contrib/netbsd-tests/lib/libc/locale/t_mbtowc.c
stable/11/lib/libc/tests/nss/getgr_test.c
Directory Properties:
stable/11/ (props changed)
Modified: stable/11/contrib/libc-vis/vis.c
==============================================================================
--- stable/11/contrib/libc-vis/vis.c Fri Mar 3 21:41:26 2017 (r314633)
+++ stable/11/contrib/libc-vis/vis.c Fri Mar 3 21:43:03 2017 (r314634)
@@ -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,
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,
*/
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,
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.
Modified: stable/11/contrib/netbsd-tests/lib/libc/locale/t_mbtowc.c
==============================================================================
--- stable/11/contrib/netbsd-tests/lib/libc/locale/t_mbtowc.c Fri Mar 3 21:41:26 2017 (r314633)
+++ stable/11/contrib/netbsd-tests/lib/libc/locale/t_mbtowc.c Fri Mar 3 21:43:03 2017 (r314634)
@@ -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)
Modified: stable/11/lib/libc/tests/nss/getgr_test.c
==============================================================================
--- stable/11/lib/libc/tests/nss/getgr_test.c Fri Mar 3 21:41:26 2017 (r314633)
+++ stable/11/lib/libc/tests/nss/getgr_test.c Fri Mar 3 21:43:03 2017 (r314634)
@@ -176,7 +176,7 @@ sdump_group(struct group *grp, char *buf
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 *buf
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 *buf
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 *g
{
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 *g
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 *g
grp->gr_passwd = NULL;
return (-1);
}
+ /* Change to parsing groups. */
+ sep = ",";
break;
default:
More information about the svn-src-stable
mailing list