--- parser3/src/main/untaint.C 2001/04/23 09:38:53 1.44 +++ parser3/src/main/untaint.C 2001/06/28 07:44:17 1.53 @@ -4,11 +4,8 @@ Copyright(c) 2001 ArtLebedev Group(http://www.artlebedev.com) Author: Alexander Petrosyan (http://design.ru/paf) - - $Id: untaint.C,v 1.44 2001/04/23 09:38:53 paf Exp $ */ - -#include "pa_config_includes.h" +static const char *RCSId="$Id: untaint.C,v 1.53 2001/06/28 07:44:17 parser Exp $"; #include "pa_pool.h" #include "pa_string.h" @@ -119,9 +116,12 @@ inline bool need_quote_http_header(const return false; } -/** - @todo fix theoretical \n mem overrun in TYPO replacements -*/ +/// @todo maybe additional check "are all pieces are clean?" would be profitable? +size_t String::cstr_bufsize(Untaint_lang lang) const { + return (lang==UL_AS_IS?size():size()*UNTAINT_TIMES_BIGGER) +1; +} + +/// @todo fix theoretical \n mem overrun in TYPO replacements char *String::store_to(char *dest, Untaint_lang lang, SQL_Connection *connection, const char *charset) const { @@ -198,27 +198,26 @@ char *String::store_to(char *dest, Untai break; case UL_MAIL_HEADER: // tainted, untaint language: mail-header - { + if(charset) { // Subject: Re: parser3: =?koi8-r?Q?=D3=C5=CD=C9=CE=C1=D2?= const char *src=row->item.ptr; - bool down=false; + bool to_base_64=false; for(int size=row->item.size; size--; src++) { if(*src & 0x80) { - if(!down) { + if(!to_base_64) { dest+=sprintf(dest, "=?%.15s?Q?", charset); - down=true; + to_base_64=true; } - dest+=sprintf(dest, "=%02X", *src & 0xFF); + dest+=sprintf(dest, "=%02X", *src & 0xFF); } else { - if(down) { - down=false; - dest+=sprintf(dest, "?="); - } *dest++=*src; } } - if(down) // close unclosed + if(to_base_64) // close dest+=sprintf(dest, "?="); + } else { + memcpy(dest, row->item.ptr, row->item.size); + dest+=row->item.size; } break; case UL_TABLE: @@ -258,9 +257,10 @@ char *String::store_to(char *dest, Untai _default; }); break; - case UL_HTML_TYPO: { + case UL_USER_HTML: { // tainted, untaint language: html-typo - char *html_for_typo=(char *)malloc(size()*2/* '\n' -> '\' 'n' */+1); + char *html_for_typo= + (char *)malloc(row->item.size*2/* '\n' -> '\' 'n' */+1); // note: // there still is a possibility that user // would not replace \n as she supposed to @@ -313,9 +313,9 @@ char *String::store_to(char *dest, Untai &b, "is %g times longer then '%s', " "while maximum, handled by Parser, is %d", - ((double)b.size())/a.size(), - a.cstr(), - UNTAINT_TIMES_BIGGER); + ((double)b.size())/a.size(), + a.cstr(), + UNTAINT_TIMES_BIGGER); } // skip 'a' in 'src' @@ -334,6 +334,7 @@ char *String::store_to(char *dest, Untai "unknown untaint language #%d of %d piece", static_cast(row->item.lang), i); // never + break; // never } if((lang==UL_UNSPECIFIED?row->item.lang:lang)!=UL_CLEAN)