diff options
author | Damien Miller <djm@cvs.openbsd.org> | 2010-08-24 23:49:07 +0000 |
---|---|---|
committer | Damien Miller <djm@cvs.openbsd.org> | 2010-08-24 23:49:07 +0000 |
commit | e087583e1d5fc4be76015df58e5e66aab8552843 (patch) | |
tree | a1ba733e3d946ecd529ceb35c0e3295ee1064e73 /lib/libc | |
parent | a5d341f248d1f222cade9d5ecff95f3f7b2d065b (diff) |
backout VIS_HEX. guenther@ points out that the C89 \xff encoding
idiotically accepts more then two hex digits following the \x, even
on platforms where a char has 8 bits. It is therefore dangerous to have
an almost-bit-not-quite compatible format in vis(3).
The VIS_ALL (encode all characters) option introduced in the same commit
remains.
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/gen/unvis.c | 51 | ||||
-rw-r--r-- | lib/libc/gen/vis.3 | 11 | ||||
-rw-r--r-- | lib/libc/gen/vis.c | 21 |
3 files changed, 10 insertions, 73 deletions
diff --git a/lib/libc/gen/unvis.c b/lib/libc/gen/unvis.c index 29c3d0a7913..d00d527b5aa 100644 --- a/lib/libc/gen/unvis.c +++ b/lib/libc/gen/unvis.c @@ -1,4 +1,4 @@ -/* $OpenBSD: unvis.c,v 1.13 2010/08/21 18:59:15 djm Exp $ */ +/* $OpenBSD: unvis.c,v 1.14 2010/08/24 23:49:06 djm Exp $ */ /*- * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -42,25 +42,8 @@ #define S_CTRL 4 /* control char started (^) */ #define S_OCTAL2 5 /* octal digit 2 */ #define S_OCTAL3 6 /* octal digit 3 */ -#define S_HEX1 7 /* hex digit 1 */ -#define S_HEX2 8 /* hex digit 2 */ #define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7') -#define ishex(c) ((((u_char)(c)) >= '0' && ((u_char)(c)) <= '9') || \ - (((u_char)(c)) >= 'a' && ((u_char)(c)) <= 'f') || \ - (((u_char)(c)) >= 'A' && ((u_char)(c)) <= 'F')) - -static u_int -dehex(u_int c) -{ - if (c >= '0' && c <= '9') - return c - '0'; - if (c >= 'a' && c <= 'f') - return 10 + c - 'a'; - if (c >= 'A' && c <= 'F') - return 10 + c - 'A'; - return 0; -} /* * unvis - decode characters previously encoded by vis @@ -70,8 +53,7 @@ unvis(char *cp, char c, int *astate, int flag) { if (flag & UNVIS_END) { - if (*astate == S_OCTAL2 || *astate == S_OCTAL3 || - *astate == S_HEX1 || *astate == S_HEX2) { + if (*astate == S_OCTAL2 || *astate == S_OCTAL3) { *astate = S_GROUND; return (UNVIS_VALID); } @@ -95,9 +77,6 @@ unvis(char *cp, char c, int *astate, int flag) *cp = c; *astate = S_GROUND; return (UNVIS_VALID); - case 'x': - *astate = S_HEX1; - return (0); case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': *cp = (c - '0'); @@ -212,32 +191,6 @@ unvis(char *cp, char c, int *astate, int flag) */ return (UNVIS_VALIDPUSH); - case S_HEX1: /* first possible hex digit */ - if (ishex(c)) { - /* - * yes - and maybe a second - */ - *cp = dehex(c); - *astate = S_HEX2; - return (0); - } - /* - * no - done with current sequence, push back passed char - */ - *astate = S_GROUND; - return (UNVIS_VALIDPUSH); - - case S_HEX2: /* second possible hex digit */ - *astate = S_GROUND; - if (ishex(c)) { - *cp = ((u_int)*cp << 4) + dehex(c); - return (UNVIS_VALID); - } - /* - * we were done, push back passed char - */ - return (UNVIS_VALIDPUSH); - default: /* * decoder in unknown state - (probably uninitialized) diff --git a/lib/libc/gen/vis.3 b/lib/libc/gen/vis.3 index ce63c2c49f7..c3289fed6d7 100644 --- a/lib/libc/gen/vis.3 +++ b/lib/libc/gen/vis.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: vis.3,v 1.25 2010/08/21 18:59:15 djm Exp $ +.\" $OpenBSD: vis.3,v 1.26 2010/08/24 23:49:06 djm 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: August 21 2010 $ +.Dd $Mdocdate: August 24 2010 $ .Dt VIS 3 .Os .Sh NAME @@ -280,13 +280,6 @@ If .Fa nextc is an octal digit, the latter representation is used to avoid ambiguity. -.It Dv VIS_HEX -Use a two digit hexadecimal sequence. -The form is -.Ql \exdd -where -.Ar d -represents a hexadecimal digit. .It Dv VIS_OCTAL Use a three digit octal sequence. The form is diff --git a/lib/libc/gen/vis.c b/lib/libc/gen/vis.c index 51407e6a7da..83227d96705 100644 --- a/lib/libc/gen/vis.c +++ b/lib/libc/gen/vis.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vis.c,v 1.20 2010/08/21 18:59:15 djm Exp $ */ +/* $OpenBSD: vis.c,v 1.21 2010/08/24 23:49:06 djm Exp $ */ /*- * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -46,8 +46,6 @@ (c) == '\007' || (c) == '\r' || \ isgraph((u_char)(c))))) -static const char hexdigits[] = "0123456789abcdef"; - /* * vis - visually encode characters */ @@ -106,19 +104,12 @@ vis(char *dst, int c, int flag, int nextc) goto done; } } - if (((c & 0177) == ' ') || (flag & (VIS_OCTAL|VIS_HEX)) || + if (((c & 0177) == ' ') || (flag & VIS_OCTAL) || ((flag & VIS_GLOB) && (c == '*' || c == '?' || c == '[' || c == '#'))) { - if ((flag & VIS_HEX) != 0) { - *dst++ = '\\'; - *dst++ = 'x'; - *dst++ = hexdigits[((u_char)c >> 4 & 0xf)]; - *dst++ = hexdigits[((u_char)c & 0xf)]; - } else { - *dst++ = '\\'; - *dst++ = ((u_char)c >> 6 & 07) + '0'; - *dst++ = ((u_char)c >> 3 & 07) + '0'; - *dst++ = ((u_char)c & 07) + '0'; - } + *dst++ = '\\'; + *dst++ = ((u_char)c >> 6 & 07) + '0'; + *dst++ = ((u_char)c >> 3 & 07) + '0'; + *dst++ = ((u_char)c & 07) + '0'; goto done; } if ((flag & VIS_NOSLASH) == 0) |