Log messages, queries, etc. would let HTML characters through unfiltered.
Fixes #1038.
return 0; // never reached
}
+static string htmlescape(const string &s) {
+ string result;
+ for(string::const_iterator it=s.begin(); it!=s.end(); ++it) {
+ switch (*it) {
+ case '&':
+ result += "&";
+ break;
+ case '<':
+ result += "<";
+ break;
+ case '>':
+ result += ">";
+ break;
+ default:
+ result += *it;
+ }
+ }
+ return result;
+}
+
void printtable(ostringstream &ret, const string &ringname, const string &title, int limit=10)
{
int tot=0;
int printed=0;
int total=max(1,tot);
for(vector<pair<string,unsigned int> >::const_iterator i=ring.begin();limit && i!=ring.end();++i,--limit) {
- ret<<"<tr><td>"<<i->first<<"</td><td>"<<i->second<<"</td><td align=right>"<< StatWebServer::makePercentage(i->second*100.0/total)<<"</td>"<<endl;
+ ret<<"<tr><td>"<<htmlescape(i->first)<<"</td><td>"<<i->second<<"</td><td align=right>"<< StatWebServer::makePercentage(i->second*100.0/total)<<"</td>"<<endl;
printed+=i->second;
}
ret<<"<tr><td colspan=3></td></tr>"<<endl;