From 606d5e477bbac8426971760815445cf832e4a92b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zden=C4=9Bk=20=C5=A0ustr?= Date: Fri, 27 May 2011 14:09:22 +0000 Subject: [PATCH] Better detection of excessively long lines in HTTP requests. --- org.glite.lb.common/src/mini_http.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/org.glite.lb.common/src/mini_http.c b/org.glite.lb.common/src/mini_http.c index e180c4c..472d578 100644 --- a/org.glite.lb.common/src/mini_http.c +++ b/org.glite.lb.common/src/mini_http.c @@ -86,14 +86,6 @@ edg_wll_ErrorCode edg_wll_http_recv(edg_wll_Context ctx,char **firstOut,char *** connPTR->bufUse += len; rdmore = 0; - if (connPTR->bufUse >= connPTR->bufSize) { - edg_wll_SetError(ctx,E2BIG,"HTTP Request too long"); - free(connPTR->buf); connPTR->buf = NULL; - connPTR->bufUse = 0; - connPTR->bufSize = 0; - goto error; - } - while (!rdmore && pstat != DONE) switch (pstat) { char *cr; @@ -105,7 +97,14 @@ edg_wll_ErrorCode edg_wll_http_recv(edg_wll_Context ctx,char **firstOut,char *** first = strdup(connPTR->buf); bshift(cr-connPTR->buf+2); pstat = HEAD; - } else rdmore = 1; + } else { + if (connPTR->bufUse >= connPTR->bufSize) { + edg_wll_SetError(ctx,E2BIG,"HTTP Request FIRST line too long"); + free(connPTR->buf); connPTR->buf = NULL; + connPTR->bufUse = 0; connPTR->bufSize = 0; + goto error; } + rdmore = 1; + } break; case HEAD: if ((cr = memchr(connPTR->buf,'\r',connPTR->bufUse)) && @@ -127,7 +126,14 @@ edg_wll_ErrorCode edg_wll_http_recv(edg_wll_Context ctx,char **firstOut,char *** clen = atoi(connPTR->buf+sizeof(CONTENT_LENGTH)-1); bshift(cr-connPTR->buf+2); - } else rdmore = 1; + } else { + if (connPTR->bufUse >= connPTR->bufSize) { + edg_wll_SetError(ctx,E2BIG,"HTTP Request HEAD line too long"); + free(connPTR->buf); connPTR->buf = NULL; + connPTR->bufUse = 0; connPTR->bufSize = 0; + goto error; } + rdmore = 1; + } break; case BODY: if (connPTR->bufUse) { @@ -207,7 +213,6 @@ edg_wll_ErrorCode edg_wll_http_recv_proxy(edg_wll_Context ctx,char **firstOut,ch while (!rdmore && pstat != DONE) switch (pstat) { char *cr; - case FIRST: if ((cr = memchr(ctx->connProxy->buf,'\r',ctx->connProxy->bufUse)) && ctx->connProxy->bufUse >= cr-ctx->connProxy->buf+2 && cr[1] == '\n') -- 1.8.2.3