From 8962c827e1ccebc4cdcab608957fcaec8ea4260f Mon Sep 17 00:00:00 2001 From: dmiller Date: Mon, 8 Apr 2019 14:58:54 +0000 Subject: [PATCH] Avoid crashing --version when Npcap can't be loaded (missing) --- nmap.cc | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/nmap.cc b/nmap.cc index 2b351511a..c47e6d99d 100644 --- a/nmap.cc +++ b/nmap.cc @@ -2753,20 +2753,24 @@ static void display_nmap_version() { with.push_back(std::string("libpcre-") + get_word_or_quote(pcre_version(), 0)); #endif - const char *pcap_version = pcap_lib_version(); #ifdef WIN32 - const char *pcap_num = strpbrk(pcap_version, "0123456789"); - if (pcap_num == NULL) - pcap_num = "(unknown)"; - std::string pcap_num_str (pcap_num, strcspn(pcap_num, ",")); + if (o.have_pcap) { + const char *pcap_version = pcap_lib_version(); + const char *pcap_num = strpbrk(pcap_version, "0123456789"); + if (pcap_num == NULL) + pcap_num = "(unknown)"; + std::string pcap_num_str (pcap_num, strcspn(pcap_num, ",")); + with.push_back(get_word_or_quote(pcap_version, 0) + std::string("-") + pcap_num_str); + } #else + const char *pcap_version = pcap_lib_version(); std::string pcap_num_str = get_word_or_quote(pcap_version, 2); -#endif with.push_back( #ifdef PCAP_INCLUDED std::string("nmap-") + #endif get_word_or_quote(pcap_version, 0) + std::string("-") + pcap_num_str); +#endif #ifdef DNET_INCLUDED with.push_back(std::string("nmap-libdnet-") + DNET_VERSION);