--- parser3/src/main/untaint.C 2001/04/04 10:50:36 1.32 +++ parser3/src/main/untaint.C 2001/04/09 11:04:12 1.37 @@ -5,7 +5,7 @@ Author: Alexander Petrosyan (http://design.ru/paf) - $Id: untaint.C,v 1.32 2001/04/04 10:50:36 paf Exp $ + $Id: untaint.C,v 1.37 2001/04/09 11:04:12 paf Exp $ */ #include "pa_config_includes.h" @@ -16,6 +16,7 @@ #include "pa_exception.h" #include "pa_table.h" #include "pa_globals.h" +#include "pa_sql_connection.h" #define escape(action) \ { \ @@ -46,7 +47,7 @@ inline bool need_file_encode(unsigned ch return !strchr( #ifdef WIN32 - ":\\" + ":\\~" #endif "./", c); } @@ -56,7 +57,7 @@ inline bool need_uri_encode(unsigned cha return !strchr("_-./", c); } -inline bool need_header_encode(unsigned char c){ +inline bool need_http_header_encode(unsigned char c){ if(strchr(" , :", c)) return false; @@ -79,8 +80,9 @@ static bool typo_present(Array::Item *va /** @test optimize whitespaces for all but 'html' @todo fix theoretical \n mem overrun in TYPO replacements + @test mail-header */ -char *String::store_to(char *dest, Untaint_lang lang) const { +char *String::store_to(char *dest, Untaint_lang lang, SQL_Connection *connection) const { // $MAIN:html-typo table Table *user_typo_table=static_cast(pool().tag()); Table *typo_table=user_typo_table?user_typo_table:default_typo_table; @@ -94,7 +96,7 @@ char *String::store_to(char *dest, Untai // WARNING: // string can grow only UNTAINT_TIMES_BIGGER - switch(lang==UL_UNKNOWN?row->item.lang:lang) { + switch(lang==UL_UNSPECIFIED?row->item.lang:lang) { case UL_CLEAN: // clean piece case UL_TAINTED: @@ -120,12 +122,17 @@ char *String::store_to(char *dest, Untai encode(need_uri_encode, '%'); }); break; - case UL_HEADER: - // tainted, untaint language: header + case UL_HTTP_HEADER: + // tainted, untaint language: http-header escape(switch(*src) { - encode(need_header_encode, '%'); + encode(need_http_header_encode, '%'); }); break; + case UL_MAIL_HEADER: + // tainted, untaint language: mail-header + memcpy(dest, row->item.ptr, row->item.size); + dest+=row->item.size; + break; case UL_TABLE: // tainted, untaint language: table escape(switch(*src) { @@ -136,9 +143,12 @@ char *String::store_to(char *dest, Untai break; case UL_SQL: // tainted, untaint language: sql - // TODO: зависимость от sql сервера - memset(dest, '?', row->item.size); - dest+=row->item.size; + if(connection) + dest+=connection->quote(dest, row->item.ptr, row->item.size); + else + THROW(0, 0, + this, + "untaint in SQL language failed - no connection specified"); break; case UL_JS: escape(switch(*src) {