summaryrefslogtreecommitdiff
path: root/lib/libc/gen
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2015-07-20 01:52:29 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2015-07-20 01:52:29 +0000
commitbee76c3752d146d3468a8d930b0a1ce71c9c2016 (patch)
treecc7324236dd49675cf4629251e6e0e743b0982e5 /lib/libc/gen
parentaffc626e51642fba84c219d063ce2484370e42ef (diff)
Add VIS_DQ to escape double quotes. OK deraadt@ semarie@ reyk@
Diffstat (limited to 'lib/libc/gen')
-rw-r--r--lib/libc/gen/unvis.c3
-rw-r--r--lib/libc/gen/vis.37
-rw-r--r--lib/libc/gen/vis.c20
3 files changed, 17 insertions, 13 deletions
diff --git a/lib/libc/gen/unvis.c b/lib/libc/gen/unvis.c
index 8982ca50647..25db9ad8f4d 100644
--- a/lib/libc/gen/unvis.c
+++ b/lib/libc/gen/unvis.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: unvis.c,v 1.15 2011/03/13 22:21:32 guenther Exp $ */
+/* $OpenBSD: unvis.c,v 1.16 2015/07/20 01:52:28 millert Exp $ */
/*-
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
@@ -78,6 +78,7 @@ unvis(char *cp, char c, int *astate, int flag)
*astate = S_GROUND;
return (0);
case '\\':
+ case '"':
*cp = c;
*astate = S_GROUND;
return (UNVIS_VALID);
diff --git a/lib/libc/gen/vis.3 b/lib/libc/gen/vis.3
index 6808d398dc5..08ee3b519b5 100644
--- a/lib/libc/gen/vis.3
+++ b/lib/libc/gen/vis.3
@@ -1,4 +1,4 @@
-.\" $OpenBSD: vis.3,v 1.34 2015/02/07 08:44:49 doug Exp $
+.\" $OpenBSD: vis.3,v 1.35 2015/07/20 01:52:28 millert Exp $
.\"
.\" Copyright (c) 1989, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -27,7 +27,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd $Mdocdate: February 7 2015 $
+.Dd $Mdocdate: July 20 2015 $
.Dt VIS 3
.Os
.Sh NAME
@@ -161,6 +161,9 @@ alter this:
.Bl -tag -width VIS_WHITEX
.It Dv VIS_ALL
Encode all characters, whether visible or not.
+.It Dv VIS_DQ
+Also encode double quote characters
+.Pf ( Ql \&" ) .
.It Dv VIS_GLOB
Also encode magic characters recognized by
.Xr glob 3
diff --git a/lib/libc/gen/vis.c b/lib/libc/gen/vis.c
index 579fa81822e..799f8fd6f21 100644
--- a/lib/libc/gen/vis.c
+++ b/lib/libc/gen/vis.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vis.c,v 1.23 2014/11/17 19:48:27 millert Exp $ */
+/* $OpenBSD: vis.c,v 1.24 2015/07/20 01:52:28 millert Exp $ */
/*-
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
@@ -56,9 +56,10 @@ char *
vis(char *dst, int c, int flag, int nextc)
{
if (isvisible(c, flag)) {
- *dst++ = c;
- if (c == '\\' && (flag & VIS_NOSLASH) == 0)
+ if ((c == '"' && (flag & VIS_DQ) != 0) ||
+ (c == '\\' && (flag & VIS_NOSLASH) == 0))
*dst++ = '\\';
+ *dst++ = c;
*dst = '\0';
return (dst);
}
@@ -171,18 +172,17 @@ strnvis(char *dst, const char *src, size_t siz, int flag)
i = 0;
for (start = dst, end = start + siz - 1; (c = *src) && dst < end; ) {
if (isvisible(c, flag)) {
- i = 1;
- *dst++ = c;
- if (c == '\\' && (flag & VIS_NOSLASH) == 0) {
+ if ((c == '"' && (flag & VIS_DQ) != 0) ||
+ (c == '\\' && (flag & VIS_NOSLASH) == 0)) {
/* need space for the extra '\\' */
- if (dst < end)
- *dst++ = '\\';
- else {
- dst--;
+ if (dst + 1 >= end) {
i = 2;
break;
}
+ *dst++ = '\\';
}
+ i = 1;
+ *dst++ = c;
src++;
} else {
i = vis(tbuf, c, flag, *++src) - tbuf;