From ef2bafb09c5e37ccaeeab9bb448a2b076055d15e Mon Sep 17 00:00:00 2001 From: dmiller Date: Mon, 28 Dec 2020 17:51:16 +0000 Subject: [PATCH] Report system error message when fopen fails --- MACLookup.cc | 2 +- nmap.cc | 8 ++++---- nmap_dns.cc | 2 +- osscan.cc | 2 +- output.cc | 4 ++-- payload.cc | 2 +- protocols.cc | 2 +- service_scan.cc | 2 +- services.cc | 2 +- 9 files changed, 13 insertions(+), 13 deletions(-) diff --git a/MACLookup.cc b/MACLookup.cc index de825607f..37758aa18 100644 --- a/MACLookup.cc +++ b/MACLookup.cc @@ -100,7 +100,7 @@ static void mac_prefix_init() { fp = fopen(filename, "r"); if (!fp) { - error("Unable to open %s. Ethernet vendor correlation will not be performed ", filename); + gh_perror("Unable to open %s. Ethernet vendor correlation will not be performed ", filename); return; } /* Record where this data file was found. */ diff --git a/nmap.cc b/nmap.cc index 9d0db842b..dd0a9616b 100644 --- a/nmap.cc +++ b/nmap.cc @@ -900,7 +900,7 @@ void parse_options(int argc, char **argv) { } else { o.inputfd = fopen(optarg, "r"); if (!o.inputfd) { - fatal("Failed to open input file %s for reading", optarg); + pfatal("Failed to open input file %s for reading", optarg); } } } else if (strcmp(long_options[option_index].name, "iR") == 0) { @@ -1070,7 +1070,7 @@ void parse_options(int argc, char **argv) { } else { o.inputfd = fopen(optarg, "r"); if (!o.inputfd) { - fatal("Failed to open input file %s for reading", optarg); + pfatal("Failed to open input file %s for reading", optarg); } } break; @@ -1368,7 +1368,7 @@ void parse_options(int argc, char **argv) { if (o.verbose == 0) { o.nmap_stdout = fopen(DEVNULL, "w"); if (!o.nmap_stdout) - fatal("Could not assign %s to stdout for writing", DEVNULL); + pfatal("Could not assign %s to stdout for writing", DEVNULL); } } else { const char *p; @@ -1683,7 +1683,7 @@ void apply_delayed_options() { if (delayed_options.exclude_file) { o.excludefd = fopen(delayed_options.exclude_file, "r"); if (!o.excludefd) - fatal("Failed to open exclude file %s for reading", delayed_options.exclude_file); + pfatal("Failed to open exclude file %s for reading", delayed_options.exclude_file); free(delayed_options.exclude_file); } o.exclude_spec = delayed_options.exclude_spec; diff --git a/nmap_dns.cc b/nmap_dns.cc index ce3e42c80..96e0b46e5 100644 --- a/nmap_dns.cc +++ b/nmap_dns.cc @@ -950,7 +950,7 @@ static void parse_resolvdotconf() { fp = fopen("/etc/resolv.conf", "r"); if (fp == NULL) { - if (firstrun) error("mass_dns: warning: Unable to open /etc/resolv.conf. Try using --system-dns or specify valid servers with --dns-servers"); + if (firstrun) gh_perror("mass_dns: warning: Unable to open /etc/resolv.conf. Try using --system-dns or specify valid servers with --dns-servers"); return; } diff --git a/osscan.cc b/osscan.cc index 50a7826e2..58c42ff8c 100644 --- a/osscan.cc +++ b/osscan.cc @@ -966,7 +966,7 @@ FingerPrintDB *parse_fingerprint_file(const char *fname) { fp = fopen(fname, "r"); if (!fp) - fatal("Unable to open Nmap fingerprint file: %s", fname); + pfatal("Unable to open Nmap fingerprint file: %s", fname); top: while (fgets(line, sizeof(line), fp)) { diff --git a/output.cc b/output.cc index 4303606ce..3a2e8ab87 100644 --- a/output.cc +++ b/output.cc @@ -1101,14 +1101,14 @@ int log_open(int logt, bool append, char *filename) { o.logfd[i] = stdout; o.nmap_stdout = fopen(DEVNULL, "w"); if (!o.nmap_stdout) - fatal("Could not assign %s to stdout for writing", DEVNULL); + pfatal("Could not assign %s to stdout for writing", DEVNULL); } else { if (append) o.logfd[i] = fopen(filename, "a"); else o.logfd[i] = fopen(filename, "w"); if (!o.logfd[i]) - fatal("Failed to open %s output file %s for writing", logtypes[i], + pfatal("Failed to open %s output file %s for writing", logtypes[i], filename); } return 1; diff --git a/payload.cc b/payload.cc index 9170289f0..9025e2646 100644 --- a/payload.cc +++ b/payload.cc @@ -297,7 +297,7 @@ int init_payloads(void) { fp = fopen(filename, "r"); if (fp == NULL) { - fprintf(stderr, "Can't open %s for reading.\n", filename); + gh_perror("Can't open %s for reading.\n", filename); return -1; } /* Record where this data file was found. */ diff --git a/protocols.cc b/protocols.cc index 3469870fc..8ed330562 100644 --- a/protocols.cc +++ b/protocols.cc @@ -93,7 +93,7 @@ static int nmap_protocols_init() { fp = fopen(filename, "r"); if (!fp) { - fatal("Unable to open %s for reading protocol information", filename); + pfatal("Unable to open %s for reading protocol information", filename); } /* Record where this data file was found. */ o.loaded_data_files["nmap-protocols"] = filename; diff --git a/service_scan.cc b/service_scan.cc index eded67fb2..6652b166e 100644 --- a/service_scan.cc +++ b/service_scan.cc @@ -1288,7 +1288,7 @@ void parse_nmap_service_probe_file(AllProbes *AP, char *filename) { // We better start by opening the file fp = fopen(filename, "r"); if (!fp) - fatal("Failed to open nmap-service-probes file %s for reading", filename); + pfatal("Failed to open nmap-service-probes file %s for reading", filename); while(fgets(line, sizeof(line), fp)) { lineno++; diff --git a/services.cc b/services.cc index 5b1c0329c..eab164057 100644 --- a/services.cc +++ b/services.cc @@ -158,7 +158,7 @@ static int nmap_services_init() { fp = fopen(filename, "r"); if (!fp) { - fatal("Unable to open %s for reading service information", filename); + pfatal("Unable to open %s for reading service information", filename); } /* Record where this data file was found. */ o.loaded_data_files["nmap-services"] = filename;