apache / apache/nuttx

[BUG] nat_port_select() returned value not safe

Open
#16,429 8 comments 0 reactions 0 assignees View on GitHub
Arch: arm Area: Networking OS: Other Type: Bug
Dominant language
C
Stars
4k
Forks
1.7k
Avg merge
1d 17h
Merged PRs (30d)
237

Description

### Description / Steps to reproduce the issue

Returned Value:
* External port number on success; 0 on failure
In some cases,when the return value is 0, it may indicate success.

![Image](https://github.com/user-attachments/assets/02964248-74cb-4426-a93f-a8a5b21fe393)

ipv4_nat_outbound_icmp() use icmp->id as port, but some careless applications may send ICMP request packets with icmp->id == 0, in this case, nat_port_select() will return a port number of 0, this 0 is a selected result, not a failure to find a port.

![Image](https://github.com/user-attachments/assets/544ff796-8719-4b68-9afc-dfe9ba1ce64d)

The return value of 0 is interpreted as an error here, preventing subsequent processes from proceeding.
![Image](https://github.com/user-attachments/assets/8e1288bc-0caa-470c-bd26-2a2dfc2e4734)

### On which OS does this issue occur?

[OS: Other]

### What is the version of your OS?

.

### NuttX Version

all

### Issue Architecture

[Arch: arm]

### Issue Area

[Area: Networking]

### Host information

_No response_

### Verification

- [x] I have verified before submitting the report.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.