* @param connp
*/
void htp_connp_destroy(htp_connp_t *connp) {
+ if (connp == NULL)
+ return;
+
if (connp->out_decompressor != NULL) {
connp->out_decompressor->destroy(connp->out_decompressor);
connp->out_decompressor = NULL;
// Destroy the configuration structure, but only
// if it is our private copy
- if (connp->is_cfg_private) {
- if (connp->cfg != NULL)
- htp_config_destroy(connp->cfg);
+ if ((connp->is_cfg_private) && (connp->cfg != NULL)) {
+ htp_config_destroy(connp->cfg);
}
free(connp);
* @param connp
*/
void htp_connp_destroy_all(htp_connp_t *connp) {
+ if (connp == NULL)
+ return;
+
if (connp->conn != NULL) {
// Destroy connection
htp_conn_destroy(connp->conn);
// Now extract the name and the value
h->name = bstr_memdup((char *) data + name_start, name_end - name_start);
+ if (h->name == NULL)
+ return HTP_ERROR;
h->value = bstr_memdup((char *) data + value_start, value_end - value_start);
+ if (h->value == NULL) {
+ bstr_free(h->name);
+ return HTP_ERROR;
+ }
return HTP_OK;
}
// No, we don't care if the method is empty.
tx->request_method = bstr_memdup((char *) data, pos);
+ if (tx->request_method == NULL) {
+ return HTP_ERROR;
+ }
#ifdef HTP_DEBUG
fprint_raw_data(stderr, __FUNCTION__, (unsigned char *)bstr_ptr(tx->request_method), bstr_len(tx->request_method));
// The protocol information spreads until the end of the line.
tx->request_protocol = bstr_memdup((char *) data + pos, len - pos);
+ if (tx->request_protocol == NULL)
+ return HTP_ERROR;
tx->request_protocol_number = htp_parse_protocol(tx->request_protocol);
#ifdef HTP_DEBUG
* @param path
*/
void htp_utf8_decode_path_inplace(htp_cfg_t *cfg, htp_tx_t *tx, bstr *path) {
+ if (path == NULL)
+ return;
+
uint8_t *data = (unsigned char *) bstr_ptr(path);
size_t len = bstr_len(path);
size_t rpos = 0;
if (incomplete->scheme != NULL) {
// Duplicate and convert to lowercase
normalized->scheme = bstr_dup_lower(incomplete->scheme);
+ if (normalized->scheme == NULL)
+ return HTP_ERROR;
}
// Username
if (incomplete->username != NULL) {
normalized->username = bstr_strdup(incomplete->username);
+ if (normalized->username == NULL)
+ return HTP_ERROR;
htp_uriencoding_normalize_inplace(normalized->username);
}
// Password
if (incomplete->password != NULL) {
normalized->password = bstr_strdup(incomplete->password);
+ if (normalized->password == NULL)
+ return HTP_ERROR;
htp_uriencoding_normalize_inplace(normalized->password);
}
// We know that incomplete->hostname does not contain
// port information, so no need to check for it here
normalized->hostname = bstr_strdup(incomplete->hostname);
+ if (normalized->hostname == NULL)
+ return HTP_ERROR;
htp_uriencoding_normalize_inplace(normalized->hostname);
htp_normalize_hostname_inplace(normalized->hostname);
}
// RFC normalization
htp_normalize_uri_path_inplace(normalized->path);
+ } else {
+ return HTP_ERROR;
}
}
// We cannot URL-decode the query string here; it needs to be
// parsed into individual key-value pairs first.
normalized->query = bstr_strdup(incomplete->query);
+ if (normalized->query == NULL)
+ return HTP_ERROR;
}
// Fragment
if (incomplete->fragment != NULL) {
normalized->fragment = bstr_strdup(incomplete->fragment);
+ if (normalized->fragment == NULL)
+ return HTP_ERROR;
htp_uriencoding_normalize_inplace(normalized->fragment);
}
* @return normalized hostnanme
*/
bstr *htp_normalize_hostname_inplace(bstr *hostname) {
+ if (hostname == NULL)
+ return NULL;
bstr_tolowercase(hostname);
char *data = bstr_ptr(hostname);
* @param hostname
*/
void htp_replace_hostname(htp_connp_t *connp, htp_uri_t *parsed_uri, bstr *hostname) {
+ if (hostname == NULL)
+ return;
int colon = bstr_chr(hostname, ':');
if (colon == -1) {
// Hostname alone
* @param s
*/
void htp_uriencoding_normalize_inplace(bstr *s) {
+ if (s == NULL) return;
unsigned char *data = (unsigned char *) bstr_ptr(s);
size_t len = bstr_len(s);
* @param s
*/
void htp_normalize_uri_path_inplace(bstr *s) {
+ if (s == NULL) return;
char *data = bstr_ptr(s);
size_t len = bstr_len(s);