--- parser3/src/main/untaint.C 2017/02/07 22:00:45 1.172 +++ parser3/src/main/untaint.C 2026/11/29 13:17:21 1.184 @@ -1,11 +1,11 @@ /** @file Parser: String class part: untaint mechanizm. - Copyright (c) 2001-2017 Art. Lebedev Studio (http://www.artlebedev.com) - Author: Alexandr Petrosian (http://paf.design.ru) + Copyright (c) 2001-2026 Art. Lebedev Studio (https://www.artlebedev.com) + Authors: Konstantin Morshnev , Alexandr Petrosian */ -volatile const char * IDENT_UNTAINT_C="$Id: untaint.C,v 1.172 2017/02/07 22:00:45 moko Exp $"; +volatile const char * IDENT_UNTAINT_C="$Id: untaint.C,v 1.184 2026/11/29 13:17:21 moko Exp $"; #include "pa_string.h" @@ -17,10 +17,9 @@ volatile const char * IDENT_UNTAINT_C="$ #include "pa_common.h" #include "pa_charset.h" #include "pa_request_charsets.h" -#include "pa_sapi.h" extern "C" { // author forgot to do that -#include "ec.h" +#include "../lib/cord/include/ec.h" } #include "pa_sql_connection.h" @@ -75,13 +74,31 @@ extern "C" { // author forgot to do that #define to_string(s) { CORD_ec_append_cord(info->result, (CORD)(s)); whitespace=false; } #define _default CORD_ec_append(info->result, c) +/// \u2028 and \u2029 (line/paragraph separators) and the next ones in utf-8 as \u20XX: they end a js string, see bug #1023; +/// other bytes after 0xE2 are not taken here, so the loop escapes them as usual +#define escape_u20XX { \ + size_t index=CORD_pos_to_index(info->pos); \ + unsigned char c2; \ + if(info->charsets && info->charsets->source().isUTF8() && fragment_length>=2 \ + && (unsigned char)info->body->fetch(index+1)==0x80 \ + && (c2=(unsigned char)info->body->fetch(index+2))>=0xA8 && c2<=0xAF){ \ + to_string("\\u20"); \ + to_hex(c2-0x80); \ + CORD_next(info->pos); \ + CORD_next(info->pos); \ + fragment_length-=2; \ + } else { \ + _default; \ + } \ +} + inline bool need_file_encode(unsigned char c){ // russian letters and space ENABLED // encoding only these... return strchr( "*?\"<>|" #ifndef WIN32 - ":\\" + ":" // not allowed in windows file names; '\' is a path separator everywhere since #1300 #endif , c)!=0; } @@ -403,17 +420,17 @@ int cstr_to_string_body_block(String::La bool email=false; uchar c; - for(const char* src=mail_ptr; (c=(uchar)*src++); ) { + for(const char* src=mail_ptr; c=(uchar)*src; src++) { if(c=='\r' || c=='\n') c=' '; - if(to_quoted_printable && (c==',' || c == '"' || addr_spec_soon(src-1/*position to 'c'*/))) { + if(to_quoted_printable && (c==',' || c == '"' || addr_spec_soon(src))) { email=c=='<'; to_string("?="); to_quoted_printable=false; } //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 && (c & 0x80 || (c == ' ' && src == mail_ptr) ) ) // starting quote-printable-encoding on first 8bit char or leading space (issue #123) || ( to_quoted_printable && !mail_header_char_valid_within_Qencoded(c) ) )) { if(!to_quoted_printable) { @@ -449,13 +466,18 @@ int cstr_to_string_body_block(String::La } break; case String::L_JS: + // quotes, < > & as \xXX: safe both inside