Moved strdup for JSON/TLV strings from Flow to Parser to handle non-null-terminated strings

This commit is contained in:
Alfredo Cardigliano 2019-09-13 12:36:19 +02:00
parent 9c06fcfe93
commit b7d459dd2b
5 changed files with 41 additions and 30 deletions

View file

@ -291,8 +291,8 @@ class Flow : public GenericHashEntry {
return (isSSL() && protos.ssl.certificate) ? protos.ssl.certificate : host_server_name;
}
inline char* getBitTorrentHash() { return(bt_hash); };
inline void setBTHash(char *h) { if(!h) return; if(bt_hash) { free(bt_hash); bt_hash = NULL; }; bt_hash = strdup(h); }
inline void setServerName(char *v) { if(host_server_name) free(host_server_name); host_server_name = strdup(v); }
inline void setBTHash(char *h) { if(!h) return; if(bt_hash) free(bt_hash); bt_hash = h; }
inline void setServerName(char *v) { if(host_server_name) free(host_server_name); host_server_name = v; }
void setTcpFlags(u_int8_t flags, bool src2dst_direction);
void updateTcpFlags(const struct bpf_timeval *when,
u_int8_t flags, bool src2dst_direction);
@ -449,11 +449,11 @@ class Flow : public GenericHashEntry {
*_icmp_type = protos.icmp.icmp_type, *_icmp_code = protos.icmp.icmp_code, *_icmp_echo_id = protos.icmp.icmp_echo_id;
}
inline char* getDNSQuery() { return(isDNS() ? protos.dns.last_query : (char*)""); }
inline void setDNSQuery(char *v) { if(isDNS()) { if(protos.dns.last_query) free(protos.dns.last_query); protos.dns.last_query = strdup(v); } }
inline void setDNSQuery(char *v) { if(isDNS()) { if(protos.dns.last_query) free(protos.dns.last_query); protos.dns.last_query = v; } }
inline void setDNSQueryType(u_int16_t t) { if(isDNS()) { protos.dns.last_query_type = t; } }
inline void setDNSRetCode(u_int16_t c) { if(isDNS()) { protos.dns.last_return_code = c; } }
inline char* getHTTPURL() { return(isHTTP() ? protos.http.last_url : (char*)""); }
inline void setHTTPURL(char *v) { if(isHTTP()) { if(protos.http.last_url) free(protos.http.last_url); protos.http.last_url = strdup(v); } }
inline void setHTTPURL(char *v) { if(isHTTP()) { if(protos.http.last_url) free(protos.http.last_url); protos.http.last_url = v; } }
inline void setHTTPRetCode(u_int16_t c) { if(isHTTP()) { protos.http.last_return_code = c; } }
inline char* getHTTPContentType() { return(isHTTP() ? protos.http.last_content_type : (char*)""); }
inline char* getSSLCertificate() { return(isSSL() ? protos.ssl.certificate : (char*)""); }