Module: kamailio
Branch: master
Commit: 48195546d7b5762be897c748bd3631f6b6a5c1d0
URL:
https://github.com/kamailio/kamailio/commit/48195546d7b5762be897c748bd3631f…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2016-08-31T15:05:51+02:00
core: tcp read - proper safety when priting log messages for read error case
- related to GH #748
---
Modified: tcp_read.c
---
Diff:
https://github.com/kamailio/kamailio/commit/48195546d7b5762be897c748bd3631f…
Patch:
https://github.com/kamailio/kamailio/commit/48195546d7b5762be897c748bd3631f…
---
diff --git a/tcp_read.c b/tcp_read.c
index 3141b67..85dd4b1 100644
--- a/tcp_read.c
+++ b/tcp_read.c
@@ -1338,7 +1338,7 @@ int tcp_read_req(struct tcp_connection* con, int* bytes_read, int*
read_flags)
* if req. is complete we might have a second unparsed
* request after it, so postpone release_with_eof
*/
- if (unlikely((con->state==S_CONN_EOF) &&
+ if (unlikely((con->state==S_CONN_EOF) &&
(! TCP_REQ_COMPLETE(req)))) {
LM_DBG("EOF\n");
resp=CONN_EOF;
@@ -1346,10 +1346,19 @@ int tcp_read_req(struct tcp_connection* con, int* bytes_read, int*
read_flags)
}
}
if (unlikely(req->error!=TCP_REQ_OK)){
- LM_ERR("bad request, state=%d, error=%d buf:\n%.*s\nparsed:\n%.*s\n",
+ if(req->buf!=NULL && req->start!=NULL && req->pos!=NULL
+ && req->pos>=req->buf && req->parsed>=req->start)
{
+ LM_ERR("bad request, state=%d, error=%d buf:\n%.*s\nparsed:\n%.*s\n",
req->state, req->error,
(int)(req->pos-req->buf), req->buf,
(int)(req->parsed-req->start), req->start);
+ } else {
+ LM_ERR("bad request, state=%d, error=%d buf:%d - %p,"
+ " parsed:%d - %p\n",
+ req->state, req->error,
+ (int)(req->pos-req->buf), req->buf,
+ (int)(req->parsed-req->start), req->start);
+ }
LM_DBG("received from: port %d\n", con->rcv.src_port);
print_ip("received from: ip", &con->rcv.src_ip, "\n");
resp=CONN_ERROR;