--- parser3/src/main/untaint.C 2010/12/29 12:17:58 1.161 +++ parser3/src/main/untaint.C 2015/04/08 18:08:53 1.166 @@ -1,11 +1,11 @@ /** @file Parser: String class part: untaint mechanizm. - Copyright(c) 2001-2005 ArtLebedev Group (http://www.artlebedev.com) + Copyright (c) 2001-2012 Art. Lebedev Studio (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ -static const char * const IDENT_UNTAINT_C="$Date: 2010/12/29 12:17:58 $"; +volatile const char * IDENT_UNTAINT_C="$Id: untaint.C,v 1.166 2015/04/08 18:08:53 moko Exp $"; #include "pa_string.h" @@ -61,10 +61,9 @@ extern "C" { // author forgot to do that #define _default CORD_ec_append(info->result, c) #define encode(need_encode_func, prefix, otherwise) \ if(need_encode_func(c)) { \ - static const char* hex="0123456789ABCDEF"; \ CORD_ec_append(info->result, prefix); \ - CORD_ec_append(info->result, hex[((unsigned char)c)/0x10]); \ - CORD_ec_append(info->result, hex[((unsigned char)c)%0x10]); \ + CORD_ec_append(info->result, hex_digits[((unsigned char)c) >> 4]); \ + CORD_ec_append(info->result, hex_digits[((unsigned char)c) & 0x0F]); \ } else \ CORD_ec_append(info->result, otherwise); #define to_char(c) { CORD_ec_append(info->result, c); whitespace=false; } @@ -74,7 +73,7 @@ inline bool need_file_encode(unsigned ch // russian letters and space ENABLED // encoding only these... return strchr( - "*?'\"<>|" + "*?\"<>|" #ifndef WIN32 ":\\" #endif @@ -82,10 +81,7 @@ inline bool need_file_encode(unsigned ch } inline bool need_uri_encode(unsigned char c){ - if((c>='0') && (c<='9') || (c>='A') && (c<='Z') || (c>='a') && (c<='z')) - return false; - - return !strchr("_-./*", c); + return !(pa_isalnum(c) || strchr("_-./*", c)); } inline bool need_regex_escape(unsigned char c){ @@ -251,10 +247,7 @@ RFC and without "_", or in would mean 0x20 */ inline bool mail_header_char_valid_within_Qencoded(char c) { - return c>='A' && c<='Z' - || c>='a' && c<='Z' - || c>='0' && c<='9' - || strchr("!*+-/", c); + return (pa_isalnum((unsigned char)c) || strchr("!*+-/", c)); } inline bool addr_spec_soon(const char *src) { for(char c; (c=*src); src++) @@ -399,8 +392,8 @@ int cstr_to_string_body_block(String::La } //RFC + An 'encoded-word' MUST NOT appear in any portion of an 'addr-spec'. if(!email && ( - !to_quoted_printable && (c & 0x80) // starting quote-printable-encoding on first 8bit char - || to_quoted_printable && !mail_header_char_valid_within_Qencoded(c) + ( !to_quoted_printable && (c & 0x80) ) // starting quote-printable-encoding on first 8bit char + || ( to_quoted_printable && !mail_header_char_valid_within_Qencoded(c) ) )) { if(!to_quoted_printable) { to_string("=?"); @@ -510,7 +503,15 @@ int cstr_to_string_body_block(String::La case '\r': to_string("\\r"); break; case '\b': to_string("\\b"); break; case '\f': to_string("\\f"); break; - default : _default; break; + default: + if((unsigned char)c < 0x20){ + to_string("\\u00"); + to_char(hex_digits[((unsigned char)c) >> 4]); + to_char(hex_digits[((unsigned char)c) & 0x0F]); + } else { + _default; + } + break; }); } else { const char *fragment_str=info->body->mid(info->fragment_begin, fragment_length).cstr();