Commit e6deefd0 authored by Evan Hunt's avatar Evan Hunt

Merge branch 'each-lgtm-fixes' into 'master'

fix LGTM warnings

See merge request !3200
parents 8915e472 08f4c7d6
Pipeline #37393 canceled with stages
......@@ -337,11 +337,7 @@ received(unsigned int bytes, isc_sockaddr_t *from, dig_query_t *query) {
}
printf(";; SERVER: %s(%s)\n", fromtext, query->servname);
time(&tnow);
#if !defined(WIN32)
(void)localtime_r(&tnow, &tmnow);
#else /* if !defined(WIN32) */
tmnow = *localtime(&tnow);
#endif /* if !defined(WIN32) */
#ifdef WIN32
/*
......
......@@ -25,6 +25,7 @@
#include <isc/mem.h>
#include <isc/print.h>
#include <isc/string.h>
#include <isc/time.h>
#include <isc/util.h>
#include <dns/keyvalues.h>
......@@ -114,7 +115,6 @@ usage(void) {
static void
printtime(dst_key_t *key, int type, const char *tag, bool epoch, FILE *stream) {
isc_result_t result;
const char *output = NULL;
isc_stdtime_t when;
if (tag != NULL) {
......@@ -127,9 +127,20 @@ printtime(dst_key_t *key, int type, const char *tag, bool epoch, FILE *stream) {
} else if (epoch) {
fprintf(stream, "%d\n", (int)when);
} else {
time_t timet = when;
output = ctime(&timet);
fprintf(stream, "%s", output);
time_t now = when;
struct tm t, *tm = localtime_r(&now, &t);
unsigned int flen;
char timebuf[80];
if (tm == NULL) {
fprintf(stream, "INVALID\n");
return;
}
flen = strftime(timebuf, sizeof(timebuf),
"%a %b %e %H:%M:%S %Y", tm);
INSIST(flen > 0U && flen < sizeof(timebuf));
fprintf(stream, "%s\n", timebuf);
}
}
......
......@@ -3105,14 +3105,18 @@ writeset(const char *prefix, dns_rdatatype_t type) {
static void
print_time(FILE *fp) {
time_t currenttime;
time_t currenttime = time(NULL);
struct tm t, *tm = localtime_r(&currenttime, &t);
unsigned int flen;
char timebuf[80];
if (outputformat != dns_masterformat_text) {
if (tm == NULL || outputformat != dns_masterformat_text) {
return;
}
currenttime = time(NULL);
fprintf(fp, "; File written on %s", ctime(&currenttime));
flen = strftime(timebuf, sizeof(timebuf), "%a %b %e %H:%M:%S %Y", tm);
INSIST(flen > 0U && flen < sizeof(timebuf));
fprintf(fp, "; File written on %s\n", timebuf);
}
static void
......
......@@ -1647,6 +1647,7 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
} else if (strcasecmp(arg, "maintain") == 0) {
allow = maint = true;
} else if (strcasecmp(arg, "off") == 0) {
/* Default */
} else {
INSIST(0);
ISC_UNREACHABLE();
......@@ -1801,6 +1802,7 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
dns_zone_setkeyopt(zone, DNS_ZONEKEY_NORESIGN,
true);
} else if (strcasecmp(arg, "maintain") == 0) {
/* Default */
} else {
INSIST(0);
ISC_UNREACHABLE();
......
......@@ -62,6 +62,7 @@
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <windows.h>
#include <isc/lang.h>
......@@ -277,6 +278,16 @@ end_directory(isc_dir_t *dir) {
}
}
inline struct tm *
gmtime_r(const time_t *clock, struct tm *result) {
errno_t ret = gmtime_s(result, clock);
if (ret != 0) {
errno = ret;
return (NULL);
}
return (result);
}
ISC_LANG_ENDDECLS
#endif /* DNS_GEN_WIN32_H */
......@@ -700,7 +700,8 @@ main(int argc, char **argv) {
}
if (now != -1) {
struct tm *tm = gmtime(&now);
struct tm t, *tm = gmtime_r(&now, &t);
if (tm != NULL && tm->tm_year > 104) {
n = snprintf(year, sizeof(year), "-%d",
tm->tm_year + 1900);
......
......@@ -78,7 +78,7 @@ fromtext_in_wks(ARGS_FROMTEXT) {
isc_token_t token;
isc_region_t region;
struct in_addr addr;
char *e;
char *e = NULL;
long proto;
unsigned char bm[8 * 1024]; /* 64k bits */
long port;
......@@ -138,8 +138,7 @@ fromtext_in_wks(ARGS_FROMTEXT) {
false));
proto = strtol(DNS_AS_STR(token), &e, 10);
if (*e == 0) {
} else if (!mygetprotobyname(DNS_AS_STR(token), &proto)) {
if (*e != '\0' && !mygetprotobyname(DNS_AS_STR(token), &proto)) {
CHECKTOK(DNS_R_UNKNOWNPROTO);
}
......@@ -175,9 +174,8 @@ fromtext_in_wks(ARGS_FROMTEXT) {
}
port = strtol(DNS_AS_STR(token), &e, 10);
if (*e == 0) {
} else if (!mygetservbyname(service, ps, &port) &&
!mygetservbyname(DNS_AS_STR(token), ps, &port))
if (*e != 0 && !mygetservbyname(service, ps, &port) &&
!mygetservbyname(DNS_AS_STR(token), ps, &port))
{
CHECKTOK(DNS_R_UNKNOWNSERVICE);
}
......
......@@ -713,12 +713,12 @@ ip2name(const dns_rpz_cidr_key_t *tgt_ip, dns_rpz_prefix_t tgt_prefix,
(tgt_ip->w[3] >> 8) & 0xffU,
(tgt_ip->w[3] >> 16) & 0xffU,
(tgt_ip->w[3] >> 24) & 0xffU);
if (len < 0 || len > (int)sizeof(str)) {
if (len < 0 || (size_t)len >= sizeof(str)) {
return (ISC_R_FAILURE);
}
} else {
len = snprintf(str, sizeof(str), "%d", tgt_prefix);
if (len == -1) {
if (len < 0 || (size_t)len >= sizeof(str)) {
return (ISC_R_FAILURE);
}
......@@ -753,15 +753,19 @@ ip2name(const dns_rpz_cidr_key_t *tgt_ip, dns_rpz_prefix_t tgt_prefix,
}
for (n = 0; n <= 7; ++n) {
INSIST(len < (int)sizeof(str));
INSIST(len > 0 && (size_t)len < sizeof(str));
if (n == best_first) {
len += snprintf(str + len, sizeof(str) - len,
".zz");
i = snprintf(str + len, sizeof(str) - len,
".zz");
n += best_len - 1;
} else {
len += snprintf(str + len, sizeof(str) - len,
".%x", w[n]);
i = snprintf(str + len, sizeof(str) - len,
".%x", w[n]);
}
if (i < 0 || (size_t)i >= (size_t)(sizeof(str) - len)) {
return (ISC_R_FAILURE);
}
len += i;
}
}
......
......@@ -2191,14 +2191,10 @@ failure:
static isc_stdtime_t
epoch_to_yyyymmdd(time_t when) {
struct tm *tm;
#if !defined(WIN32)
struct tm tm0;
tm = localtime_r(&when, &tm0);
#else /* if !defined(WIN32) */
tm = localtime(&when);
#endif /* if !defined(WIN32) */
struct tm t, *tm = localtime_r(&when, &t);
if (tm == NULL) {
return (0);
}
return (((tm->tm_year + 1900) * 10000) + ((tm->tm_mon + 1) * 100) +
tm->tm_mday);
}
......
......@@ -1611,6 +1611,7 @@ check_dnskey(vctx_t *vctx) {
is_ksk = ((dnskey.flags & DNS_KEYFLAG_KSK) != 0);
if ((dnskey.flags & DNS_KEYOWNER_ZONE) == 0) {
/* Non zone key, skip. */
} else if ((dnskey.flags & DNS_KEYFLAG_REVOKE) != 0) {
if ((dnskey.flags & DNS_KEYFLAG_KSK) != 0 &&
!dns_dnssec_selfsigns(&rdata, vctx->origin,
......
......@@ -501,9 +501,6 @@ isc_sockaddr_fromsockaddr(isc_sockaddr_t *isa, const struct sockaddr *sa) {
default:
return (ISC_R_NOTIMPLEMENTED);
}
if (length == 0) {
return (ISC_R_NOTIMPLEMENTED);
}
memset(isa, 0, sizeof(isc_sockaddr_t));
memcpy(isa, sa, length);
......
......@@ -12,6 +12,7 @@
#ifndef ISC_TIME_H
#define ISC_TIME_H 1
#include <errno.h>
#include <inttypes.h>
#include <stdbool.h>
#include <windows.h>
......@@ -19,6 +20,30 @@
#include <isc/lang.h>
#include <isc/types.h>
/***
*** POSIX Shims
***/
inline struct tm *
gmtime_r(const time_t *clock, struct tm *result) {
errno_t ret = gmtime_s(result, clock);
if (ret != 0) {
errno = ret;
return (NULL);
}
return (result);
}
inline struct tm *
localtime_r(const time_t *clock, struct tm *result) {
errno_t ret = localtime_s(result, clock);
if (ret != 0) {
errno = ret;
return (NULL);
}
return (result);
}
/***
*** Intervals
***/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment