Commit 3a00c237 authored by jan.koester's avatar jan.koester
Browse files

more protection against sql injections

parent ea66a0e9
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -59,7 +59,7 @@ namespace blogi {
            int ncount=0;

            if (tag) {
                sql = "select id from tags where name='"; sql << tag << "' LIMIT 1";
                sql = "select id from tags where name='"; sql.escaped(tag) << "' LIMIT 1";
                if(Args->database->exec(&sql,res)<1){
                    excep[libhttppp::HTTPException::Critical] << "no tag data found for this name!";
                    throw excep;
+20 −2
Original line number Diff line number Diff line
@@ -128,6 +128,13 @@ void blogi::StaticPage::editPage(libhttppp::HttpRequest* req, libhtmlpp::HtmlStr
        for (libhttppp::HttpForm::MultipartFormData* curformdat = form.getMultipartFormData(); curformdat; curformdat = curformdat->nextMultipartFormData()) {
            libhttppp::HttpForm::MultipartFormData::ContentDisposition* curctdisp = curformdat->getContentDisposition();{
                if(strcmp(curctdisp->getName(),"pageid")==0){
                    for(size_t i =0; i<curformdat->getDataSize(); ++i){
                        if(!isdigit(curformdat->getData()[i])){
                            libhttppp::HTTPException excep;
                            excep[libhttppp::HTTPException::Error] << "Wrong formted Pageid!";
                            throw excep;
                        }
                    }
                    id=atoi(curformdat->getData());
                }
            }
@@ -163,10 +170,21 @@ void blogi::StaticPage::editPage(libhttppp::HttpRequest* req, libhtmlpp::HtmlStr
    }catch(...){};

    if(id<0){

        for(libhttppp::HttpForm::UrlcodedFormData *cdat=form.getUrlcodedFormData(); cdat; cdat=cdat->nextUrlcodedFormData()){
            if(strcmp(cdat->getKey(),"pageid")==0)
            if(strcmp(cdat->getKey(),"pageid")==0){
                size_t pgidlen=strlen(cdat->getValue());
                for(size_t i =0; i<pgidlen; ++i){
                        if(!isdigit(cdat->getValue()[i])){
                            libhttppp::HTTPException excep;
                            excep[libhttppp::HTTPException::Error] << "Wrong formted Pageid!";
                            throw excep;
                        }
                }
                id=atoi(cdat->getValue());
            }
        }

        if(id<0){
            libhttppp::HTTPException excep;
            excep[libhttppp::HTTPException::Error] << "Staticpage with this id not found!";
@@ -221,7 +239,7 @@ bool blogi::StaticPage::Controller(netplus::con *curcon,libhttppp::HttpRequest *
        blogi::SQL sql;
        blogi::DBResult res;

        sql << "select url,text,meta from static_content where url='" << surl.c_str() << "' LIMIT 1";
        sql << "select url,text,meta from static_content where url='"; sql.escaped(surl.c_str()) << "' LIMIT 1";

        if (Args->database->exec(&sql,res)<1) {
            excep[libhttppp::HTTPException::Error] << "Staticpage with this url not found!";
+12 −0
Original line number Diff line number Diff line
@@ -60,6 +60,18 @@ blogi::SQL & blogi::SQL::operator=(const char* sql){
    return *this;
}

blogi::SQL & blogi::SQL::escaped(const char* text){
    size_t tlen=strlen(text);
    for(size_t i = 0; i < tlen; ++i){
        if(text[i]=='\''){
            _SQL.append("''");
        }else{
            _SQL.push_back(text[i]);
        }
    }
    return *this;
}


const char * blogi::SQL::c_str(){
    return _SQL.c_str();
+3 −0
Original line number Diff line number Diff line
@@ -40,6 +40,9 @@ namespace blogi {
        SQL& operator<<(const char *sql);
        SQL& operator<<(int sql);
        SQL& operator=(const char *sql);

        SQL& escaped(const char *text);

        const char *c_str();
        void clear();
        bool empty();