From: Alan T. DeKok Date: Mon, 3 Nov 2014 20:35:58 +0000 (-0500) Subject: Fix fr_utf8_strchar() and tests X-Git-Tag: branch_3_1_x~4784 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8aabee0041dc152cedb3deff2aea81822228ace1;p=thirdparty%2Ffreeradius-server.git Fix fr_utf8_strchar() and tests allowed characters shouldn't be escaped in the test. the function returns const it checks for fr_utf8_char() of str, not char the second time around --- diff --git a/src/include/libradius.h b/src/include/libradius.h index 8fc5232699d..a9cf09530f4 100644 --- a/src/include/libradius.h +++ b/src/include/libradius.h @@ -423,7 +423,7 @@ int fr_check_lib_magic(uint64_t magic); * Printing functions. */ int fr_utf8_char(uint8_t const *str); -char *fr_utf8_strchr(int *chr_len, const char *str, const char *chr); +char const *fr_utf8_strchr(int *chr_len, char const *str, char const *chr); size_t fr_print_string(char const *in, size_t inlen, char *out, size_t outlen, char quote); size_t fr_print_string_len(char const *in, size_t inlen, char quote); diff --git a/src/lib/print.c b/src/lib/print.c index 5b25d764e14..73df92a9032 100644 --- a/src/lib/print.c +++ b/src/lib/print.c @@ -128,25 +128,23 @@ int fr_utf8_char(uint8_t const *str) * @param[in] chr Multibyte needle. * @return The position of chr in str or NULL if not found. */ -char *fr_utf8_strchr(int *chr_len, const char *str, const char *chr) +char const *fr_utf8_strchr(int *chr_len, char const *str, char const *chr) { int cchr; - char *out; cchr = fr_utf8_char((uint8_t const *)chr); if (cchr == 0) cchr = 1; if (chr_len) *chr_len = cchr; - while (str[0]) { + while (*str) { int schr; - schr = fr_utf8_char((uint8_t const *)chr); + schr = fr_utf8_char((uint8_t const *) str); if (schr == 0) schr = 1; if (schr != cchr) goto next; if (memcmp(str, chr, schr) == 0) { - memcpy(&out, &str, sizeof(out)); - return out; + return (char const *) str; } next: str += schr; diff --git a/src/tests/keywords/escape b/src/tests/keywords/escape index 758f6ebb6a5..c9a9cfadfd2 100644 --- a/src/tests/keywords/escape +++ b/src/tests/keywords/escape @@ -7,9 +7,9 @@ update request { Tmp-String-0 := '@abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_: /' Tmp-String-1 := '±§#$%^&+={[}];<,>?`|"' - Tmp-String-2 := '™œ¥¤' + Tmp-String-2 := '™¥¤' Tmp-String-3 := '=C2=B1=C2=A7=23=24=25=5E=26=2B=3D=7B=5B=7D=5D=3B=3C=2C=3E=3F=60=7C=22' - Tmp-String-4 := '=E2=84=A2=C5=93=C2=A5=C2=A4' + Tmp-String-4 := '=E2=84=A2=C2=A5=C2=A4' Tmp-String-5 := '=40=61=62=63=64=65=66=67' # Mixture of safe and unsafe chars