Minor code cleanup
This commit is contained in:
+32
-29
@@ -291,32 +291,35 @@ 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;
|
u_int8_t filename_len = packet->content_disposition_line.len - attachment_len;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if(packet->content_disposition_line.ptr[attachment_len] == '\"'){
|
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[packet->content_disposition_line.len-1] != '\"') {
|
||||||
//case: filename="file_name
|
//case: filename="file_name
|
||||||
flow->http.filename = ndpi_malloc(filename_len);
|
flow->http.filename = ndpi_malloc(filename_len);
|
||||||
if(flow->http.filename != NULL){
|
if(flow->http.filename != NULL) {
|
||||||
flow->http.filename = strncpy(flow->http.filename, (char*)packet->content_disposition_line.ptr+attachment_len+1, filename_len-1);
|
strncpy(flow->http.filename, (char*)packet->content_disposition_line.ptr+attachment_len+1, filename_len-1);
|
||||||
flow->http.filename[filename_len-1] = '\0';
|
flow->http.filename[filename_len-1] = '\0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
//case: filename="file_name"
|
//case: filename="file_name"
|
||||||
flow->http.filename = ndpi_malloc(filename_len-1);
|
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) {
|
||||||
flow->http.filename[filename_len-2] = '\0';
|
strncpy(flow->http.filename, (char*)packet->content_disposition_line.ptr+attachment_len+1,
|
||||||
}
|
filename_len-2);
|
||||||
}
|
flow->http.filename[filename_len-2] = '\0';
|
||||||
}
|
}
|
||||||
else{
|
}
|
||||||
//case: filename=file_name
|
}
|
||||||
flow->http.filename = ndpi_malloc(filename_len+1);
|
else{
|
||||||
if(flow->http.filename != NULL){
|
//case: filename=file_name
|
||||||
flow->http.filename = strncpy(flow->http.filename, (char*)packet->content_disposition_line.ptr+attachment_len, filename_len);
|
flow->http.filename = ndpi_malloc(filename_len+1);
|
||||||
flow->http.filename[filename_len] = '\0';
|
|
||||||
}
|
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';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(filename_len > ATTACHMENT_LEN) {
|
if(filename_len > ATTACHMENT_LEN) {
|
||||||
attachment_len += filename_len-ATTACHMENT_LEN-1;
|
attachment_len += filename_len-ATTACHMENT_LEN-1;
|
||||||
@@ -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_U[] = { "Uuid", NULL};
|
||||||
static const char* suspicious_http_header_keys_X[] = { "X-Hire-Me", 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;
|
int i;
|
||||||
unsigned int header_len;
|
unsigned int header_len;
|
||||||
const u_int8_t* header_limit;
|
const u_int8_t* header_limit;
|
||||||
|
|
||||||
if((header_limit = memchr(packet_line.ptr, ':', packet_line.len))) {
|
if((header_limit = memchr(packet_line.ptr, ':', packet_line.len))) {
|
||||||
header_len = header_limit - packet_line.ptr;
|
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,
|
if(!strncasecmp((const char*) packet_line.ptr,
|
||||||
suspicious_headers[i], header_len))
|
suspicious_headers[i], header_len))
|
||||||
return 1;
|
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)
|
for(i=0; (i < packet->parsed_lines)
|
||||||
&& (packet->line[i].ptr != NULL)
|
&& (packet->line[i].ptr != NULL)
|
||||||
&& (packet->line[i].len > 0); i++) {
|
&& (packet->line[i].len > 0); i++) {
|
||||||
switch(packet->line[i].ptr[0]){
|
switch(packet->line[i].ptr[0]) {
|
||||||
case 'A':
|
case 'A':
|
||||||
if(is_a_suspicious_header(suspicious_http_header_keys_A, packet->line[i])) {
|
if(is_a_suspicious_header(suspicious_http_header_keys_A, packet->line[i])) {
|
||||||
char str[64];
|
char str[64];
|
||||||
|
|||||||
Reference in New Issue
Block a user