From 5395071c11c02d6ad22b85a0d6d0cae86a42fe95 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Tue, 1 Nov 2011 15:11:42 +0100 Subject: [PATCH] Make http logging code more robust against cases where the htp state is incomplete (out of memory conditions). --- src/app-layer-htp.c | 5 +++-- src/log-httplog.c | 16 +++++++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/app-layer-htp.c b/src/app-layer-htp.c index 29bc5a2ca3..68c40ec656 100644 --- a/src/app-layer-htp.c +++ b/src/app-layer-htp.c @@ -616,8 +616,9 @@ int HtpTransactionGetLoggableId(Flow *f) int id = 0; HtpState *http_state = f->aldata[AlpGetStateIdx(ALPROTO_HTTP)]; - if (http_state == NULL) { - SCLogDebug("no http state"); + if (http_state == NULL || http_state->connp == NULL || + http_state->connp->conn == NULL) { + SCLogDebug("no (void) http state"); goto error; } diff --git a/src/log-httplog.c b/src/log-httplog.c index 0444655794..e32a2abe36 100644 --- a/src/log-httplog.c +++ b/src/log-httplog.c @@ -118,7 +118,10 @@ static void LogHttpLogExtended(LogHttpFileCtx * hlog, htp_tx_t *tx) fprintf(hlog->file_ctx->fp, " [**] "); /* referer */ - htp_header_t *h_referer = table_getc(tx->request_headers, "referer"); + htp_header_t *h_referer = NULL; + if (tx->request_headers != NULL) { + h_referer = table_getc(tx->request_headers, "referer"); + } if (h_referer != NULL) { PrintRawUriFp(hlog->file_ctx->fp, (uint8_t *)bstr_ptr(h_referer->value), @@ -141,6 +144,8 @@ static void LogHttpLogExtended(LogHttpFileCtx * hlog, htp_tx_t *tx) PrintRawUriFp(hlog->file_ctx->fp, (uint8_t *)bstr_ptr(tx->request_protocol), bstr_len(tx->request_protocol)); + } else { + fprintf(hlog->file_ctx->fp, ""); } fprintf(hlog->file_ctx->fp, " [**] "); @@ -159,6 +164,8 @@ static void LogHttpLogExtended(LogHttpFileCtx * hlog, htp_tx_t *tx) bstr_len(h_location->value)); } } + } else { + fprintf(hlog->file_ctx->fp, ""); } /* length */ @@ -204,7 +211,7 @@ static TmEcode LogHttpLogIPWrapper(ThreadVars *tv, Packet *p, void *data, Packet goto end; } - if (htp_state->connp == NULL) + if (htp_state->connp == NULL || htp_state->connp->conn == NULL) goto end; htp_tx_t *tx = NULL; @@ -279,7 +286,10 @@ static TmEcode LogHttpLogIPWrapper(ThreadVars *tv, Packet *p, void *data, Packet fprintf(hlog->file_ctx->fp, " [**] "); /* user agent */ - htp_header_t *h_user_agent = table_getc(tx->request_headers, "user-agent"); + htp_header_t *h_user_agent = NULL; + if (tx->request_headers != NULL) { + h_user_agent = table_getc(tx->request_headers, "user-agent"); + } if (h_user_agent != NULL) { PrintRawUriFp(hlog->file_ctx->fp, (uint8_t *)bstr_ptr(h_user_agent->value),