Minor code cleanup
This commit is contained in:
+14
-11
@@ -291,20 +291,22 @@ static ndpi_protocol_category_t ndpi_http_check_content(struct ndpi_detection_mo
|
||||
u_int8_t filename_len = packet->content_disposition_line.len - attachment_len;
|
||||
int i;
|
||||
|
||||
if(packet->content_disposition_line.ptr[attachment_len] == '\"'){
|
||||
if(packet->content_disposition_line.ptr[packet->content_disposition_line.len-1] != '\"'){
|
||||
if(packet->content_disposition_line.ptr[attachment_len] == '\"') {
|
||||
if(packet->content_disposition_line.ptr[packet->content_disposition_line.len-1] != '\"') {
|
||||
//case: filename="file_name
|
||||
flow->http.filename = ndpi_malloc(filename_len);
|
||||
if(flow->http.filename != NULL){
|
||||
flow->http.filename = strncpy(flow->http.filename, (char*)packet->content_disposition_line.ptr+attachment_len+1, filename_len-1);
|
||||
if(flow->http.filename != NULL) {
|
||||
strncpy(flow->http.filename, (char*)packet->content_disposition_line.ptr+attachment_len+1, filename_len-1);
|
||||
flow->http.filename[filename_len-1] = '\0';
|
||||
}
|
||||
}
|
||||
else{
|
||||
//case: filename="file_name"
|
||||
flow->http.filename = ndpi_malloc(filename_len-1);
|
||||
if(flow->http.filename != NULL){
|
||||
flow->http.filename = strncpy(flow->http.filename, (char*)packet->content_disposition_line.ptr+attachment_len+1, filename_len-2);
|
||||
|
||||
if(flow->http.filename != NULL) {
|
||||
strncpy(flow->http.filename, (char*)packet->content_disposition_line.ptr+attachment_len+1,
|
||||
filename_len-2);
|
||||
flow->http.filename[filename_len-2] = '\0';
|
||||
}
|
||||
}
|
||||
@@ -312,8 +314,9 @@ static ndpi_protocol_category_t ndpi_http_check_content(struct ndpi_detection_mo
|
||||
else{
|
||||
//case: filename=file_name
|
||||
flow->http.filename = ndpi_malloc(filename_len+1);
|
||||
if(flow->http.filename != NULL){
|
||||
flow->http.filename = strncpy(flow->http.filename, (char*)packet->content_disposition_line.ptr+attachment_len, filename_len);
|
||||
|
||||
if(flow->http.filename != NULL) {
|
||||
strncpy(flow->http.filename, (char*)packet->content_disposition_line.ptr+attachment_len, filename_len);
|
||||
flow->http.filename[filename_len] = '\0';
|
||||
}
|
||||
}
|
||||
@@ -1039,14 +1042,14 @@ static const char* suspicious_http_header_keys_T[] = { "TLS_version", NULL};
|
||||
static const char* suspicious_http_header_keys_U[] = { "Uuid", NULL};
|
||||
static const char* suspicious_http_header_keys_X[] = { "X-Hire-Me", NULL};
|
||||
|
||||
static int is_a_suspicious_header(const char* suspicious_headers[], struct ndpi_int_one_line_struct packet_line){
|
||||
static int is_a_suspicious_header(const char* suspicious_headers[], struct ndpi_int_one_line_struct packet_line) {
|
||||
int i;
|
||||
unsigned int header_len;
|
||||
const u_int8_t* header_limit;
|
||||
|
||||
if((header_limit = memchr(packet_line.ptr, ':', packet_line.len))) {
|
||||
header_len = header_limit - packet_line.ptr;
|
||||
for(i=0; suspicious_headers[i] != NULL; i++){
|
||||
for(i=0; suspicious_headers[i] != NULL; i++) {
|
||||
if(!strncasecmp((const char*) packet_line.ptr,
|
||||
suspicious_headers[i], header_len))
|
||||
return 1;
|
||||
@@ -1066,7 +1069,7 @@ static void ndpi_check_http_header(struct ndpi_detection_module_struct *ndpi_str
|
||||
for(i=0; (i < packet->parsed_lines)
|
||||
&& (packet->line[i].ptr != NULL)
|
||||
&& (packet->line[i].len > 0); i++) {
|
||||
switch(packet->line[i].ptr[0]){
|
||||
switch(packet->line[i].ptr[0]) {
|
||||
case 'A':
|
||||
if(is_a_suspicious_header(suspicious_http_header_keys_A, packet->line[i])) {
|
||||
char str[64];
|
||||
|
||||
Reference in New Issue
Block a user