More strictly check strtod results
Some checks failed
nmap multiplatform autobuilds / build (arm64, gcc, ubuntu-latest-gcc-arm64, ubuntu-latest) (push) Has been cancelled
nmap multiplatform autobuilds / build (clang, freebsd-15-clang, ubuntu-latest) (push) Has been cancelled
nmap multiplatform autobuilds / build (clang, macos-15-clang, macos-15) (push) Has been cancelled
nmap multiplatform autobuilds / build (clang, macos-26-clang, macos-26) (push) Has been cancelled
nmap multiplatform autobuilds / build (clang, netbsd-10-clang, ubuntu-latest) (push) Has been cancelled
nmap multiplatform autobuilds / build (clang, openbsd-7-clang, ubuntu-latest) (push) Has been cancelled
nmap multiplatform autobuilds / build (clang, solaris-11-clang, ubuntu-latest) (push) Has been cancelled
nmap multiplatform autobuilds / build (clang, ubuntu-latest-clang, ubuntu-latest) (push) Has been cancelled
nmap multiplatform autobuilds / build (egcc, openbsd-7-gcc, ubuntu-latest) (push) Has been cancelled
nmap multiplatform autobuilds / build (gcc, freebsd-15-gcc, ubuntu-latest) (push) Has been cancelled
nmap multiplatform autobuilds / build (gcc, netbsd-10-gcc, ubuntu-latest) (push) Has been cancelled
nmap multiplatform autobuilds / build (gcc, solaris-11-gcc, ubuntu-latest) (push) Has been cancelled
nmap multiplatform autobuilds / build (gcc, ubuntu-latest-gcc, ubuntu-latest) (push) Has been cancelled
nmap multiplatform autobuilds / build (msvc, windows-latest-msvc, windows-latest) (push) Has been cancelled

This commit is contained in:
dmiller 2026-08-31 17:51:18 +00:00
parent d781b43d17
commit b97fabd935

13
nmap.cc
View file

@ -138,6 +138,7 @@
#include <string>
#include <sstream>
#include <vector>
#include <cmath>
/* global options */
extern char *optarg;
@ -970,18 +971,20 @@ void parse_options(int argc, char **argv) {
fatal("Data payload MTU must be >0 and multiple of 8");
} else if (strcmp(long_options[option_index].name, "port-ratio") == 0) {
char *ptr;
o.topportlevel = strtod(optarg, &ptr);
if (!ptr || o.topportlevel < 0 || o.topportlevel >= 1)
d = strtod(optarg, &ptr);
if (errno != 0 || !ptr || ptr == optarg || *ptr != '\0' || !std::isfinite(d) || d < 0 || d >= 1)
fatal("--port-ratio should be between [0 and 1)");
o.topportlevel = d;
} else if (strcmp(long_options[option_index].name, "exclude-ports") == 0) {
if (o.exclude_portlist)
fatal("Only 1 --exclude-ports option allowed, separate multiple ranges with commas.");
o.exclude_portlist = strdup(optarg);
} else if (strcmp(long_options[option_index].name, "top-ports") == 0) {
char *ptr;
o.topportlevel = strtod(optarg, &ptr);
if (!ptr || o.topportlevel < 1 || ((double)((int)o.topportlevel)) != o.topportlevel)
fatal("--top-ports should be an integer 1 or greater");
l = strtol(optarg, &ptr, 10);
if (errno != 0 || !ptr || ptr == optarg || *ptr != '\0' || l < 1 || l > 65535)
fatal("--top-ports should be an integer between 1 and 65535");
o.topportlevel = l;
} else if (strcmp(long_options[option_index].name, "ip-options") == 0) {
delayed_options.raw_scan_options = true;
o.ipoptions = (u8*) safe_malloc(4 * 10 + 1);