Fix two separate segv's in the http logging code.

remotes/origin/master-1.0.x
Victor Julien 16 years ago
parent e462364e68
commit d6c53b68bf

@ -93,6 +93,10 @@ TmEcode LogHttpLogIPv4(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq)
/* check if we have HTTP state or not */ /* check if we have HTTP state or not */
SCMutexLock(&p->flow->m); SCMutexLock(&p->flow->m);
uint16_t proto = AppLayerGetProtoFromPacket(p);
if (proto != ALPROTO_HTTP)
goto end;
HtpState *htp_state = (HtpState *)AppLayerGetProtoStateFromPacket(p); HtpState *htp_state = (HtpState *)AppLayerGetProtoStateFromPacket(p);
if (htp_state == NULL) { if (htp_state == NULL) {
SCLogDebug("no http state, so no request logging"); SCLogDebug("no http state, so no request logging");
@ -193,6 +197,10 @@ TmEcode LogHttpLogIPv6(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq)
/* check if we have HTTP state or not */ /* check if we have HTTP state or not */
SCMutexLock(&p->flow->m); SCMutexLock(&p->flow->m);
uint16_t proto = AppLayerGetProtoFromPacket(p);
if (proto != ALPROTO_HTTP)
goto end;
HtpState *htp_state = (HtpState *)AppLayerGetProtoStateFromPacket(p); HtpState *htp_state = (HtpState *)AppLayerGetProtoStateFromPacket(p);
if (htp_state == NULL) { if (htp_state == NULL) {
SCLogDebug("no http state, so no request logging"); SCLogDebug("no http state, so no request logging");

@ -3,31 +3,22 @@
#include "suricata-common.h" #include "suricata-common.h"
#include "util-error.h" #include "util-error.h"
#include "util-debug.h" #include "util-debug.h"
#include "htp/bstr.h"
void PrintRawUriFp(FILE *fp, uint8_t *buf, uint32_t buflen) void PrintRawUriFp(FILE *fp, uint8_t *buf, uint32_t buflen)
{ {
uint32_t u; char nbuf[2048] = "";
bstr *uri_buf;
char temp[5] = ""; char temp[5] = "";
uri_buf = bstr_alloc(buflen + 20); /* XXX any sane number ? to accommodate uint32_t u = 0;
the non-printable chars, so that we
dont need to reallocate, if there are
less non-printable chars */
if (uri_buf == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "memory allocation failed");
return;
}
for (u = 0; u < buflen; u++) { for (u = 0; u < buflen; u++) {
if (isprint(buf[u])) { if (isprint(buf[u])) {
bstr_add_mem(uri_buf, (char *)&buf[u], 1); snprintf(temp, sizeof(temp), "%c", buf[u]);
} else { } else {
snprintf(temp, sizeof(temp), "\\x%02X", buf[u]); snprintf(temp, sizeof(temp), "\\x%02X", buf[u]);
bstr_add_cstr(uri_buf, temp);
} }
strlcat(nbuf, temp, sizeof(nbuf));
} }
fprintf(fp, "%s", bstr_tocstr(uri_buf)); fprintf(fp, "%s", nbuf);
bstr_free(uri_buf);
} }
void PrintRawDataFp(FILE *fp, uint8_t *buf, uint32_t buflen) { void PrintRawDataFp(FILE *fp, uint8_t *buf, uint32_t buflen) {

Loading…
Cancel
Save