X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_httpd_stats.cpp;h=e17bf514f0835d494e57f60074bd5e30b009a55a;hb=a5d110282a864fd2e91b51ce360a977cd0643657;hp=b1613d5a526c422378662292cc28018b7291b314;hpb=44f42a13de52c8025942ddab42f51feb36821782;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_httpd_stats.cpp b/src/modules/m_httpd_stats.cpp index b1613d5a5..e17bf514f 100644 --- a/src/modules/m_httpd_stats.cpp +++ b/src/modules/m_httpd_stats.cpp @@ -34,9 +34,10 @@ class ModuleHttpStats : public Module public: - ModuleHttpStats() { + void init() + { Implementation eventlist[] = { I_OnEvent }; - ServerInstance->Modules->Attach(eventlist, this, 1); + ServerInstance->Modules->Attach(eventlist, this, sizeof(eventlist)/sizeof(Implementation)); } std::string Sanitize(const std::string &str) @@ -54,14 +55,22 @@ class ModuleHttpStats : public Module ret += it->second; ret += ';'; } - else if (*x < 32 || *x > 126) + else if (*x == 0x09 || *x == 0x0A || *x == 0x0D || ((*x >= 0x20) && (*x <= 0x7e))) { - int n = (unsigned char)*x; - ret += ("&#" + ConvToStr(n) + ";"); + // The XML specification defines the following characters as valid inside an XML document: + // Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF] + ret += *x; } else { - ret += *x; + // If we reached this point then the string contains characters which can + // not be represented in XML, even using a numeric escape. Therefore, we + // Base64 encode the entire string and wrap it in a CDATA. + ret.clear(); + ret += ""; + break; } } return ret; @@ -144,7 +153,7 @@ class ModuleHttpStats : public Module Channel* c = a->second; data << ""; - data << "" << c->GetUsers()->size() << "" << c->name << ""; + data << "" << c->GetUsers()->size() << "" << Sanitize(c->name) << ""; data << ""; data << "" << Sanitize(c->topic) << ""; data << "" << Sanitize(c->setby) << ""; @@ -204,7 +213,7 @@ class ModuleHttpStats : public Module data << ""; data << "" << b->servername << ""; data << "" << b->parentname << ""; - data << "" << b->gecos << ""; + data << "" << Sanitize(b->gecos) << ""; data << "" << b->usercount << ""; // This is currently not implemented, so, commented out. // data << "" << b->opercount << "";