Fix fr_utf8_strchar() and tests
authorAlan T. DeKok <aland@freeradius.org>
Mon, 3 Nov 2014 20:35:58 +0000 (15:35 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 3 Nov 2014 20:35:58 +0000 (15:35 -0500)
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

src/include/libradius.h
src/lib/print.c
src/tests/keywords/escape

index 8fc5232..a9cf095 100644 (file)
@@ -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);
index 5b25d76..73df92a 100644 (file)
@@ -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;
index 758f6eb..c9a9cfa 100644 (file)
@@ -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