svn commit: r326324 - stable/10/contrib/libc-vis

Brooks Davis brooks at FreeBSD.org
Tue Nov 28 17:20:55 UTC 2017


Author: brooks
Date: Tue Nov 28 17:20:53 2017
New Revision: 326324
URL: https://svnweb.freebsd.org/changeset/base/326324

Log:
  MFC r301679 (partial), r309626, r326307
  
  r301679:
  Update to a June 8th snapshot of (un)vis form NetBSD.
  
  This adds stravis() and some new encoding flags VIS_SHELL, VIS_META,
  and VIS_NOLOCALE.
  
  Assorted cleanups and fixes includeing a manpage typo[0].
  
  NOTE: The symbol for stravis() is not exported in this merge.
  
  r309626:
  strvis(3): Avoid internal state of multibyte functions being tainted.
  
  The mbtoc(3) and wctomb(3) functions use internal state which may be
  tainted before the call to strvis(3).  In this context we can just use
  the thread-safe versions mbrtoc(3) and wcrtomb(3) which allow passing
  our own state from our stack.
  
  r326307:
  Update vis(3) the latest from NetBSD.
  
  This adds VIS_DQ for compatiblity with OpenBSD.
  
  Correct by an off-by-one error and a read buffer overflow detected using
  asan.
  
  PR:		210013 [0]
  Submitted by:	pi [0]

Modified:
  stable/10/contrib/libc-vis/unvis.3
  stable/10/contrib/libc-vis/unvis.c
  stable/10/contrib/libc-vis/vis.3
  stable/10/contrib/libc-vis/vis.c
  stable/10/contrib/libc-vis/vis.h
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/contrib/libc-vis/unvis.3
==============================================================================
--- stable/10/contrib/libc-vis/unvis.3	Tue Nov 28 17:07:21 2017	(r326323)
+++ stable/10/contrib/libc-vis/unvis.3	Tue Nov 28 17:20:53 2017	(r326324)
@@ -1,4 +1,4 @@
-.\"	$NetBSD: unvis.3,v 1.27 2012/12/15 07:34:36 wiz Exp $
+.\"	$NetBSD: unvis.3,v 1.29 2017/10/24 19:14:55 abhinav Exp $
 .\"	$FreeBSD$
 .\"
 .\" Copyright (c) 1989, 1991, 1993
@@ -35,7 +35,10 @@
 .Os
 .Sh NAME
 .Nm unvis ,
-.Nm strunvis
+.Nm strunvis ,
+.Nm strnunvis ,
+.Nm strunvisx ,
+.Nm strnunvisx
 .Nd decode a visual representation of characters
 .Sh LIBRARY
 .Lb libc
@@ -184,7 +187,7 @@ char out;
 
 while ((ch = getchar()) != EOF) {
 again:
-	switch(unvis(\*[Am]out, ch, \*[Am]state, 0)) {
+	switch(unvis(&out, ch, &state, 0)) {
 	case 0:
 	case UNVIS_NOCHAR:
 		break;
@@ -198,7 +201,7 @@ again:
 		errx(EXIT_FAILURE, "Bad character sequence!");
 	}
 }
-if (unvis(\*[Am]out, '\e0', \*[Am]state, UNVIS_END) == UNVIS_VALID)
+if (unvis(&out, '\e0', &state, UNVIS_END) == UNVIS_VALID)
 	(void)putchar(out);
 .Ed
 .Sh ERRORS

Modified: stable/10/contrib/libc-vis/unvis.c
==============================================================================
--- stable/10/contrib/libc-vis/unvis.c	Tue Nov 28 17:07:21 2017	(r326323)
+++ stable/10/contrib/libc-vis/unvis.c	Tue Nov 28 17:20:53 2017	(r326324)
@@ -1,4 +1,4 @@
-/*	$NetBSD: unvis.c,v 1.41 2012/12/15 04:29:53 matt Exp $	*/
+/*	$NetBSD: unvis.c,v 1.44 2014/09/26 15:43:36 roy Exp $	*/
 
 /*-
  * Copyright (c) 1989, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)unvis.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: unvis.c,v 1.41 2012/12/15 04:29:53 matt Exp $");
+__RCSID("$NetBSD: unvis.c,v 1.44 2014/09/26 15:43:36 roy Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 __FBSDID("$FreeBSD$");
@@ -322,6 +322,12 @@ unvis(char *cp, int c, int *astate, int flag)
 			 */
 			*astate = SS(0, S_GROUND);
 			return UNVIS_NOCHAR;
+		default:
+			if (isgraph(c)) {
+				*cp = c;
+				*astate = SS(0, S_GROUND);
+				return UNVIS_VALID;
+			}
 		}
 		goto bad;
 

Modified: stable/10/contrib/libc-vis/vis.3
==============================================================================
--- stable/10/contrib/libc-vis/vis.3	Tue Nov 28 17:07:21 2017	(r326323)
+++ stable/10/contrib/libc-vis/vis.3	Tue Nov 28 17:20:53 2017	(r326324)
@@ -1,4 +1,4 @@
-.\"	$NetBSD: vis.3,v 1.39 2013/02/20 20:05:26 christos Exp $
+.\"	$NetBSD: vis.3,v 1.49 2017/08/05 20:22:29 wiz Exp $
 .\"	$FreeBSD$
 .\"
 .\" Copyright (c) 1989, 1991, 1993
@@ -30,13 +30,14 @@
 .\"
 .\"     @(#)vis.3	8.1 (Berkeley) 6/9/93
 .\"
-.Dd February 19, 2013
+.Dd April 22, 2017
 .Dt VIS 3
 .Os
 .Sh NAME
 .Nm vis ,
 .Nm nvis ,
 .Nm strvis ,
+.Nm stravis ,
 .Nm strnvis ,
 .Nm strvisx ,
 .Nm strnvisx ,
@@ -60,6 +61,8 @@
 .Ft int
 .Fn strvis "char *dst" "const char *src" "int flag"
 .Ft int
+.Fn stravis "char **dst" "const char *src" "int flag"
+.Ft int
 .Fn strnvis "char *dst" "size_t dlen" "const char *src" "int flag"
 .Ft int
 .Fn strvisx "char *dst" "const char *src" "size_t len" "int flag"
@@ -112,6 +115,7 @@ encoding format (explained below).
 .Pp
 The
 .Fn strvis ,
+.Fn stravis ,
 .Fn strnvis ,
 .Fn strvisx ,
 and
@@ -158,6 +162,9 @@ forms return the number of characters in
 (not including the trailing
 .Dv NUL ) .
 The
+.Fn stravis
+function allocates space dynamically to hold the string.
+The
 .Dq Nm n
 versions of the functions also take an additional argument
 .Fa dlen
@@ -236,15 +243,37 @@ except space, tab, and newline are encoded (see
 The following flags
 alter this:
 .Bl -tag -width VIS_WHITEX
+.It Dv VIS_DQ
+Also encode double quotes
 .It Dv VIS_GLOB
 Also encode the magic characters
 .Ql ( * ,
 .Ql \&? ,
-.Ql \&[
+.Ql \&[ ,
 and
 .Ql # )
 recognized by
 .Xr glob 3 .
+.It Dv VIS_SHELL
+Also encode the meta characters used by shells (in addition to the glob
+characters):
+.Ql ( ' ,
+.Ql ` ,
+.Ql \&" ,
+.Ql \&; ,
+.Ql & ,
+.Ql < ,
+.Ql > ,
+.Ql \&( ,
+.Ql \&) ,
+.Ql \&| ,
+.Ql \&] ,
+.Ql \e ,
+.Ql $ ,
+.Ql \&! ,
+.Ql \&^ ,
+and
+.Ql ~ ) .
 .It Dv VIS_SP
 Also encode space.
 .It Dv VIS_TAB
@@ -253,11 +282,10 @@ Also encode tab.
 Also encode newline.
 .It Dv VIS_WHITE
 Synonym for
-.Dv VIS_SP
-\&|
-.Dv VIS_TAB
-\&|
-.Dv VIS_NL .
+.Dv VIS_SP | VIS_TAB | VIS_NL .
+.It Dv VIS_META
+Synonym for
+.Dv VIS_WHITE | VIS_GLOB | VIS_SHELL .
 .It Dv VIS_SAFE
 Only encode
 .Dq unsafe
@@ -284,7 +312,7 @@ warning on the use of the
 .Dv VIS_NOSLASH
 flag below).
 .Pp
-There are four forms of encoding.
+There are six forms of encoding.
 All forms use the backslash character
 .Ql \e
 to introduce a special
@@ -375,6 +403,9 @@ If
 .Fa nextc
 is an octal digit, the latter representation is used to
 avoid ambiguity.
+.Pp
+Non-printable characters without C-style
+backslash sequences use the default representation.
 .It Dv VIS_OCTAL
 Use a three digit octal sequence.
 The form is
@@ -382,6 +413,11 @@ The form is
 where
 .Em d
 represents an octal digit.
+.It Dv VIS_CSTYLE \&| Dv VIS_OCTAL
+Same as
+.Dv VIS_CSTYLE
+except that non-printable characters without C-style
+backslash sequences use a three digit octal sequence.
 .It Dv VIS_HTTPSTYLE
 Use URI encoding as described in RFC 1738.
 The form is
@@ -417,6 +453,11 @@ The encoding conversion is influenced by the setting o
 environment variable which defines the set of characters
 that can be copied without encoding.
 .Pp
+If
+.Dv VIS_NOLOCALE
+is set, processing is done assuming the C locale and overriding
+any other environment settings.
+.Pp
 When 8-bit data is present in the input,
 .Ev LC_CTYPE
 must be set to the correct locale or to the C locale.
@@ -512,7 +553,7 @@ appeared in
 .Nx 6.0
 and
 .Fx 9.2 .
-Myltibyte character support was added in
+Multibyte character support was added in
 .Nx 7.0
 and
 .Fx 9.2 .

Modified: stable/10/contrib/libc-vis/vis.c
==============================================================================
--- stable/10/contrib/libc-vis/vis.c	Tue Nov 28 17:07:21 2017	(r326323)
+++ stable/10/contrib/libc-vis/vis.c	Tue Nov 28 17:20:53 2017	(r326324)
@@ -1,4 +1,4 @@
-/*	$NetBSD: vis.c,v 1.62 2014/09/08 17:35:01 christos Exp $	*/
+/*	$NetBSD: vis.c,v 1.74 2017/11/27 16:37:21 christos Exp $	*/
 
 /*-
  * Copyright (c) 1989, 1993
@@ -57,7 +57,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: vis.c,v 1.62 2014/09/08 17:35:01 christos Exp $");
+__RCSID("$NetBSD: vis.c,v 1.74 2017/11/27 16:37:21 christos Exp $");
 #endif /* LIBC_SCCS and not lint */
 #ifdef __FBSDID
 __FBSDID("$FreeBSD$");
@@ -97,15 +97,42 @@ static wchar_t *do_svis(wchar_t *, wint_t, int, wint_t
 
 #undef BELL
 #define BELL L'\a'
+ 
+#if defined(LC_C_LOCALE)
+#define iscgraph(c)      isgraph_l(c, LC_C_LOCALE)
+#else
+/* Keep it simple for now, no locale stuff */
+#define iscgraph(c)	isgraph(c)
+#ifdef notyet
+#include <locale.h>
+static int
+iscgraph(int c) {
+	int rv;
+	char *ol;
 
+	ol = setlocale(LC_CTYPE, "C");
+	rv = isgraph(c);
+	if (ol)
+		setlocale(LC_CTYPE, ol);
+	return rv;
+}
+#endif
+#endif
+
+#define ISGRAPH(flags, c) \
+    (((flags) & VIS_NOLOCALE) ? iscgraph(c) : iswgraph(c))
+
 #define iswoctal(c)	(((u_char)(c)) >= L'0' && ((u_char)(c)) <= L'7')
 #define iswwhite(c)	(c == L' ' || c == L'\t' || c == L'\n')
 #define iswsafe(c)	(c == L'\b' || c == BELL || c == L'\r')
 #define xtoa(c)		L"0123456789abcdef"[c]
 #define XTOA(c)		L"0123456789ABCDEF"[c]
 
-#define MAXEXTRAS	10
+#define MAXEXTRAS	30
 
+static const wchar_t char_shell[] = L"'`\";&<>()|{}]\\$!^~";
+static const wchar_t char_glob[] = L"*?[#";
+
 #if !HAVE_NBTOOL_CONFIG_H
 #ifndef __NetBSD__
 /*
@@ -213,8 +240,23 @@ do_mbyte(wchar_t *dst, wint_t c, int flags, wint_t nex
 				*dst++ = L'0';
 			}
 			return dst;
+		/* We cannot encode these characters in VIS_CSTYLE
+		 * because they special meaning */
+		case L'n':
+		case L'r':
+		case L'b':
+		case L'a':
+		case L'v':
+		case L't':
+		case L'f':
+		case L's':
+		case L'0':
+		case L'M':
+		case L'^':
+		case L'$': /* vis(1) -l */
+			break;
 		default:
-			if (iswgraph(c)) {
+			if (ISGRAPH(flags, c) && !iswoctal(c)) {
 				*dst++ = L'\\';
 				*dst++ = c;
 				return dst;
@@ -266,7 +308,7 @@ do_svis(wchar_t *dst, wint_t c, int flags, wint_t next
 	uint64_t bmsk, wmsk;
 
 	iswextra = wcschr(extra, c) != NULL;
-	if (!iswextra && (iswgraph(c) || iswwhite(c) ||
+	if (!iswextra && (ISGRAPH(flags, c) || iswwhite(c) ||
 	    ((flags & VIS_SAFE) && iswsafe(c)))) {
 		*dst++ = c;
 		return dst;
@@ -310,29 +352,34 @@ 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 (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] = (wint_t)(u_char)src[i];
+			dst[i] = (wchar_t)(u_char)src[i];
 		d = dst + len;
 	} else
 		d = dst + wcslen(dst);
 
-	if (flags & VIS_GLOB) {
-		*d++ = L'*';
-		*d++ = L'?';
-		*d++ = L'[';
-		*d++ = L'#';
-	}
+	if (flags & VIS_GLOB)
+		for (s = char_glob; *s; *d++ = *s++)
+			continue;
 
+	if (flags & VIS_SHELL)
+		for (s = char_shell; *s; *d++ = *s++)
+			continue;
+
 	if (flags & VIS_SP) *d++ = L' ';
 	if (flags & VIS_TAB) *d++ = L'\t';
 	if (flags & VIS_NL) *d++ = L'\n';
+	if (flags & VIS_DQ) *d++ = L'"';
 	if ((flags & VIS_NOSLASH) == 0) *d++ = L'\\';
 	*d = L'\0';
 
@@ -345,7 +392,7 @@ makeextralist(int flags, const char *src)
  *	All user-visible functions call this one.
  */
 static int
-istrsenvisx(char *mbdst, size_t *dlen, const char *mbsrc, size_t mblength,
+istrsenvisx(char **mbdstp, size_t *dlen, const char *mbsrc, size_t mblength,
     int flags, const char *mbextra, int *cerr_ptr)
 {
 	wchar_t *dst, *src, *pdst, *psrc, *start, *extra;
@@ -353,14 +400,24 @@ istrsenvisx(char *mbdst, size_t *dlen, const char *mbs
 	uint64_t bmsk, wmsk;
 	wint_t c;
 	visfun_t f;
-	int clen = 0, cerr = 0, error = -1, i, shft;
+	int clen = 0, cerr, error = -1, i, shft;
+	char *mbdst, *mdst;
 	ssize_t mbslength, maxolen;
+	mbstate_t mbstate;
 
-	_DIAGASSERT(mbdst != NULL);
+	_DIAGASSERT(mbdstp != NULL);
 	_DIAGASSERT(mbsrc != NULL || mblength == 0);
 	_DIAGASSERT(mbextra != NULL);
 
+	mbslength = (ssize_t)mblength;
 	/*
+	 * When inputing a single character, must also read in the
+	 * next character for nextc, the look-ahead character.
+	 */
+	if (mbslength == 1)
+		mbslength++;
+
+	/*
 	 * Input (mbsrc) is a char string considered to be multibyte
 	 * characters.  The input loop will read this string pulling
 	 * one character, possibly multiple bytes, from mbsrc and
@@ -375,16 +432,28 @@ istrsenvisx(char *mbdst, size_t *dlen, const char *mbs
 
 	/* Allocate space for the wide char strings */
 	psrc = pdst = extra = NULL;
-	if ((psrc = calloc(mblength + 1, sizeof(*psrc))) == NULL)
+	mdst = NULL;
+	if ((psrc = calloc(mbslength + 1, sizeof(*psrc))) == NULL)
 		return -1;
-	if ((pdst = calloc((4 * mblength) + 1, sizeof(*pdst))) == NULL)
+	if ((pdst = calloc((16 * mbslength) + 1, sizeof(*pdst))) == NULL)
 		goto out;
+	if (*mbdstp == NULL) {
+		if ((mdst = calloc((16 * mbslength) + 1, sizeof(*mdst))) == NULL)
+			goto out;
+		*mbdstp = mdst;
+	}
+
+	mbdst = *mbdstp;
 	dst = pdst;
 	src = psrc;
 
-	/* Use caller's multibyte conversion error flag. */
-	if (cerr_ptr)
-		cerr = *cerr_ptr;
+	if (flags & VIS_NOLOCALE) {
+		/* Do one byte at a time conversion */
+		cerr = 1;
+	} else {
+		/* Use caller's multibyte conversion error flag. */
+		cerr = cerr_ptr ? *cerr_ptr : 0;
+	}
 
 	/*
 	 * Input loop.
@@ -392,29 +461,24 @@ istrsenvisx(char *mbdst, size_t *dlen, const char *mbs
 	 * stop at NULs because we may be processing a block of data
 	 * that includes NULs.
 	 */
-	mbslength = (ssize_t)mblength;
-	/*
-	 * When inputing a single character, must also read in the
-	 * next character for nextc, the look-ahead character.
-	 */
-	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;
 			clen = 1;
 			cerr = 1;
 		}
-		if (clen == 0)
+		if (clen == 0) {
 			/*
 			 * NUL in input gives 0 return value. process
 			 * as single NUL byte and keep going.
 			 */
 			clen = 1;
+		}
 		/* Advance buffer character pointer. */
 		src++;
 		/* Advance input pointer by number of bytes read. */
@@ -424,6 +488,7 @@ istrsenvisx(char *mbdst, size_t *dlen, const char *mbs
 	}
 	len = src - psrc;
 	src = psrc;
+
 	/*
 	 * In the single character input case, we will have actually
 	 * processed two characters, c and nextc.  Reset len back to
@@ -439,7 +504,7 @@ istrsenvisx(char *mbdst, size_t *dlen, const char *mbs
 			errno = ENOSPC;
 			goto out;
 		}
-		*mbdst = '\0';		/* can't create extra, return "" */
+		*mbdst = '\0';	/* can't create extra, return "" */
 		error = 0;
 		goto out;
 	}
@@ -473,9 +538,10 @@ istrsenvisx(char *mbdst, size_t *dlen, const char *mbs
 	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.
@@ -511,9 +577,11 @@ istrsenvisx(char *mbdst, size_t *dlen, const char *mbs
 	/* Terminate the output string. */
 	*mbdst = '\0';
 
-	/* Pass conversion error flag out. */
-	if (cerr_ptr)
-		*cerr_ptr = cerr;
+	if (flags & VIS_NOLOCALE) {
+		/* Pass conversion error flag out. */
+		if (cerr_ptr)
+			*cerr_ptr = cerr;
+	}
 
 	free(extra);
 	free(pdst);
@@ -524,14 +592,15 @@ out:
 	free(extra);
 	free(pdst);
 	free(psrc);
+	free(mdst);
 	return error;
 }
 
 static int
-istrsenvisxl(char *mbdst, size_t *dlen, const char *mbsrc,
+istrsenvisxl(char **mbdstp, size_t *dlen, const char *mbsrc,
     int flags, const char *mbextra, int *cerr_ptr)
 {
-	return istrsenvisx(mbdst, dlen, mbsrc,
+	return istrsenvisx(mbdstp, dlen, mbsrc,
 	    mbsrc != NULL ? strlen(mbsrc) : 0, flags, mbextra, cerr_ptr);
 }
 
@@ -554,7 +623,7 @@ svis(char *mbdst, int c, int flags, int nextc, const c
 	cc[0] = c;
 	cc[1] = nextc;
 
-	ret = istrsenvisx(mbdst, NULL, cc, 1, flags, mbextra, NULL);
+	ret = istrsenvisx(&mbdst, NULL, cc, 1, flags, mbextra, NULL);
 	if (ret < 0)
 		return NULL;
 	return mbdst + ret;
@@ -569,7 +638,7 @@ snvis(char *mbdst, size_t dlen, int c, int flags, int 
 	cc[0] = c;
 	cc[1] = nextc;
 
-	ret = istrsenvisx(mbdst, &dlen, cc, 1, flags, mbextra, NULL);
+	ret = istrsenvisx(&mbdst, &dlen, cc, 1, flags, mbextra, NULL);
 	if (ret < 0)
 		return NULL;
 	return mbdst + ret;
@@ -578,33 +647,33 @@ snvis(char *mbdst, size_t dlen, int c, int flags, int 
 int
 strsvis(char *mbdst, const char *mbsrc, int flags, const char *mbextra)
 {
-	return istrsenvisxl(mbdst, NULL, mbsrc, flags, mbextra, NULL);
+	return istrsenvisxl(&mbdst, NULL, mbsrc, flags, mbextra, NULL);
 }
 
 int
 strsnvis(char *mbdst, size_t dlen, const char *mbsrc, int flags, const char *mbextra)
 {
-	return istrsenvisxl(mbdst, &dlen, mbsrc, flags, mbextra, NULL);
+	return istrsenvisxl(&mbdst, &dlen, mbsrc, flags, mbextra, NULL);
 }
 
 int
 strsvisx(char *mbdst, const char *mbsrc, size_t len, int flags, const char *mbextra)
 {
-	return istrsenvisx(mbdst, NULL, mbsrc, len, flags, mbextra, NULL);
+	return istrsenvisx(&mbdst, NULL, mbsrc, len, flags, mbextra, NULL);
 }
 
 int
 strsnvisx(char *mbdst, size_t dlen, const char *mbsrc, size_t len, int flags,
     const char *mbextra)
 {
-	return istrsenvisx(mbdst, &dlen, mbsrc, len, flags, mbextra, NULL);
+	return istrsenvisx(&mbdst, &dlen, mbsrc, len, flags, mbextra, NULL);
 }
 
 int
 strsenvisx(char *mbdst, size_t dlen, const char *mbsrc, size_t len, int flags,
     const char *mbextra, int *cerr_ptr)
 {
-	return istrsenvisx(mbdst, &dlen, mbsrc, len, flags, mbextra, cerr_ptr);
+	return istrsenvisx(&mbdst, &dlen, mbsrc, len, flags, mbextra, cerr_ptr);
 }
 #endif
 
@@ -621,7 +690,7 @@ vis(char *mbdst, int c, int flags, int nextc)
 	cc[0] = c;
 	cc[1] = nextc;
 
-	ret = istrsenvisx(mbdst, NULL, cc, 1, flags, "", NULL);
+	ret = istrsenvisx(&mbdst, NULL, cc, 1, flags, "", NULL);
 	if (ret < 0)
 		return NULL;
 	return mbdst + ret;
@@ -636,7 +705,7 @@ nvis(char *mbdst, size_t dlen, int c, int flags, int n
 	cc[0] = c;
 	cc[1] = nextc;
 
-	ret = istrsenvisx(mbdst, &dlen, cc, 1, flags, "", NULL);
+	ret = istrsenvisx(&mbdst, &dlen, cc, 1, flags, "", NULL);
 	if (ret < 0)
 		return NULL;
 	return mbdst + ret;
@@ -653,15 +722,22 @@ nvis(char *mbdst, size_t dlen, int c, int flags, int n
 int
 strvis(char *mbdst, const char *mbsrc, int flags)
 {
-	return istrsenvisxl(mbdst, NULL, mbsrc, flags, "", NULL);
+	return istrsenvisxl(&mbdst, NULL, mbsrc, flags, "", NULL);
 }
 
 int
 strnvis(char *mbdst, size_t dlen, const char *mbsrc, int flags)
 {
-	return istrsenvisxl(mbdst, &dlen, mbsrc, flags, "", NULL);
+	return istrsenvisxl(&mbdst, &dlen, mbsrc, flags, "", NULL);
 }
 
+int
+stravis(char **mbdstp, const char *mbsrc, int flags)
+{
+	*mbdstp = NULL;
+	return istrsenvisxl(mbdstp, NULL, mbsrc, flags, "", NULL);
+}
+
 /*
  * strvisx - visually encode characters from src into dst
  *
@@ -676,19 +752,19 @@ strnvis(char *mbdst, size_t dlen, const char *mbsrc, i
 int
 strvisx(char *mbdst, const char *mbsrc, size_t len, int flags)
 {
-	return istrsenvisx(mbdst, NULL, mbsrc, len, flags, "", NULL);
+	return istrsenvisx(&mbdst, NULL, mbsrc, len, flags, "", NULL);
 }
 
 int
 strnvisx(char *mbdst, size_t dlen, const char *mbsrc, size_t len, int flags)
 {
-	return istrsenvisx(mbdst, &dlen, mbsrc, len, flags, "", NULL);
+	return istrsenvisx(&mbdst, &dlen, mbsrc, len, flags, "", NULL);
 }
 
 int
 strenvisx(char *mbdst, size_t dlen, const char *mbsrc, size_t len, int flags,
     int *cerr_ptr)
 {
-	return istrsenvisx(mbdst, &dlen, mbsrc, len, flags, "", cerr_ptr);
+	return istrsenvisx(&mbdst, &dlen, mbsrc, len, flags, "", cerr_ptr);
 }
 #endif

Modified: stable/10/contrib/libc-vis/vis.h
==============================================================================
--- stable/10/contrib/libc-vis/vis.h	Tue Nov 28 17:07:21 2017	(r326323)
+++ stable/10/contrib/libc-vis/vis.h	Tue Nov 28 17:20:53 2017	(r326324)
@@ -1,4 +1,4 @@
-/*	$NetBSD: vis.h,v 1.21 2013/02/20 17:01:15 christos Exp $	*/
+/*	$NetBSD: vis.h,v 1.25 2017/04/23 01:57:36 christos Exp $	*/
 /*	$FreeBSD$	*/
 
 /*-
@@ -52,6 +52,7 @@
 #define	VIS_NL		0x0010	/* also encode newline */
 #define	VIS_WHITE	(VIS_SP | VIS_TAB | VIS_NL)
 #define	VIS_SAFE	0x0020	/* only encode "unsafe" characters */
+#define	VIS_DQ		0x8000	/* also encode double quotes */
 
 /*
  * other
@@ -64,6 +65,9 @@
 #define	VIS_HTTP1866	0x0400	/* http-style &#num; or &string; */
 #define	VIS_NOESCAPE	0x0800	/* don't decode `\' */
 #define	_VIS_END	0x1000	/* for unvis */
+#define	VIS_SHELL	0x2000	/* encode shell special characters [not glob] */
+#define	VIS_META	(VIS_WHITE | VIS_GLOB | VIS_SHELL)
+#define	VIS_NOLOCALE	0x4000	/* encode using the C locale */
 
 /*
  * unvis return codes
@@ -89,6 +93,7 @@ char	*svis(char *, int, int, int, const char *);
 char	*snvis(char *, size_t, int, int, int, const char *);
 
 int	strvis(char *, const char *, int);
+int	stravis(char **, const char *, int);
 int	strnvis(char *, size_t, const char *, int);
 
 int	strsvis(char *, const char *, int, const char *);


More information about the svn-src-stable mailing list