[JDEV] [patch client.c]
Rodolphe Duge de Bernonville
rod at idealx.com
Tue Feb 20 08:42:33 CST 2001
In pthsock/client.c
The jabber server may be overloaded by a user who
send big xml tag or data.
Furthermore when a user has not sent his username/password,
he can send request that are bufferized inside client.c.
This should be limited to 10 requests before being disconnected
(auth, presence, roster, filter, agents ...). This would
avoid high intensive memory and cpu (when the user send his
user/password)
usage.
Patch for the first part :
--- jabber2/jabberd/lib/lib.h Thu Feb 1 22:21:43 2001
+++ ../MODIF/jabber2/jabberd/lib/lib.h Tue Feb 20 15:10:57 2001
@@ -557,6 +557,7 @@
KARMA_HEARTBEAT seconds */
#define KARMA_PENALTY -5 /* where you go when you hit 0 karma */
#define KARMA_RESTORE 5 /* where you go when you payed your penelty or
INIT */
+#define MAXNODESIZE 8192
struct karma
{
@@ -566,6 +567,8 @@
int inc,dec; /* how much to increment/decrement */
int penalty,restore; /* what penalty (<0) or restore (>0) */
time_t last_update; /* time this was last incremented */
+ int maxnodesize;
+ int conf_maxnodesize;
};
struct karma *karma_new(pool p); /* creates a new karma object, with
default values */
--- jabber2/jabberd/mio_xml.c Thu Jan 18 08:43:40 2001
+++ ../MODIF/jabber2/jabberd/mio_xml.c Tue Feb 20 15:17:06 2001
@@ -29,6 +29,8 @@
*
--------------------------------------------------------------------------*/
#include <jabberd.h>
+extern xmlnode greymatter__;
+
/* *******************************************
* Internal Expat Callbacks
@@ -83,6 +85,8 @@
}
m->stacknode = parent;
}
+
+ m->k.maxnodesize = 0;
}
void _mio_xstream_CDATA(mio m, const char* cdata, int len)
@@ -118,8 +122,26 @@
void _mio_xml_parser(mio m, const void *buf, size_t bufsz)
{
/* init the parser if this is the first read call */
- if(m->parser == NULL)
- _mio_xstream_init(m);
+ if(m->parser == NULL){
+ xmlnode io = xmlnode_get_tag(greymatter__, "io");
+
+ m->k.maxnodesize = 0;
+ m->k.conf_maxnodesize = j_atoi(xmlnode_get_data(xmlnode_get_tag(io,
"maxnodesize")), MAXNODESIZE);
+ _mio_xstream_init(m);
+ }
+
+ if ( (m->k.maxnodesize += bufsz) > m->k.conf_maxnodesize){
+ if(m->cb != NULL)
+ {
+ (*(mio_std_cb)m->cb)(m, MIO_ERROR, m->cb_arg);
+ mio_write(m, NULL, "<stream:error>Invalid
XML</stream:error>", -1);
+ mio_close(m);
+ }
+
+ return;
+ }
+
+ fprintf(stderr, "_mio_xml_parser : m->k.maxnodesize : %d\n",
m->k.maxnodesize );
if(XML_Parse(m->parser, buf, bufsz, 0) == 0)
if(m->cb != NULL)
@@ -129,3 +151,4 @@
mio_close(m);
}
}
+
--- jabber2/pthsock/client.c Sat Feb 3 23:46:57 2001
+++ ../MODIF/jabber2/pthsock/client.c Tue Feb 20 15:32:41 2001
@@ -44,6 +44,7 @@
#include <jabberd.h>
#define DEFAULT_AUTH_TIMEOUT 0
+#define MAX_REQ_BEFORE_AUTH 10
/* socket manager instance */
typedef struct smi_st
@@ -54,6 +55,7 @@
HASHTABLE users;
xmlnode cfg;
char *host;
+ int nreqbeforeauth;
} *smi, _smi;
typedef enum { state_UNKNOWN, state_AUTHD } user_state;
@@ -303,6 +305,10 @@
q = pmalloco(xmlnode_pool(x), sizeof(_mio_wbq));
q->x = x;
pth_msgport_put(cd->pre_auth_mp, (void*)q);
+ if (pth_msgport_pending(cd->pre_auth_mp) > cd->si->nreqbeforeauth){
+ mio_write(m, NULL, "<stream:error>Too many
requests</stream:error></stream:stream>", -1);
+ mio_close(m);
+ }
return;
}
else if (NSCHECK(q, NS_AUTH))
@@ -434,6 +440,8 @@
s__i->cfg = xdb_get(xc, jid_new(xmlnode_pool(x),
"config at -internal"), "jabber:config:pth-csock");
s__i->host = host = i->id;
+ s__i->nreqbeforeauth =
j_atoi(xmlnode_get_data(xmlnode_get_tag(s__i->cfg, "nreqbeforeauth")),
MAX_REQ_BEFORE_AUTH);
+
k.val =KARMA_INIT;
k.bytes = 0;
More information about the JDev
mailing list