Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added feature to extract filename from http attachment #2037

Merged
merged 9 commits into from
Jul 11, 2023
21 changes: 13 additions & 8 deletions src/lib/protocols/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ static ndpi_protocol_category_t ndpi_http_check_content(struct ndpi_detection_mo
flow->guessed_category = flow->category = NDPI_PROTOCOL_CATEGORY_DOWNLOAD_FT;
ndpi_set_binary_application_transfer(ndpi_struct, flow, str);
NDPI_LOG_INFO(ndpi_struct, "Found executable HTTP transfer");
//return(flow->category);
}
}
}
Expand All @@ -296,21 +295,27 @@ static ndpi_protocol_category_t ndpi_http_check_content(struct ndpi_detection_mo
if(packet->content_disposition_line.ptr[packet->content_disposition_line.len-1] != '\"'){
//case: filename="file_name
flow->http.filename = ndpi_malloc(filename_len);
IvanNardi marked this conversation as resolved.
Show resolved Hide resolved
flow->http.filename = strncpy(flow->http.filename, (char*)packet->content_disposition_line.ptr+attachment_len+1, filename_len-1);
flow->http.filename[filename_len-1] = '\0';
if(flow->http.filename != NULL){
flow->http.filename = strncpy(flow->http.filename, (char*)packet->content_disposition_line.ptr+attachment_len+1, filename_len-1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assignment not necessary

flow->http.filename[filename_len-1] = '\0';
}
}
else{
//case: filename="file_name"
flow->http.filename = ndpi_malloc(filename_len-1);
flow->http.filename = strncpy(flow->http.filename, (char*)packet->content_disposition_line.ptr+attachment_len+1, filename_len-2);
flow->http.filename[filename_len-2] = '\0';
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assignment not necessary

flow->http.filename[filename_len-2] = '\0';
}
}
}
else{
//case: filename=file_name
flow->http.filename = ndpi_malloc(filename_len+1);
IvanNardi marked this conversation as resolved.
Show resolved Hide resolved
flow->http.filename = strncpy(flow->http.filename, (char*)packet->content_disposition_line.ptr+attachment_len, filename_len);
flow->http.filename[filename_len] = '\0';
if(flow->http.filename != NULL){
flow->http.filename = strncpy(flow->http.filename, (char*)packet->content_disposition_line.ptr+attachment_len, filename_len);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assignment not necessary

flow->http.filename[filename_len] = '\0';
}
}

if(filename_len > ATTACHMENT_LEN) {
Expand Down
Loading