Skip to content

Assertion failure with IP protocol scan #2896

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

Closed
Eponymous-One opened this issue Jul 22, 2024 · 3 comments
Closed

Assertion failure with IP protocol scan #2896

Eponymous-One opened this issue Jul 22, 2024 · 3 comments
Assignees

Comments

@Eponymous-One
Copy link

Eponymous-One commented Jul 22, 2024

Describe the bug
Running an IP protocol scan on protocol number 255 (reserved) immediately causes an assertion failure. This has been tested on Nmap 7.94SVN on Ubuntu 24.04. This is very quick and easy to reproduce.

Error message:

nmap: protocols.cc:193: const nprotoent* nmap_getprotbynum(int): Assertion `num >= 0 && num < UCHAR_MAX' failed.
Aborted (core dumped)

To Reproduce
nmap -vvv -sO <ipaddr> -Pn -p255

Expected behavior
Nmap should "scan" and then return a formatted table.

Version info (please complete the following information):

As above.

I've noticed this on a few recent versions of Nmap but haven't worked out exactly when the regression was introduced.

I'm pretty sure this wasn't affecting Nmap 7.91 on Ubuntu 22.04 however so it's likely to have been introduced after this.

I suspect something is causing the "num" to be 256 which causes the assertion to fire. If you run:
nmap -vvv -sO <ipaddr> -Pn -p0-254

...there are no issues.

@Eponymous-One
Copy link
Author

Actually looking into this a bit more:

protocols.cc:

194   assert(num >= 0 && num < UCHAR_MAX);

UCHAR_MAX is 255...

So it's simply a matter of changing that line to:

assert(num >= 0 && num <= UCHAR_MAX);

or if you prefer:

assert(num >= 0 && num < (UCHAR_MAX + 1));

its-mr-monday added a commit to its-mr-monday/nmap that referenced this issue Jul 23, 2024
@nnposter
Copy link

nnposter commented Aug 5, 2024

Actually, the fix needs more than that. The IP protocol table is defined too small by one, so changing the assertion without fixing the table definition results in potential out-of-bounds read. See #2900 for a more comprehensive fix.

@nnposter nnposter self-assigned this Aug 5, 2024
@nnposter nnposter added the bug label Aug 5, 2024
@nnposter
Copy link

nnposter commented Aug 8, 2024

Thank you for reporting the issue. The fix from #2900 has been committed as r38951.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants