Skip to content

Commit

Permalink
Custom rules: add missing check
Browse files Browse the repository at this point in the history
Fix an use-of-uninitialized-value error

```
==28646==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x55a9b7a3dea2 in ndpi_patricia_lookup /home/ivan/svnrepos/nDPI/src/lib/third_party/src/ndpi_patricia.c:739:8
    ntop#1 0x55a9b7442cac in add_to_ptree /home/ivan/svnrepos/nDPI/src/lib/ndpi_main.c:2588:10
    ntop#2 0x55a9b7469290 in ndpi_add_ip_risk_mask /home/ivan/svnrepos/nDPI/src/lib/ndpi_main.c:4161:12
    ntop#3 0x55a9b746cf14 in ndpi_handle_rule /home/ivan/svnrepos/nDPI/src/lib/ndpi_main.c:4297:11
    ntop#4 0x55a9b74842ae in ndpi_load_protocols_file_fd /home/ivan/svnrepos/nDPI/src/lib/ndpi_main.c:4944:8
    ntop#5 0x55a9b7424706 in LLVMFuzzerTestOneInput /home/ivan/svnrepos/nDPI/fuzz/fuzz_filecfg_protocols.c:38:3
[...]
```

Found by oss-fuzz
See: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=63754
  • Loading branch information
IvanNardi committed Oct 31, 2023
1 parent 5000651 commit 47edb41
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/lib/ndpi_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4151,13 +4151,15 @@ int ndpi_add_ip_risk_mask(struct ndpi_detection_module_struct *ndpi_str,
if(!is_ipv6 && ndpi_str->ip_risk_mask_ptree) {
struct in_addr pin;

pin.s_addr = inet_addr(addr);
if(inet_pton(AF_INET, addr, &pin) != 1)
return(-1);
node = add_to_ptree(ndpi_str->ip_risk_mask_ptree, AF_INET,
&pin, cidr ? atoi(cidr) : 32 /* bits */);
} else if(is_ipv6 && ndpi_str->ip_risk_mask_ptree6) {
struct in6_addr pin6;

inet_pton(AF_INET6, addr, &pin6);
if(inet_pton(AF_INET6, addr, &pin6) != 1)
return(-1);
node = add_to_ptree(ndpi_str->ip_risk_mask_ptree6, AF_INET6,
&pin6, cidr ? atoi(cidr) : 128 /* bits */);
} else {
Expand Down

0 comments on commit 47edb41

Please sign in to comment.