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. MFC after: 1 day
This commit is contained in:
commit
ff88ef4183
@ -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
|
||||
|
@ -1,4 +1,4 @@
|
||||
.\" $NetBSD: vis.3,v 1.45 2016/06/08 15:00:04 wiz Exp $
|
||||
.\" $NetBSD: vis.3,v 1.49 2017/08/05 20:22:29 wiz Exp $
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.\" Copyright (c) 1989, 1991, 1993
|
||||
@ -30,7 +30,7 @@
|
||||
.\"
|
||||
.\" @(#)vis.3 8.1 (Berkeley) 6/9/93
|
||||
.\"
|
||||
.Dd January 14, 2015
|
||||
.Dd April 22, 2017
|
||||
.Dt VIS 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
@ -243,6 +243,8 @@ 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 ( * ,
|
||||
@ -310,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
|
||||
@ -401,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
|
||||
@ -408,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
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: vis.c,v 1.71 2016/01/14 20:41:23 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.71 2016/01/14 20:41:23 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$");
|
||||
@ -379,6 +379,7 @@ makeextralist(int flags, const char *src)
|
||||
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';
|
||||
|
||||
@ -408,6 +409,14 @@ istrsenvisx(char **mbdstp, size_t *dlen, const char *mbsrc, size_t mblength,
|
||||
_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
|
||||
@ -424,12 +433,12 @@ istrsenvisx(char **mbdstp, size_t *dlen, const char *mbsrc, size_t mblength,
|
||||
/* Allocate space for the wide char strings */
|
||||
psrc = pdst = extra = NULL;
|
||||
mdst = NULL;
|
||||
if ((psrc = calloc(mblength + 1, sizeof(*psrc))) == 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((4 * mblength) + 1, sizeof(*mdst))) == NULL)
|
||||
if ((mdst = calloc((16 * mbslength) + 1, sizeof(*mdst))) == NULL)
|
||||
goto out;
|
||||
*mbdstp = mdst;
|
||||
}
|
||||
@ -452,13 +461,6 @@ istrsenvisx(char **mbdstp, size_t *dlen, const char *mbsrc, size_t mblength,
|
||||
* 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. */
|
||||
@ -470,12 +472,13 @@ istrsenvisx(char **mbdstp, size_t *dlen, const char *mbsrc, size_t mblength,
|
||||
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. */
|
||||
@ -485,6 +488,7 @@ istrsenvisx(char **mbdstp, size_t *dlen, const char *mbsrc, size_t mblength,
|
||||
}
|
||||
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
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: vis.h,v 1.24 2016/01/14 20:42:14 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
|
||||
|
Loading…
Reference in New Issue
Block a user