mirror of
https://github.com/isc-projects/bind9.git
synced 2026-06-03 22:08:25 -04:00
Merge branch 'each-lgtm-fixes-v9_11' into 'v9_11'
fix LGTM warnings See merge request isc-projects/bind9!3250
This commit is contained in:
commit
4b1e020deb
10 changed files with 105 additions and 48 deletions
|
|
@ -277,11 +277,7 @@ received(unsigned int bytes, isc_sockaddr_t *from, dig_query_t *query) {
|
|||
printf(";; Query time: %ld msec\n", (long) diff / 1000);
|
||||
printf(";; SERVER: %s(%s)\n", fromtext, query->servname);
|
||||
time(&tnow);
|
||||
#if defined(ISC_PLATFORM_USETHREADS) && !defined(WIN32)
|
||||
(void)localtime_r(&tnow, &tmnow);
|
||||
#else
|
||||
tmnow = *localtime(&tnow);
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -28,6 +28,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>
|
||||
|
|
@ -109,7 +110,6 @@ 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)
|
||||
|
|
@ -121,9 +121,20 @@ printtime(dst_key_t *key, int type, const char *tag, bool epoch,
|
|||
} 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2954,13 +2954,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(¤ttime, &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(¤ttime));
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1442,7 +1442,7 @@ ns_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();
|
||||
|
|
@ -1591,7 +1591,7 @@ ns_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>
|
||||
|
|
@ -268,6 +269,16 @@ end_directory(isc_dir_t *dir) {
|
|||
FindClose(dir->handle);
|
||||
}
|
||||
|
||||
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 */
|
||||
|
|
|
|||
|
|
@ -689,7 +689,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);
|
||||
|
|
|
|||
|
|
@ -73,7 +73,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;
|
||||
|
|
@ -115,10 +115,12 @@ fromtext_in_wks(ARGS_FROMTEXT) {
|
|||
false));
|
||||
|
||||
isc_buffer_availableregion(target, ®ion);
|
||||
if (getquad(DNS_AS_STR(token), &addr, lexer, callbacks) != 1)
|
||||
if (getquad(DNS_AS_STR(token), &addr, lexer, callbacks) != 1) {
|
||||
CHECKTOK(DNS_R_BADDOTTEDQUAD);
|
||||
if (region.length < 4)
|
||||
}
|
||||
if (region.length < 4) {
|
||||
return (ISC_R_NOSPACE);
|
||||
}
|
||||
memmove(region.base, &addr, 4);
|
||||
isc_buffer_add(target, 4);
|
||||
|
||||
|
|
@ -129,18 +131,19 @@ 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);
|
||||
}
|
||||
|
||||
if (proto < 0 || proto > 0xff)
|
||||
if (proto < 0 || proto > 0xff) {
|
||||
CHECKTOK(ISC_R_RANGE);
|
||||
}
|
||||
|
||||
if (proto == IPPROTO_TCP)
|
||||
if (proto == IPPROTO_TCP) {
|
||||
ps = "tcp";
|
||||
else if (proto == IPPROTO_UDP)
|
||||
} else if (proto == IPPROTO_UDP) {
|
||||
ps = "udp";
|
||||
}
|
||||
|
||||
CHECK(uint8_tobuffer(proto, target));
|
||||
|
||||
|
|
@ -148,8 +151,9 @@ fromtext_in_wks(ARGS_FROMTEXT) {
|
|||
do {
|
||||
CHECK(isc_lex_getmastertoken(lexer, &token,
|
||||
isc_tokentype_string, true));
|
||||
if (token.type != isc_tokentype_string)
|
||||
if (token.type != isc_tokentype_string) {
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Lowercase the service string as some getservbyname() are
|
||||
|
|
@ -161,15 +165,18 @@ fromtext_in_wks(ARGS_FROMTEXT) {
|
|||
service[i] = tolower(service[i]&0xff);
|
||||
|
||||
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);
|
||||
if (port < 0 || port > 0xffff)
|
||||
}
|
||||
|
||||
if (port < 0 || port > 0xffff) {
|
||||
CHECKTOK(ISC_R_RANGE);
|
||||
if (port > maxport)
|
||||
}
|
||||
if (port > maxport) {
|
||||
maxport = port;
|
||||
}
|
||||
bm[port / 8] |= (0x80 >> (port % 8));
|
||||
} while (1);
|
||||
|
||||
|
|
|
|||
|
|
@ -696,13 +696,14 @@ 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);
|
||||
}
|
||||
for (i = 0; i < DNS_RPZ_CIDR_WORDS; i++) {
|
||||
w[i*2+1] = ((tgt_ip->w[DNS_RPZ_CIDR_WORDS-1-i] >> 16)
|
||||
& 0xffff);
|
||||
|
|
@ -732,15 +733,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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2082,16 +2082,12 @@ dns_update_signaturesinc(dns_update_log_t *log, dns_zone_t *zone, dns_db_t *db,
|
|||
|
||||
static isc_stdtime_t
|
||||
epoch_to_yyyymmdd(time_t when) {
|
||||
struct tm *tm;
|
||||
|
||||
#if defined(ISC_PLATFORM_USETHREADS) && !defined(WIN32)
|
||||
struct tm tm0;
|
||||
tm = localtime_r(&when, &tm0);
|
||||
#else
|
||||
tm = localtime(&when);
|
||||
#endif
|
||||
return (((tm->tm_year + 1900) * 10000) +
|
||||
((tm->tm_mon + 1) * 100) + tm->tm_mday);
|
||||
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);
|
||||
}
|
||||
|
||||
uint32_t
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
#ifndef ISC_TIME_H
|
||||
#define ISC_TIME_H 1
|
||||
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdbool.h>
|
||||
#include <windows.h>
|
||||
|
|
@ -20,6 +21,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
|
||||
***/
|
||||
|
|
|
|||
Loading…
Reference in a new issue