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

Numeric truncation at tls.c:1010 #2005

Merged
merged 2 commits into from
Jun 8, 2023
Merged

Conversation

headshog
Copy link
Contributor

@headshog headshog commented Jun 5, 2023

Hi! We've been fuzzing nDPI with sydr-fuzz security predicates and numeric truncation error was found in tls.c:1010.

In ndpi_search_tls_tcp function we have found this error on line 1010. On this line value (message->buffer[3] << 8) + message->buffer[4] + 5, which has int type due to integer promotion, can be truncated. Then the variable len is used in if operator on line 1012, that can work out incorrectly. So variable type u_int16_t len should be changed to u_int32_t len.

Environment

How to reproduce this error

  1. Build docker container:

    sudo docker build -t oss-sydr-fuzz-ndpi .
    
    
  2. Run docker container:

    docker run --privileged --network host -v /etc/localtime:/etc/localtime:ro --rm -it -v $PWD:/fuzz oss-sydr-fuzz-ndpi /bin/bash
    
    
  3. Run on the following input:

    /nDPI/libfuzzer/fuzz_ndpi_reader sydr_dc37d65b367f71e74967d3478cc161b48ad86c7d_num_trunc_0
    
    
  4. Output:

    protocols/tls.c:1010:11: runtime error: implicit conversion from type 'int' of value 65540 (32-bit, signed) to type 'u_int16_t' (aka 'unsigned short') changed the value to 4 (16-bit, unsigned)
    SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior protocols/tls.c:1010:11
    

@headshog headshog changed the title Numeric truncation at `tls.c:1010' Numeric truncation at tls.c:1010 Jun 5, 2023
@sonarcloud
Copy link

sonarcloud bot commented Jun 5, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@IvanNardi
Copy link
Collaborator

Thank you

@IvanNardi IvanNardi merged commit 7dcceb4 into ntop:dev Jun 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants