--- parser3/src/main/untaint.C 2024/05/26 18:36:01 1.178 +++ 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-2023 Art. Lebedev Studio (http://www.artlebedev.com) + 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.178 2024/05/26 18:36:01 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,7 +17,6 @@ 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 "../lib/cord/include/ec.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; } @@ -449,13 +466,18 @@ int cstr_to_string_body_block(String::La } break; case String::L_JS: + // quotes, < > & as \xXX: safe both inside