--- parser3/src/main/untaint.C 2001/11/21 08:26:55 1.78 +++ parser3/src/main/untaint.C 2001/12/10 10:20:24 1.83 @@ -4,7 +4,7 @@ Copyright(c) 2001 ArtLebedev Group(http://www.artlebedev.com) Author: Alexander Petrosyan (http://paf.design.ru) - $Id: untaint.C,v 1.78 2001/11/21 08:26:55 paf Exp $ + $Id: untaint.C,v 1.83 2001/12/10 10:20:24 paf Exp $ */ #include "pa_pool.h" @@ -25,7 +25,6 @@ } #define _default default: *dest++=*src; break #define encode(need_encode_func, prefix) \ - default: \ if(need_encode_func(*src)) { \ static const char *hex="0123456789ABCDEF"; \ char chunk[3]={prefix}; \ @@ -41,14 +40,20 @@ dest+=bsize; \ inline bool need_file_encode(unsigned char c){ + // theoretical problem with, for instance, "_2B" and "." fragments, + // they would yield the same + // because need_file_encode('_')=false + // but we need to delete such files somehow, getting names from ^index + if((c>='0') &&(c<='9') ||(c>='A') &&(c<='Z') ||(c>='a') &&(c<='z')) return false; return !strchr( + "_./()-" #ifdef WIN32 ":\\~" #endif - "./()_-", c); + , c); } inline bool need_uri_encode(unsigned char c){ if((c>='0') &&(c<='9') ||(c>='A') &&(c<='Z') ||(c>='a') &&(c<='z')) @@ -84,8 +89,7 @@ static const char * String_Untaint_lang_ "SQL", ///< ^table:sql body "JS", ///< JavaScript code "XML", ///< ^dom:set xml - "HTML", ///< HTML code (for editing) - "UHTML", ///< HTML code with USER chars + "HTML" ///< HTML code (for editing) }; @@ -258,6 +262,7 @@ char *String::store_to(char *dest, Untai // WARNING: // before any changes check cstr_bufsize first!!! bool whitespace=true; + // expanded STRING_FOREACH_ROW here for debugging purposes const Chunk *chunk=&head; \ do { \ const Chunk::Row *row=chunk->rows; \ @@ -285,23 +290,22 @@ char *String::store_to(char *dest, Untai break; case UL_FILE_SPEC: // tainted, untaint language: file [name] - escape(switch(*src) { - case ' ': to_char('_'); break; - encode(need_file_encode, '+'); - }); + escape( + encode(need_file_encode, '_'); + ); break; case UL_URI: // tainted, untaint language: uri escape(switch(*src) { case ' ': to_char('+'); break; - encode(need_uri_encode, '%'); + default: encode(need_uri_encode, '%'); }); break; case UL_HTTP_HEADER: // tainted, untaint language: http-field-content-text escape(switch(*src) { case ' ': to_char('+'); break; - encode(need_uri_encode, '%'); + default: encode(need_uri_encode, '%'); }); break; case UL_MAIL_HEADER: @@ -377,9 +381,8 @@ char *String::store_to(char *dest, Untai default: throw Exception(0, 0, this, - "unknown untaint language #%d of %d piece", - static_cast(row->item.lang), - i); // never + "unknown untaint language #%d", + static_cast(row->item.lang)); // sould never break; // never } @@ -389,7 +392,7 @@ char *String::store_to(char *dest, Untai for(char *src=start; src"); #endif - dest+=sprintf(dest, "#%s: ", - String_Untaint_lang_name[row->item.lang]); + uchar show_lang=row->item.lang & ~UL_OPTIMIZE_BIT; + if(show_lang>=sizeof(String_Untaint_lang_name)/sizeof(String_Untaint_lang_name[0])) + throw Exception(0, 0, + this, + "unknown untaint language #%d", + static_cast(show_lang)); // sould never + + dest+=sprintf(dest, "#%s%s: ", + String_Untaint_lang_name[show_lang], + row->item.lang & UL_OPTIMIZE_BIT?".O":""); char *dest_after_origins=dest; memcpy(dest, row->item.ptr, row->item.size);