1
0
mirror of https://github.com/nmap/nmap.git synced 2026-01-02 04:49:02 +00:00

Replace localtime calls with thread-safe alternative. See #1834

This commit is contained in:
dmiller
2019-12-15 05:05:57 +00:00
parent 6995af0743
commit 4a1c9424d3
10 changed files with 132 additions and 49 deletions

View File

@@ -645,16 +645,28 @@ void printportoutput(Target *currenths, PortList *plist) {
if (o.verbose > 1 || o.debugging) {
time_t tm_secs, tm_sece;
struct tm *tm;
struct tm tm;
int err;
char tbufs[128];
tm_secs = currenths->StartTime();
tm_sece = currenths->EndTime();
tm = localtime(&tm_secs);
if (strftime(tbufs, sizeof(tbufs), "%Y-%m-%d %H:%M:%S %Z", tm) <= 0)
fatal("Unable to properly format host start time");
log_write(LOG_PLAIN, "Scanned at %s for %lds\n",
tbufs, (long) (tm_sece - tm_secs));
err = n_localtime(&tm_secs, &tm);
if (err) {
error("Error in localtime: %s", strerror(err));
log_write(LOG_PLAIN, "Scanned for %lds\n",
(long) (tm_sece - tm_secs));
}
else {
if (strftime(tbufs, sizeof(tbufs), "%Y-%m-%d %H:%M:%S %Z", &tm) <= 0) {
error("Unable to properly format host start time");
log_write(LOG_PLAIN, "Scanned for %lds\n",
(long) (tm_sece - tm_secs));
}
else {
log_write(LOG_PLAIN, "Scanned at %s for %lds\n",
tbufs, (long) (tm_sece - tm_secs));
}
}
}
log_write(LOG_MACHINE, "Host: %s (%s)", currenths->targetipstr(),
currenths->HostName());