mirror of
https://github.com/nmap/nmap.git
synced 2025-12-06 12:41:29 +00:00
Report system error message when fopen fails
This commit is contained in:
@@ -100,7 +100,7 @@ static void mac_prefix_init() {
|
|||||||
|
|
||||||
fp = fopen(filename, "r");
|
fp = fopen(filename, "r");
|
||||||
if (!fp) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
/* Record where this data file was found. */
|
/* Record where this data file was found. */
|
||||||
|
|||||||
8
nmap.cc
8
nmap.cc
@@ -900,7 +900,7 @@ void parse_options(int argc, char **argv) {
|
|||||||
} else {
|
} else {
|
||||||
o.inputfd = fopen(optarg, "r");
|
o.inputfd = fopen(optarg, "r");
|
||||||
if (!o.inputfd) {
|
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) {
|
} else if (strcmp(long_options[option_index].name, "iR") == 0) {
|
||||||
@@ -1070,7 +1070,7 @@ void parse_options(int argc, char **argv) {
|
|||||||
} else {
|
} else {
|
||||||
o.inputfd = fopen(optarg, "r");
|
o.inputfd = fopen(optarg, "r");
|
||||||
if (!o.inputfd) {
|
if (!o.inputfd) {
|
||||||
fatal("Failed to open input file %s for reading", optarg);
|
pfatal("Failed to open input file %s for reading", optarg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -1368,7 +1368,7 @@ void parse_options(int argc, char **argv) {
|
|||||||
if (o.verbose == 0) {
|
if (o.verbose == 0) {
|
||||||
o.nmap_stdout = fopen(DEVNULL, "w");
|
o.nmap_stdout = fopen(DEVNULL, "w");
|
||||||
if (!o.nmap_stdout)
|
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 {
|
} else {
|
||||||
const char *p;
|
const char *p;
|
||||||
@@ -1683,7 +1683,7 @@ void apply_delayed_options() {
|
|||||||
if (delayed_options.exclude_file) {
|
if (delayed_options.exclude_file) {
|
||||||
o.excludefd = fopen(delayed_options.exclude_file, "r");
|
o.excludefd = fopen(delayed_options.exclude_file, "r");
|
||||||
if (!o.excludefd)
|
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);
|
free(delayed_options.exclude_file);
|
||||||
}
|
}
|
||||||
o.exclude_spec = delayed_options.exclude_spec;
|
o.exclude_spec = delayed_options.exclude_spec;
|
||||||
|
|||||||
@@ -950,7 +950,7 @@ static void parse_resolvdotconf() {
|
|||||||
|
|
||||||
fp = fopen("/etc/resolv.conf", "r");
|
fp = fopen("/etc/resolv.conf", "r");
|
||||||
if (fp == NULL) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -966,7 +966,7 @@ FingerPrintDB *parse_fingerprint_file(const char *fname) {
|
|||||||
|
|
||||||
fp = fopen(fname, "r");
|
fp = fopen(fname, "r");
|
||||||
if (!fp)
|
if (!fp)
|
||||||
fatal("Unable to open Nmap fingerprint file: %s", fname);
|
pfatal("Unable to open Nmap fingerprint file: %s", fname);
|
||||||
|
|
||||||
top:
|
top:
|
||||||
while (fgets(line, sizeof(line), fp)) {
|
while (fgets(line, sizeof(line), fp)) {
|
||||||
|
|||||||
@@ -1101,14 +1101,14 @@ int log_open(int logt, bool append, char *filename) {
|
|||||||
o.logfd[i] = stdout;
|
o.logfd[i] = stdout;
|
||||||
o.nmap_stdout = fopen(DEVNULL, "w");
|
o.nmap_stdout = fopen(DEVNULL, "w");
|
||||||
if (!o.nmap_stdout)
|
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 {
|
} else {
|
||||||
if (append)
|
if (append)
|
||||||
o.logfd[i] = fopen(filename, "a");
|
o.logfd[i] = fopen(filename, "a");
|
||||||
else
|
else
|
||||||
o.logfd[i] = fopen(filename, "w");
|
o.logfd[i] = fopen(filename, "w");
|
||||||
if (!o.logfd[i])
|
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);
|
filename);
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -297,7 +297,7 @@ int init_payloads(void) {
|
|||||||
|
|
||||||
fp = fopen(filename, "r");
|
fp = fopen(filename, "r");
|
||||||
if (fp == NULL) {
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
/* Record where this data file was found. */
|
/* Record where this data file was found. */
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ static int nmap_protocols_init() {
|
|||||||
|
|
||||||
fp = fopen(filename, "r");
|
fp = fopen(filename, "r");
|
||||||
if (!fp) {
|
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. */
|
/* Record where this data file was found. */
|
||||||
o.loaded_data_files["nmap-protocols"] = filename;
|
o.loaded_data_files["nmap-protocols"] = filename;
|
||||||
|
|||||||
@@ -1288,7 +1288,7 @@ void parse_nmap_service_probe_file(AllProbes *AP, char *filename) {
|
|||||||
// We better start by opening the file
|
// We better start by opening the file
|
||||||
fp = fopen(filename, "r");
|
fp = fopen(filename, "r");
|
||||||
if (!fp)
|
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)) {
|
while(fgets(line, sizeof(line), fp)) {
|
||||||
lineno++;
|
lineno++;
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ static int nmap_services_init() {
|
|||||||
|
|
||||||
fp = fopen(filename, "r");
|
fp = fopen(filename, "r");
|
||||||
if (!fp) {
|
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. */
|
/* Record where this data file was found. */
|
||||||
o.loaded_data_files["nmap-services"] = filename;
|
o.loaded_data_files["nmap-services"] = filename;
|
||||||
|
|||||||
Reference in New Issue
Block a user