Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/gen fix VIS_HTTPSTYLE to not convert "safe" ($-_.+)...



details:   https://anonhg.NetBSD.org/src/rev/2d20a1a22040
branches:  trunk
changeset: 749253:2d20a1a22040
user:      plunky <plunky%NetBSD.org@localhost>
date:      Mon Nov 23 10:08:47 2009 +0000

description:
fix VIS_HTTPSTYLE to not convert "safe" ($-_.+) and "extra" (!*'(),)
characters as mentioned in rfc1738 and rfc1808 and, I think intended
all along in this code but the logic was inverted.

Don't use strchr as it also matches the NUL character which we want
to escape, just compare against the chars directly as done in the
FreeBSD code.

diffstat:

 lib/libc/gen/vis.c |  17 ++++++++++++-----
 1 files changed, 12 insertions(+), 5 deletions(-)

diffs (42 lines):

diff -r bda6004295d1 -r 2d20a1a22040 lib/libc/gen/vis.c
--- a/lib/libc/gen/vis.c        Mon Nov 23 09:41:53 2009 +0000
+++ b/lib/libc/gen/vis.c        Mon Nov 23 10:08:47 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vis.c,v 1.40 2009/02/11 13:52:28 christos Exp $        */
+/*     $NetBSD: vis.c,v 1.41 2009/11/23 10:08:47 plunky 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.40 2009/02/11 13:52:28 christos Exp $");
+__RCSID("$NetBSD: vis.c,v 1.41 2009/11/23 10:08:47 plunky Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
@@ -120,13 +120,20 @@
 static char *
 do_hvis(char *dst, int c, int flag, int nextc, const char *extra)
 {
-       if (!isascii(c) || !isalnum(c) || strchr("$-_.+!*'(),", c) != NULL) {
+
+       if ((isascii(c) && isalnum(c))
+           /* safe */
+           || c == '$' || c == '-' || c == '_' || c == '.' || c == '+'
+           /* extra */
+           || c == '!' || c == '*' || c == '\'' || c == '(' || c == ')'
+           || c == ',') {
+               dst = do_svis(dst, c, flag, nextc, extra);
+       } else {
                *dst++ = '%';
                *dst++ = xtoa(((unsigned int)c >> 4) & 0xf);
                *dst++ = xtoa((unsigned int)c & 0xf);
-       } else {
-               dst = do_svis(dst, c, flag, nextc, extra);
        }
+
        return dst;
 }
 



Home | Main Index | Thread Index | Old Index