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 diameter.c:76 #2034

Merged
merged 1 commit into from
Jul 5, 2023

Conversation

headshog
Copy link
Contributor

@headshog headshog commented Jul 5, 2023

Hi! We've been fuzzing nDPI with sydr-fuzz security predicates and we found numeric truncation error in diameter.c:76.

In function is_diameter on line 76 variable com_code has type u_int16_t. But on the right side of operator there is an integer type value, so the numeric truncation may occur. Variable com_code is used after in if operator where it is checked for equality to constant values on line 78. We found an input for fuzz-target which makes com_code variable equal to one of these constants after truncation on line 76. That means that that function returns with code 0, which is most likely incorrect. So we suggest to change the type u_int16_t of this variable to type u_int32_t.

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_alloc_fail sydr_39642e89d3e664c881362684e932beee68506e95_num_trunc_1.txt
    
    
  4. Output:

    protocols/diameter.c:76:26: runtime error: implicit conversion from type 'int' of value 65810 (32-bit, signed) to type 'u_int16_t' (aka 'unsigned short') changed the value to 274 (16-bit, unsigned)
    SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior protocols/diameter.c:76:26
    

@sonarcloud
Copy link

sonarcloud bot commented Jul 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 IvanNardi merged commit 076ba96 into ntop:dev Jul 5, 2023
33 checks passed
@IvanNardi
Copy link
Collaborator

@headshog, thanks for your fixes

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