Various fixes for scan-build warnings

pull/807/head
Victor Julien 12 years ago
parent cd7a5ff0ca
commit 31a024c9b5

@ -85,9 +85,10 @@ static void JsonHttpLogJSON(JsonHttpLogThread *aft, json_t *js, htp_tx_t *tx)
{ {
c = SCStrndup((char *)bstr_ptr(tx->request_hostname), c = SCStrndup((char *)bstr_ptr(tx->request_hostname),
bstr_len(tx->request_hostname)); bstr_len(tx->request_hostname));
json_object_set_new(hjs, "hostname", json_string(c)); if (c != NULL) {
if (c != NULL) json_object_set_new(hjs, "hostname", json_string(c));
SCFree(c); SCFree(c);
}
} else { } else {
json_object_set_new(hjs, "hostname", json_string("<hostname unknown>")); json_object_set_new(hjs, "hostname", json_string("<hostname unknown>"));
} }
@ -97,9 +98,10 @@ static void JsonHttpLogJSON(JsonHttpLogThread *aft, json_t *js, htp_tx_t *tx)
{ {
c = SCStrndup((char *)bstr_ptr(tx->request_uri), c = SCStrndup((char *)bstr_ptr(tx->request_uri),
bstr_len(tx->request_uri)); bstr_len(tx->request_uri));
json_object_set_new(hjs, "uri", json_string(c)); if (c != NULL) {
if (c != NULL) json_object_set_new(hjs, "uri", json_string(c));
SCFree(c); SCFree(c);
}
} }
/* user agent */ /* user agent */
@ -110,9 +112,10 @@ static void JsonHttpLogJSON(JsonHttpLogThread *aft, json_t *js, htp_tx_t *tx)
if (h_user_agent != NULL) { if (h_user_agent != NULL) {
c = SCStrndup((char *)bstr_ptr(h_user_agent->value), c = SCStrndup((char *)bstr_ptr(h_user_agent->value),
bstr_len(h_user_agent->value)); bstr_len(h_user_agent->value));
json_object_set_new(hjs, "user-agent", json_string(c)); if (c != NULL) {
if (c != NULL) json_object_set_new(hjs, "user-agent", json_string(c));
SCFree(c); SCFree(c);
}
} else { } else {
json_object_set_new(hjs, "user-agent", json_string("<useragent unknown>")); json_object_set_new(hjs, "user-agent", json_string("<useragent unknown>"));
} }
@ -125,9 +128,10 @@ static void JsonHttpLogJSON(JsonHttpLogThread *aft, json_t *js, htp_tx_t *tx)
if (h_x_forwarded_for != NULL) { if (h_x_forwarded_for != NULL) {
c = SCStrndup((char *)bstr_ptr(h_x_forwarded_for->value), c = SCStrndup((char *)bstr_ptr(h_x_forwarded_for->value),
bstr_len(h_x_forwarded_for->value)); bstr_len(h_x_forwarded_for->value));
json_object_set_new(hjs, "xff", json_string(c)); if (c != NULL) {
if (c != NULL) json_object_set_new(hjs, "xff", json_string(c));
SCFree(c); SCFree(c);
}
} }
/* content-type */ /* content-type */
@ -139,14 +143,14 @@ static void JsonHttpLogJSON(JsonHttpLogThread *aft, json_t *js, htp_tx_t *tx)
char *p; char *p;
c = SCStrndup((char *)bstr_ptr(h_content_type->value), c = SCStrndup((char *)bstr_ptr(h_content_type->value),
bstr_len(h_content_type->value)); bstr_len(h_content_type->value));
p = strchrnul(c, ';'); if (c != NULL) {
*p = '\0'; p = strchrnul(c, ';');
json_object_set_new(hjs, "content-type", json_string(c)); *p = '\0';
if (c != NULL) json_object_set_new(hjs, "content-type", json_string(c));
SCFree(c); SCFree(c);
}
} }
#if 1
if (http_ctx->flags & LOG_HTTP_EXTENDED) { if (http_ctx->flags & LOG_HTTP_EXTENDED) {
/* referer */ /* referer */
htp_header_t *h_referer = NULL; htp_header_t *h_referer = NULL;
@ -156,51 +160,55 @@ static void JsonHttpLogJSON(JsonHttpLogThread *aft, json_t *js, htp_tx_t *tx)
if (h_referer != NULL) { if (h_referer != NULL) {
c = SCStrndup((char *)bstr_ptr(h_referer->value), c = SCStrndup((char *)bstr_ptr(h_referer->value),
bstr_len(h_referer->value)); bstr_len(h_referer->value));
json_object_set_new(hjs, "referer", json_string(c)); if (c != NULL) {
if (c != NULL) json_object_set_new(hjs, "referer", json_string(c));
SCFree(c); SCFree(c);
}
} }
/* method */ /* method */
if (tx->request_method != NULL) { if (tx->request_method != NULL) {
c = SCStrndup((char *)bstr_ptr(tx->request_method), c = SCStrndup((char *)bstr_ptr(tx->request_method),
bstr_len(tx->request_method)); bstr_len(tx->request_method));
json_object_set_new(hjs, "method", json_string(c)); if (c != NULL) {
if (c != NULL) json_object_set_new(hjs, "method", json_string(c));
SCFree(c); SCFree(c);
}
} }
/* protocol */ /* protocol */
if (tx->request_protocol != NULL) { if (tx->request_protocol != NULL) {
c = SCStrndup((char *)bstr_ptr(tx->request_protocol), c = SCStrndup((char *)bstr_ptr(tx->request_protocol),
bstr_len(tx->request_protocol)); bstr_len(tx->request_protocol));
json_object_set_new(hjs, "protocol", json_string(c)); if (c != NULL) {
if (c != NULL) json_object_set_new(hjs, "protocol", json_string(c));
SCFree(c); SCFree(c);
}
} }
/* response status */ /* response status */
if (tx->response_status != NULL) { if (tx->response_status != NULL) {
c = SCStrndup((char *)bstr_ptr(tx->response_status), c = SCStrndup((char *)bstr_ptr(tx->response_status),
bstr_len(tx->response_status)); bstr_len(tx->response_status));
json_object_set_new(hjs, "status", json_string(c)); if (c != NULL) {
if (c != NULL) json_object_set_new(hjs, "status", json_string(c));
SCFree(c); SCFree(c);
}
htp_header_t *h_location = htp_table_get_c(tx->response_headers, "location"); htp_header_t *h_location = htp_table_get_c(tx->response_headers, "location");
if (h_location != NULL) { if (h_location != NULL) {
c = SCStrndup((char *)bstr_ptr(h_location->value), c = SCStrndup((char *)bstr_ptr(h_location->value),
bstr_len(h_location->value)); bstr_len(h_location->value));
json_object_set_new(hjs, "redirect", json_string(c)); if (c != NULL) {
if (c != NULL) json_object_set_new(hjs, "redirect", json_string(c));
SCFree(c); SCFree(c);
}
} }
} }
/* length */ /* length */
json_object_set_new(hjs, "length", json_integer(tx->response_message_len)); json_object_set_new(hjs, "length", json_integer(tx->response_message_len));
} }
#endif
json_object_set_new(js, "http", hjs); json_object_set_new(js, "http", hjs);
} }
@ -248,12 +256,17 @@ OutputCtx *OutputHttpLogInit(ConfNode *conf)
} }
LogHttpFileCtx *http_ctx = SCMalloc(sizeof(LogHttpFileCtx)); LogHttpFileCtx *http_ctx = SCMalloc(sizeof(LogHttpFileCtx));
if (unlikely(http_ctx == NULL)) if (unlikely(http_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
return NULL; return NULL;
}
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx)); OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) if (unlikely(output_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
SCFree(http_ctx);
return NULL; return NULL;
}
http_ctx->file_ctx = file_ctx; http_ctx->file_ctx = file_ctx;
http_ctx->flags = LOG_HTTP_DEFAULT; http_ctx->flags = LOG_HTTP_DEFAULT;
@ -282,8 +295,10 @@ OutputCtx *OutputHttpLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
return NULL; return NULL;
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx)); OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) if (unlikely(output_ctx == NULL)) {
SCFree(http_ctx);
return NULL; return NULL;
}
http_ctx->file_ctx = ajt->file_ctx; http_ctx->file_ctx = ajt->file_ctx;
http_ctx->flags = LOG_HTTP_DEFAULT; http_ctx->flags = LOG_HTTP_DEFAULT;

@ -234,12 +234,17 @@ OutputCtx *OutputTlsLogInit(ConfNode *conf)
} }
OutputTlsCtx *tls_ctx = SCMalloc(sizeof(OutputTlsCtx)); OutputTlsCtx *tls_ctx = SCMalloc(sizeof(OutputTlsCtx));
if (unlikely(tls_ctx == NULL)) if (unlikely(tls_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
return NULL; return NULL;
}
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx)); OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) if (unlikely(output_ctx == NULL)) {
LogFileFreeCtx(file_ctx);
SCFree(tls_ctx);
return NULL; return NULL;
}
tls_ctx->file_ctx = file_ctx; tls_ctx->file_ctx = file_ctx;
tls_ctx->flags = LOG_TLS_DEFAULT; tls_ctx->flags = LOG_TLS_DEFAULT;
@ -274,8 +279,10 @@ OutputCtx *OutputTlsLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
return NULL; return NULL;
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx)); OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) if (unlikely(output_ctx == NULL)) {
SCFree(tls_ctx);
return NULL; return NULL;
}
tls_ctx->file_ctx = ajt->file_ctx; tls_ctx->file_ctx = ajt->file_ctx;
tls_ctx->flags = LOG_TLS_DEFAULT; tls_ctx->flags = LOG_TLS_DEFAULT;

@ -373,8 +373,11 @@ OutputCtx *OutputJsonInitCtx(ConfNode *conf)
} }
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx)); OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
if (unlikely(output_ctx == NULL)) if (unlikely(output_ctx == NULL)) {
LogFileFreeCtx(json_ctx->file_ctx);
SCFree(json_ctx);
return NULL; return NULL;
}
output_ctx->data = json_ctx; output_ctx->data = json_ctx;
output_ctx->DeInit = OutputJsonDeInitCtx; output_ctx->DeInit = OutputJsonDeInitCtx;
@ -401,6 +404,7 @@ OutputCtx *OutputJsonInitCtx(ConfNode *conf)
if (SCConfLogOpenGeneric(conf, json_ctx->file_ctx, DEFAULT_LOG_FILENAME) < 0) { if (SCConfLogOpenGeneric(conf, json_ctx->file_ctx, DEFAULT_LOG_FILENAME) < 0) {
LogFileFreeCtx(json_ctx->file_ctx); LogFileFreeCtx(json_ctx->file_ctx);
SCFree(json_ctx);
return NULL; return NULL;
} }

Loading…
Cancel
Save