Diff for /parser3/src/main/untaint.C between versions 1.130 and 1.134.6.1

version 1.130, 2004/02/17 10:38:08 version 1.134.6.1, 2005/08/05 13:03:03
Line 1 Line 1
 /** @file  /** @file
         Parser: String class part: untaint mechanizm.          Parser: String class part: untaint mechanizm.
   
         Copyright(c) 2001-2004 ArtLebedev Group (http://www.artlebedev.com)          Copyright(c) 2001-2005 ArtLebedev Group (http://www.artlebedev.com)
         Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)          Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
 */  */
   
Line 34  extern "C" { // author forgot to do that Line 34  extern "C" { // author forgot to do that
     {  \      {  \
         bool skip=false; \          bool skip=false; \
         if(optimize) switch(c) { \          if(optimize) switch(c) { \
         case ' ': case '\r': case '\n': case '\t': \          case ' ': case '\n': case '\t': \
                 if(whitespace) \                  if(whitespace) \
                         skip=true; /*skipping subsequent*/ \                          skip=true; /*skipping subsequent*/ \
                 else \                  else \
Line 58  extern "C" { // author forgot to do that Line 58  extern "C" { // author forgot to do that
                 char c=CORD_pos_fetch(info->pos); \                  char c=CORD_pos_fetch(info->pos); \
                 action \                  action \
         }          }
 #define _default  default: CORD_ec_append(info->result, c); break  #define _default CORD_ec_append(info->result, c)
 #define encode(need_encode_func, prefix, otherwise)  \  #define encode(need_encode_func, prefix, otherwise)  \
         if(need_encode_func(c)) { \          if(need_encode_func(c)) { \
                 static const char* hex="0123456789ABCDEF"; \                  static const char* hex="0123456789ABCDEF"; \
Line 399  int cstr_to_string_body_block(char alang Line 399  int cstr_to_string_body_block(char alang
                 } else                  } else
                         ec_append(info->result, optimize, whitespace, info->pos, fragment_length);                          ec_append(info->result, optimize, whitespace, info->pos, fragment_length);
                 break;                  break;
         case String::L_TABLE:   
                 // tainted, untaint language: table  
                 escape(switch(c) {  
                         case '\t': to_char(' ');  break;  
                         case '\n': to_char(' ');  break;  
                         _default;  
                 });  
                 break;  
         case String::L_SQL:          case String::L_SQL:
                 // tainted, untaint language: sql                  // tainted, untaint language: sql
                 if(info->connection) {                  if(info->connection) {
Line 427  int cstr_to_string_body_block(char alang Line 419  int cstr_to_string_body_block(char alang
                         case '\n': to_string("\\n");  break;                          case '\n': to_string("\\n");  break;
                         case '\\': to_string("\\\\");  break;                          case '\\': to_string("\\\\");  break;
                         case '\xFF': to_string("\\\xFF");  break;                          case '\xFF': to_string("\\\xFF");  break;
                         _default;                          default: _default; break;
                 });                  });
                 break;                  break;
         case String::L_XML:          case String::L_XML:
                   // [2]    Char    ::=    #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF] 
                 escape(switch(c) {                  escape(switch(c) {
                           case '\x9': 
                           case '\xA': 
                           case '\xD': // this is usually removed on input
                                   _default; 
                                   break;
                         case '&': to_string("&amp;");  break;                          case '&': to_string("&amp;");  break;
                         case '>': to_string("&gt;");  break;                          case '>': to_string("&gt;");  break;
                         case '<': to_string("&lt;");  break;                          case '<': to_string("&lt;");  break;
                         case '"': to_string("&quot;");  break;                          case '"': to_string("&quot;");  break;
                         case '\'': to_string("&apos;");  break;                          case '\'': to_string("&apos;");  break;
                         _default;                          default: 
                                   if(((unsigned char)c)<0x20) {
                                           // fixing it, so that libxml would not result
                                           // in fatal error parsing text
                                           // though it really violates standard.
                                           // to indicate there were an error
                                           // replace bad char not to it's code, 
                                           // which we can do,
                                           // but rather to '!' to show that input were actually
                                           // invalid.
                                           // life: shows that MSIE can somehow garble form values
                                           // so that they contain these chars.
                                           to_char('!'); 
                                   } else {
                                           _default; 
                                   }
                                   break;
                 });                  });
                 break;                  break;
         case String::L_HTML:          case String::L_HTML:
Line 446  int cstr_to_string_body_block(char alang Line 460  int cstr_to_string_body_block(char alang
                         case '>': to_string("&gt;");  break;                          case '>': to_string("&gt;");  break;
                         case '<': to_string("&lt;");  break;                          case '<': to_string("&lt;");  break;
                         case '"': to_string("&quot;");  break;                          case '"': to_string("&quot;");  break;
                         _default;                          default: _default; break;
                 });                  });
                 break;                  break;
         default:          default:
Line 464  int cstr_to_string_body_block(char alang Line 478  int cstr_to_string_body_block(char alang
 String::Body String::cstr_to_string_body(Language lang,   String::Body String::cstr_to_string_body(Language lang, 
                   SQL_Connection* connection,                    SQL_Connection* connection,
                   const Request_charsets *charsets) const {                    const Request_charsets *charsets) const {
           if(is_empty())
                   return String::Body();
   
         Cstr_to_string_body_block_info info;          Cstr_to_string_body_block_info info;
         // input          // input
Line 478  String::Body String::cstr_to_string_body Line 494  String::Body String::cstr_to_string_body
         info.fragment_begin=0;          info.fragment_begin=0;
         info.whitespace=true;          info.whitespace=true;
   
         if(!is_empty())          langs.for_each(body, cstr_to_string_body_block, &info);
                 langs.for_each(body, cstr_to_string_body_block, &info);  
   
         return String::Body(CORD_ec_to_cord(info.result));          return String::Body(CORD_ec_to_cord(info.result));
 }  }

Removed from v.1.130  
changed lines
  Added in v.1.134.6.1


E-mail: