* [Bug 2954] Version 4.2.8p4 crashes on startup with sig fault
- fixed data race conditions in threaded DNS worker. perlinger@ntp.org
- limit threading warm-up to linux; FreeBSD bombs on it. perlinger@ntp.org
+* [Bug 2962] truncation of size_t/ptrdiff_t on 64bit targets. perlinger@ntp.org
+ - fixed several other warnings (cast-alignment, missing const, missing prorotypes)
+ - promote use of 'size_t' for values that express a size
+ - use ptr-to-const for read-only arguments
+ - make sure SOCKET values are not truncated (win32-specific)
+ - format string fixes
* Unity cleanup for FreeBSD-6.4. Harlan Stenn.
* Unity test cleanup. Harlan Stenn.
---
recvbuff.h \
refclock_atom.h \
refidsmear.h \
+ safecast.h \
ssl_applink.c \
timepps-SCO.h \
timepps-Solaris.h \
extern void refclock_control(sockaddr_u *,
const struct refclockstat *,
struct refclockstat *);
-extern int refclock_open (char *, u_int, u_int);
+extern int refclock_open (const char *, u_int, u_int);
extern int refclock_setup (int, u_int, u_int);
extern void refclock_timer (struct peer *);
extern void refclock_transmit(struct peer *);
/* authkeys.c */
extern void auth_delkeys (void);
extern int auth_havekey (keyid_t);
-extern int authdecrypt (keyid_t, u_int32 *, int, int);
-extern int authencrypt (keyid_t, u_int32 *, int);
+extern int authdecrypt (keyid_t, u_int32 *, size_t, size_t);
+extern size_t authencrypt (keyid_t, u_int32 *, size_t);
extern int authhavekey (keyid_t);
extern int authistrusted (keyid_t);
extern int authreadkeys (const char *);
extern int ymd2yd (int, int, int);
/* a_md5encrypt.c */
-extern int MD5authdecrypt (int, u_char *, u_int32 *, int, int);
-extern int MD5authencrypt (int, u_char *, u_int32 *, int);
+extern int MD5authdecrypt (int, const u_char *, u_int32 *, size_t, size_t);
+extern size_t MD5authencrypt (int, const u_char *, u_int32 *, size_t);
extern void MD5auth_setkey (keyid_t, int, const u_char *, size_t);
extern u_int32 addr2refid (sockaddr_u *);
extern int freq_cnt;
/* ntp_monitor.c */
-#define MON_HASH_SIZE (1U << mon_hash_bits)
+#define MON_HASH_SIZE ((size_t)1U << mon_hash_bits)
#define MON_HASH_MASK (MON_HASH_SIZE - 1)
#define MON_HASH(addr) (sock_hash(addr) & MON_HASH_MASK)
extern void init_mon (void);
--- /dev/null
+#ifndef SAFECAST_H
+#define SAFECAST_H
+
+#include <limits.h>
+static inline int size2int_chk(size_t v)
+{
+ if (v > INT_MAX)
+ abort();
+ return (int)(v);
+}
+
+static inline int size2int_sat(size_t v)
+{
+ return (v > INT_MAX) ? INT_MAX : (int)v;
+}
+
+/* Compilers can emit warning about increased alignment requirements
+ * when casting pointers. The impact is tricky: on machines where
+ * alignment is just a performance issue (x86,x64,...) this might just
+ * cause a performance penalty. On others, an address error can occur
+ * and the process dies...
+ *
+ * Still, there are many cases where the pointer arithmetic and the
+ * buffer alignment make sure this does not happen. OTOH, the compiler
+ * doesn't know this and still emits warnings.
+ *
+ * The following cast macros are going through void pointers to tell
+ * the compiler that there is no alignment requirement to watch.
+ */
+#define UA_PTR(ptype,pval) ((ptype *)(void*)(pval))
+#define UAC_PTR(ptype,pval) ((const ptype *)(const void*)(pval))
+#define UAV_PTR(ptype,pval) ((volatile ptype *)(volatile void*)(pval))
+
+#endif
result = ISC_R_NOTFOUND;
else {
*symbolp = found->symbol;
- *offsetp = (const char *)addr - (char *)found->addr;
+ *offsetp = (u_long)((const char *)addr - (char *)found->addr);
}
return (result);
void
isc__buffer_putstr(isc_buffer_t *b, const char *source) {
- unsigned int l;
+ size_t l;
unsigned char *cp;
REQUIRE(ISC_BUFFER_VALID(b));
cp = isc_buffer_used(b);
memcpy(cp, source, l);
- b->used += l;
+ b->used += (u_int)l; /* checked above - no overflow here */
}
isc_result_t
int
isc_net_aton(const char *cp, struct in_addr *addr) {
unsigned long val;
- int base, n;
+ int base;
unsigned char c;
isc_uint8_t parts[4];
isc_uint8_t *pp = parts;
* Concoct the address according to
* the number of parts specified.
*/
- n = pp - parts + 1;
- switch (n) {
+ switch (pp - parts + 1) {
case 1: /* a -- 32 bits */
break;
const char *pch;
if ((pch = strchr(digits, ch)) != NULL) {
- unsigned int newv = *tp * 10 + (pch - digits);
+ size_t newv = *tp * 10 + (pch - digits);
if (saw_digit && *tp == 0)
return (0);
* Since some memmove()'s erroneously fail to handle
* overlapping regions, we'll do the shift by hand.
*/
- const int n = tp - colonp;
+ const size_t n = tp - colonp;
int i;
if (tp == endp)
return (0);
- for (i = 1; i <= n; i++) {
+ for (i = 1; (size_t)i <= n; i++) {
endp[- i] = colonp[n - i];
colonp[n - i] = 0;
}
char *basenam, *digit_end;
const char *dirname;
int version, greatest = -1;
- unsigned int basenamelen;
+ size_t basenamelen;
isc_dir_t dir;
isc_result_t result;
char sep = '/';
if (r == NULL)
return (ISC_R_FAILURE);
- alen = strlen(abuf);
+ alen = (unsigned int)strlen(abuf); /* no overflow possible */
INSIST(alen < sizeof(abuf));
zlen = 0;
return (ISC_R_FAILURE);
}
- plen = strlen(pbuf);
+ plen = (unsigned int)strlen(pbuf);
INSIST(plen < sizeof(pbuf));
isc_netaddr_fromsockaddr(&netaddr, sockaddr);
isc__task_create(isc_taskmgr_t *manager0, unsigned int quantum,
isc_task_t **taskp)
{
- isc__taskmgr_t *manager = (isc__taskmgr_t *)manager0;
+ isc__taskmgr_t *manager = (void*)manager0;
isc__task_t *task;
isc_boolean_t exiting;
isc_result_t result;
*/
REQUIRE(managerp != NULL);
- manager = (isc__taskmgr_t *)*managerp;
+ manager = (void*)(*managerp);
REQUIRE(VALID_MANAGER(manager));
#ifndef USE_WORKER_THREADS
ISC_TASKFUNC_SCOPE void
isc__taskmgr_setmode(isc_taskmgr_t *manager0, isc_taskmgrmode_t mode) {
- isc__taskmgr_t *manager = (isc__taskmgr_t *)manager0;
+ isc__taskmgr_t *manager = (void*)manager0;
LOCK(&manager->lock);
manager->mode = mode;
ISC_TASKFUNC_SCOPE isc_taskmgrmode_t
isc__taskmgr_mode(isc_taskmgr_t *manager0) {
- isc__taskmgr_t *manager = (isc__taskmgr_t *)manager0;
+ isc__taskmgr_t *manager = (void*)manager0;
isc_taskmgrmode_t mode;
LOCK(&manager->lock);
mode = manager->mode;
#ifndef USE_WORKER_THREADS
isc_boolean_t
isc__taskmgr_ready(isc_taskmgr_t *manager0) {
- isc__taskmgr_t *manager = (isc__taskmgr_t *)manager0;
+ isc__taskmgr_t *manager = (void*)manager0;
isc_boolean_t is_ready;
#ifdef USE_SHARED_MANAGER
isc_result_t
isc__taskmgr_dispatch(isc_taskmgr_t *manager0) {
- isc__taskmgr_t *manager = (isc__taskmgr_t *)manager0;
+ isc__taskmgr_t *manager = (void*)manager0;
#ifdef USE_SHARED_MANAGER
if (manager == NULL)
#else
ISC_TASKFUNC_SCOPE void
isc__taskmgr_pause(isc_taskmgr_t *manager0) {
- isc__taskmgr_t *manager = (isc__taskmgr_t *)manager0;
+ isc__taskmgr_t *manager = (void*)manager0;
LOCK(&manager->lock);
while (manager->tasks_running > 0) {
WAIT(&manager->paused, &manager->lock);
ISC_TASKFUNC_SCOPE void
isc__taskmgr_resume(isc_taskmgr_t *manager0) {
- isc__taskmgr_t *manager = (isc__taskmgr_t *)manager0;
+ isc__taskmgr_t *manager = (void*)manager0;
LOCK(&manager->lock);
if (manager->pause_requested) {
IP_ADAPTER_ADDRESSES * ipaaCur; /* enumeration position */
IP_ADAPTER_UNICAST_ADDRESS *ipuaCur; /* enumeration subposition */
/* fields used for the older address enumeration ioctls */
- int socket;
+ SOCKET socket;
INTERFACE_INFO IFData; /* Current Interface Info */
int numIF; /* Current Interface count */
int v4IF; /* Number of IPv4 Interfaces */
static void
try_ipv6pktinfo(void) {
- int s, on;
+ SOCKET s;
+ int on;
char strbuf[ISC_STRERRORSIZE];
isc_result_t result;
int optname;
*
* Returns length of MAC including key ID and digest.
*/
-int
+size_t
MD5authencrypt(
- int type, /* hash algorithm */
- u_char *key, /* key pointer */
- u_int32 *pkt, /* packet pointer */
- int length /* packet length */
+ int type, /* hash algorithm */
+ const u_char * key, /* key pointer */
+ u_int32 * pkt, /* packet pointer */
+ size_t length /* packet length */
)
{
u_char digest[EVP_MAX_MD_SIZE];
EVP_DigestInit(&ctx, EVP_get_digestbynid(type));
#endif
EVP_DigestUpdate(&ctx, key, cache_secretsize);
- EVP_DigestUpdate(&ctx, (u_char *)pkt, (u_int)length);
+ EVP_DigestUpdate(&ctx, (u_char *)pkt, length);
EVP_DigestFinal(&ctx, digest, &len);
memmove((u_char *)pkt + length + 4, digest, len);
return (len + 4);
*/
int
MD5authdecrypt(
- int type, /* hash algorithm */
- u_char *key, /* key pointer */
- u_int32 *pkt, /* packet pointer */
- int length, /* packet length */
- int size /* MAC size */
+ int type, /* hash algorithm */
+ const u_char * key, /* key pointer */
+ u_int32 * pkt, /* packet pointer */
+ size_t length, /* packet length */
+ size_t size /* MAC size */
)
{
u_char digest[EVP_MAX_MD_SIZE];
EVP_DigestInit(&ctx, EVP_get_digestbynid(type));
#endif
EVP_DigestUpdate(&ctx, key, cache_secretsize);
- EVP_DigestUpdate(&ctx, (u_char *)pkt, (u_int)length);
+ EVP_DigestUpdate(&ctx, (u_char *)pkt, length);
EVP_DigestFinal(&ctx, digest, &len);
- if ((u_int)size != len + 4) {
+ if (size != (size_t)len + 4) {
msyslog(LOG_ERR,
"MAC decrypt: MAC length error");
return (0);
}
- return !memcmp(digest, (char *)pkt + length + 4, len);
+ return !memcmp(digest, (const char *)pkt + length + 4, len);
}
/*
while (*cp != '\0' && (ind = strchr(digits, *cp)) != NULL) {
dec_i = (dec_i << 3) + (dec_i << 1); /* multiply by 10 */
- dec_i += (ind - digits);
+ dec_i += (u_long)(ind - digits);
cp++;
}
&& (ind = strchr(digits, *cp)) != NULL) {
ndec++;
dec_f = (dec_f << 3) + (dec_f << 1); /* *10 */
- dec_f += (ind - digits);
+ dec_f += (u_long)(ind - digits);
cp++;
}
*
* Returns length of authenticator field, zero if key not found.
*/
-int
+size_t
authencrypt(
keyid_t keyno,
u_int32 * pkt,
- int length
+ size_t length
)
{\
/*
authdecrypt(
keyid_t keyno,
u_int32 * pkt,
- int length,
- int size
+ size_t length,
+ size_t size
)
{
/*
const u_char *str
)
{
- int len;
+ size_t len;
len = strlen((const char *)str);
if (0 == len)
* including a possible rounding from the fractional part.
*/
cp = cpend = cpdec = &cbuf[10];
- for (dec = cp - cbuf; dec > 0 && fpi != 0; dec--) {
+ for (dec = (int)(cp - cbuf); dec > 0 && fpi != 0; dec--) {
/* can add another digit */
u_int32 digit;
cpdec += 3;
}
if ((size_t)dec > sizeof(cbuf) - (cpend - cbuf))
- dec = sizeof(cbuf) - (cpend - cbuf);
+ dec = (int)(sizeof(cbuf) - (cpend - cbuf));
/*
* If there's a fraction to deal with, do so.
u_char *tp = cpend;
int carry = ((fpv & 0x80000000) != 0);
- for (dec = tp - cbuf; carry && dec > 0; dec--) {
+ for (dec = (int)(tp - cbuf); carry && dec > 0; dec--) {
*--tp += 1;
if (*tp == 10)
*tp = 0;
while (*cp != '\0' && (cp - cpstart) < 8 &&
(ind = strchr(digits, *cp)) != NULL) {
dec_i = dec_i << 4; /* multiply by 16 */
- dec_i += ((ind - digits) > 15) ? (ind - digits) - 6
- : (ind - digits);
+ dec_i += ((ind - digits) > 15)
+ ? (u_long)(ind - digits - 6)
+ : (u_long)(ind - digits);
cp++;
}
while (*cp != '\0' && (cp - cpstart) < 8 &&
(ind = strchr(digits, *cp)) != NULL) {
dec_f = dec_f << 4; /* multiply by 16 */
- dec_f += ((ind - digits) > 15) ? (ind - digits) - 6
- : (ind - digits);
+ dec_f += ((ind - digits) > 15)
+ ? (u_long)(ind - digits - 6)
+ : (u_long)(ind - digits);
cp++;
}
*/
*bp++ = '.';
if ((cpdec - cp) < 3) {
- register int i = 3 - (cpdec - cp);
-
+ size_t i = 3 - (cpdec - cp);
do {
*bp++ = '0';
} while (--i > 0);
)
{
va_list ap;
- size_t rc;
+ int rc;
va_start(ap, fmt);
rc = mvsnprintf(buf, bufsiz, fmt, ap);
#include <l_stdlib.h>
#include <ntp_random.h>
+#include "safecast.h"
#ifdef USE_OPENSSL_CRYPTO_RAND
#include <openssl/err.h>
#ifdef USE_OPENSSL_CRYPTO_RAND
int rc;
- rc = RAND_bytes(buf, nbytes);
+ rc = RAND_bytes(buf, size2int_chk(nbytes));
if (1 != rc) {
unsigned long err;
char *err_str;
#include "ntp.h"
#include "ntp_stdlib.h"
#include "ntp_lineedit.h"
+#include "safecast.h"
#define MAXEDITLINE 512
line = fgets(line_buf, sizeof(line_buf), stdin);
if (NULL != line && *line) {
- *pcount = strlen(line);
+ *pcount = (int)strlen(line); /* cannot overflow here */
line = estrdup(line);
} else
line = NULL;
prev_octets);
blocking_children_alloc = new_alloc;
- return prev_alloc;
+ /* assume we'll never have enough workers to overflow u_int */
+ return (u_int)prev_alloc;
}
switch (cflags) {
case PRINT_C_CHAR:
charptr = va_arg(args, signed char *);
- *charptr = len;
+ *charptr = (signed char)len;
break;
case PRINT_C_SHORT:
shortptr = va_arg(args, short int *);
- *shortptr = len;
+ *shortptr = (short int)len;
break;
case PRINT_C_LONG:
longptr = va_arg(args, long int *);
- *longptr = len;
+ *longptr = (long int)len;
break;
case PRINT_C_LLONG:
llongptr = va_arg(args, LLONG *);
- *llongptr = len;
+ *llongptr = (LLONG)len;
break;
case PRINT_C_SIZE:
/*
* size_t argument." (7.19.6.1, 7)
*/
sizeptr = va_arg(args, SSIZE_T *);
- *sizeptr = len;
+ *sizeptr = (SSIZE_T)len;
break;
case PRINT_C_INTMAX:
intmaxptr = va_arg(args, INTMAX_T *);
- *intmaxptr = len;
+ *intmaxptr = (INTMAX_T)len;
break;
case PRINT_C_PTRDIFF:
ptrdiffptr = va_arg(args, PTRDIFF_T *);
- *ptrdiffptr = len;
+ *ptrdiffptr = (PTRDIFF_T)len;
break;
default:
intptr = va_arg(args, int *);
- *intptr = len;
+ *intptr = (int)len;
break;
}
break;
* Factor of ten with the number of digits needed for the fractional
* part. For example, if the precision is 3, the mask will be 1000.
*/
- mask = mypow10(precision);
+ mask = (UINTMAX_T)mypow10(precision);
/*
* We "cheat" by converting the fractional part to integer by
* multiplying by a factor of ten.
if (value >= UINTMAX_MAX)
return UINTMAX_MAX;
- result = value;
+ result = (UINTMAX_T)value;
/*
* At least on NetBSD/sparc64 3.0.2 and 4.99.30, casting long double to
* an integer type converts e.g. 1.9 to 2 instead of 1 (which violates
{
unsigned int rtc;
- parseprintf(DD_PARSE, ("inp_computime(0x%lx, 0x%x, ...)\n", (long)parseio, ch));
+ parseprintf(DD_PARSE, ("inp_computime(0x%p, 0x%x, ...)\n", (void*)parseio, ch));
switch (ch)
{
{
unsigned int rtc;
- parseprintf(DD_PARSE, ("inp_dcf7000(0x%lx, 0x%x, ...)\n", (long)parseio, ch));
+ parseprintf(DD_PARSE, ("inp_dcf7000(0x%p, 0x%x, ...)\n", (void*)parseio, ch));
switch (ch)
{
{
unsigned int rtc;
- parseprintf(DD_PARSE, ("inp_hopf6021(0x%lx, 0x%x, ...)\n", (long)parseio, ch));
+ parseprintf(DD_PARSE, ("inp_hopf6021(0x%p, 0x%x, ...)\n", (void*)parseio, ch));
switch (ch)
{
{
unsigned int rtc;
- parseprintf(DD_PARSE, ("mbg_input(0x%lx, 0x%x, ...)\n", (long)parseio, ch));
+ parseprintf(DD_PARSE, ("mbg_input(0x%p, 0x%x, ...)\n", (void*)parseio, ch));
switch (ch)
{
msg_buf = (struct msg_buf *)parseio->parse_pdata;
- parseprintf(DD_PARSE, ("gps_input(0x%lx, 0x%x, ...)\n", (long)parseio, ch));
+ parseprintf(DD_PARSE, ("gps_input(0x%p, 0x%x, ...)\n", (void*)parseio, ch));
if (!msg_buf)
return PARSE_INP_SKIP;
{
static struct timeval timeout = { 1, 500000 }; /* 1.5 secongs denote second #60 */
- parseprintf(DD_PARSE, ("inp_rawdcf(0x%lx, 0x%x, ...)\n", (long)parseio, ch));
+ parseprintf(DD_PARSE, ("inp_rawdcf(0x%p, 0x%x, ...)\n", (void*)parseio, ch));
parseio->parse_dtime.parse_stime = *tstamp; /* collect timestamp */
{
unsigned int rtc;
- parseprintf(DD_PARSE, ("inp_rcc8000(0x%lx, 0x%x, ...)\n", (long)parseio, ch));
+ parseprintf(DD_PARSE, ("inp_rcc8000(0x%p, 0x%x, ...)\n", (void*)parseio, ch));
switch (ch)
{
{
unsigned int rtc;
- parseprintf(DD_PARSE, ("inp_schmid(0x%lx, 0x%x, ...)\n", (long)parseio, ch));
+ parseprintf(DD_PARSE, ("inp_schmid(0x%p, 0x%x, ...)\n", (void*)parseio, ch));
switch ((uint8_t)ch)
{
{
unsigned int rtc;
- parseprintf(DD_PARSE, ("inp_trimtaip(0x%lx, 0x%x, ...)\n", (long)parseio, ch));
+ parseprintf(DD_PARSE, ("inp_trimtaip(0x%p, 0x%x, ...)\n", (void*)parseio, ch));
switch (ch)
{
extern int printf (const char *, ...);
#endif
-static const u_char VT_INITIALISED = 0x01;
-static const u_char VT_SYNCHRONISED = 0x02;
-static const u_char VT_ALARM_STATE = 0x04;
+/* static const u_char VT_INITIALISED = 0x01; */
+/* static const u_char VT_SYNCHRONISED = 0x02; */
+/* static const u_char VT_ALARM_STATE = 0x04; */
static const u_char VT_BST = 0x08;
-static const u_char VT_SEASON_CHANGE = 0x10;
-static const u_char VT_LAST_TELEGRAM_OK = 0x20;
+/* static const u_char VT_SEASON_CHANGE = 0x10; */
+/* static const u_char VT_LAST_TELEGRAM_OK = 0x20; */
/*
* The Varitext receiver sends a datagram in the following format every minute
struct varitext *t = (struct varitext *)parseio->parse_pdata;
int rtc;
- parseprintf(DD_PARSE, ("inp_varitext(0x%lx, 0x%x, ...)\n", (long)parseio, ch));
+ parseprintf(DD_PARSE, ("inp_varitext(0x%p, 0x%x, ...)\n", (void*)parseio, ch));
if (!t)
return PARSE_INP_SKIP; /* local data not allocated - sigh! */
{
unsigned int rtc;
- parseprintf(DD_PARSE, ("inp_wharton_400a(0x%lx, 0x%x, ...)\n", (long)parseio, ch));
+ parseprintf(DD_PARSE, ("inp_wharton_400a(0x%p, 0x%x, ...)\n", (void*)parseio, ch));
switch (ch)
{
break;
}
- parseprintf(DD_PARSE, ("parse_ioread(0x%lx, char=0x%x, ..., ...)\n", (unsigned long)parseio, ch & 0xFF));
+ parseprintf(DD_PARSE, ("parse_ioread(0x%p, char=0x%x, ..., ...)\n", (void*)parseio, ch & 0xFF));
if (!clockformats[parseio->parse_lformat]->convert)
{
u_char errcode
)
{
- int maclen;
+ size_t maclen;
numctlerrors++;
DPRINTF(3, ("sending control error %u\n", errcode));
)
{
size_t i;
- int dlen;
- int sendlen;
- int maclen;
- int totlen;
+ size_t dlen;
+ size_t sendlen;
+ size_t maclen;
+ size_t totlen;
keyid_t keyid;
dlen = datapt - rpkt.u.data;
}
/* Check if the declared size fits into the remaining
- * buffer.
+ * buffer. We *know* 'macbytes' > 0 here!
*/
- if (len > macbytes) {
+ if (len > (u_int)macbytes) {
DPRINTF(1, ("crypto_recv: possible attack detected, associd %d\n",
associd));
return XEVNT_LEN;
#include "timevalops.h"
#include "timespecops.h"
#include "ntpd-opts.h"
+#include "safecast.h"
/* Don't include ISC's version of IPv6 variables and structures */
#define ISC_IPV6_H 1
hints.ai_flags |= AI_NUMERICHOST;
if (getaddrinfo(tmpbuf, NULL, &hints, &result) == 0) {
AF(addr) = AF_INET6;
- resaddr6 = (struct sockaddr_in6 *)result->ai_addr;
+ resaddr6 = UA_PTR(struct sockaddr_in6, result->ai_addr);
SET_ADDR6N(addr, resaddr6->sin6_addr);
SET_SCOPE(addr, resaddr6->sin6_scope_id);
#endif /* HAVE_BINTIME */
#ifdef HAVE_TIMESTAMPNS
case SCM_TIMESTAMPNS:
- tsp = (struct timespec *)CMSG_DATA(cmsghdr);
+ tsp = UA_PTR(struct timespec, CMSG_DATA(cmsghdr));
if (sys_tick > measured_tick &&
sys_tick > 1e-9) {
ticks = (unsigned long)((tsp->tv_nsec * 1e-9) /
fds = activefds;
tvzero.tv_sec = tvzero.tv_usec = 0;
- n = select(maxactivefd + 1, &fds, (fd_set *)0, (fd_set *)0,
- &tvzero);
+ n = select(maxactivefd + 1, &fds, NULL, NULL, &tvzero);
/*
* If there are no packets waiting just return
break;
case FD_TYPE_FILE:
- closeserial(lsock->fd);
+ closeserial((int)lsock->fd);
break;
default:
* process routing message
*/
#ifdef HAVE_RTNETLINK
- for (nh = (struct nlmsghdr *)buffer;
+ for (nh = UA_PTR(struct nlmsghdr, buffer);
NLMSG_OK(nh, cnt);
nh = NLMSG_NEXT(nh, cnt)) {
msg_type = nh->nlmsg_type;
double dtemp, etemp; /* double temps */
char tbuf[80]; /* report buffer */
+ (void)ntp_adj_ret; /* not always used below... */
/*
* If the loop is opened or the NIST LOCKCLOCK is in use,
* monitor and record the offsets anyway in order to determine
const char * loop_desc;
int ntp_adj_ret;
+ (void)ntp_adj_ret; /* not always used below... */
drift_comp = freq;
loop_desc = "ntpd";
#ifdef KERNEL_PLL
struct pkt xpkt; /* transmit packet structure */
struct pkt *rpkt; /* receive packet structure */
l_fp xmt_tx, xmt_ty;
- int sendlen;
+ size_t sendlen;
#ifdef AUTOKEY
u_int32 temp32;
#endif
#ifdef DEBUG
if (debug)
printf(
- "transmit: at %ld %s->%s mode %d len %d\n",
+ "transmit: at %ld %s->%s mode %d len %lu\n",
current_time, stoa(&rbufp->dstadr->sin),
- stoa(&rbufp->recv_srcadr), xmode, sendlen);
+ stoa(&rbufp->recv_srcadr), xmode,
+ (u_long)sendlen);
#endif
return;
}
*/
cookie = session_key(&rbufp->recv_srcadr,
&rbufp->dstadr->sin, 0, sys_private, 0);
- if (rbufp->recv_length > sendlen + (int)MAX_MAC_LEN) {
+ if ((size_t)rbufp->recv_length > sendlen + MAX_MAC_LEN) {
session_key(&rbufp->dstadr->sin,
&rbufp->recv_srcadr, xkeyid, 0, 2);
temp32 = CRYPTO_RESP;
#ifdef DEBUG
if (debug)
printf(
- "transmit: at %ld %s->%s mode %d keyid %08x len %d\n",
+ "transmit: at %ld %s->%s mode %d keyid %08x len %lu\n",
current_time, ntoa(&rbufp->dstadr->sin),
- ntoa(&rbufp->recv_srcadr), xmode, xkeyid, sendlen);
+ ntoa(&rbufp->recv_srcadr), xmode, xkeyid,
+ (u_long)sendlen);
#endif
}
*/
int
refclock_open(
- char *dev, /* device name pointer */
- u_int speed, /* serial port speed (code) */
- u_int lflags /* line discipline flags */
+ const char *dev, /* device name pointer */
+ u_int speed, /* serial port speed (code) */
+ u_int lflags /* line discipline flags */
)
{
int fd;
u_long trust
)
{
- register u_long *kp;
+ register uint32_t *kp;
register int items;
items = INFO_NITEMS(inpkt->err_nitems);
- kp = (u_long *)&inpkt->u;
+ kp = (uint32_t*)&inpkt->u;
while (items-- > 0) {
authtrust(*kp, trust);
kp++;
const size_t count = INC_RESLIST4;
restrict_u * rl;
restrict_u * res;
- int i;
+ size_t i;
UNLINK_HEAD_SLIST(res, resfree4, link);
if (res != NULL)
const size_t count = INC_RESLIST6;
restrict_u * rl;
restrict_u * res;
- int i;
+ size_t i;
UNLINK_HEAD_SLIST(res, resfree6, link);
if (res != NULL)
while (len) {
int n = write(fd, buf, len);
if (n <= 0) return total;
- buf = n + (char *)buf;
+ buf = n + (const char *)buf;
len -= n;
total += n;
}
{
if (read_all(fd, len, sizeof(*len)) != sizeof(*len)) return -1;
*len = ntohl(*len);
- (*buf) = emalloc(*len);
+ *buf = emalloc(*len);
if (read_all(fd, *buf, *len) != *len) {
free(*buf);
+ *buf = NULL;
return -1;
}
return 0;
* announce the leap event has happened.
*/
const char *leapmsg = NULL;
- if (lsdata.warped < 0) {
+ double lswarp = lsdata.warped;
+ if (lswarp < 0.0) {
if (clock_max_back > 0.0 &&
- clock_max_back < fabs(lsdata.warped)) {
- step_systime(lsdata.warped);
+ clock_max_back < -lswarp) {
+ step_systime(lswarp);
leapmsg = leapmsg_p_step;
} else {
leapmsg = leapmsg_p_slew;
}
- } else if (lsdata.warped > 0) {
+ } else if (lswarp > 0.0) {
if (clock_max_fwd > 0.0 &&
- clock_max_fwd < fabs(lsdata.warped)) {
- step_systime(lsdata.warped);
+ clock_max_fwd < lswarp) {
+ step_systime(lswarp);
leapmsg = leapmsg_n_step;
} else {
leapmsg = leapmsg_n_slew;
{
FILE *fp;
const char *value;
- int len;
+ size_t len;
double old_drift;
l_fp now;
time_t ttnow;
(int)sizeof(statsdir) - 2);
} else {
int add_dir_sep;
- int value_l;
+ size_t value_l;
/* Add a DIR_SEP unless we already have one. */
value_l = strlen(value);
const char *keyfile
)
{
- int len;
+ size_t len;
len = strlen(keyfile);
if (!len)
static char *
mkreadable(
char *buffer,
- long blen,
+ size_t blen,
const char *src,
- u_long srclen,
+ size_t srclen,
int hex
)
{
static enum segstat_t shm_query(volatile struct shmTime *shm_in, struct shm_stat_t *shm_stat)
/* try to grab a sample from the specified SHM segment */
{
- volatile struct shmTime shmcopy, *shm = shm_in;
+ struct shmTime shmcopy;
+ volatile struct shmTime *shm = shm_in;
volatile int cnt;
unsigned int cns_new, rns_new;
* (b) memset compiles to an uninterruptible single-instruction bitblt.
*/
memory_barrier();
- memcpy((void *)&shmcopy, (void *)shm, sizeof(struct shmTime));
+ memcpy(&shmcopy, (void*)(uintptr_t)shm, sizeof(struct shmTime));
shm->valid = 0;
memory_barrier();
pp = peer->procptr;
if (!(pp->sloppyclockflag & CLK_FLAG1)) {
- int len = strlen(cmd);
+ size_t len = strlen(cmd);
true_debug(peer, "Send '%s'\n", cmd);
if (write(pp->io.fd, cmd, (unsigned)len) != len)
memcpy(ppsRef, pRefObj->pps, TSYNC_REF_LEN);
// Extract the Clock Service Time Scale and convert to correct byte order
- memcpy(&tmscl, ((TIME_SCALE*)(it1->payloads)), sizeof(tmscl));
+ memcpy(&tmscl, it1->payloads, sizeof(tmscl));
tmscl = ntohl(tmscl);
// Extract leap second info from ioctl payload and perform byte swapping
nfound = poll(rdfdes, (unsigned int)nbsock, timeout.tv_sec * 1000);
#else
- nfound = select(maxfd, &rdfdes, (fd_set *)0,
- (fd_set *)0, &timeout);
+ nfound = select(maxfd, &rdfdes, NULL, NULL,
+ &timeout);
#endif
if (nfound > 0)
input_handler();
* If not, just timestamp it and send it away.
*/
if (sys_authenticate) {
- int len;
+ size_t len;
xpkt.exten[0] = htonl(sys_authkey);
get_systime(&server->xmt);
printf("receive: rpkt keyid=%ld sys_authkey=%ld decrypt=%ld\n",
(long int)ntohl(rpkt->exten[0]), (long int)sys_authkey,
(long int)authdecrypt(sys_authkey, (u_int32 *)rpkt,
- LEN_PKT_NOMAC, (int)(rbufp->recv_length - LEN_PKT_NOMAC)));
+ LEN_PKT_NOMAC, (size_t)(rbufp->recv_length - LEN_PKT_NOMAC)));
if (has_mac && ntohl(rpkt->exten[0]) == sys_authkey &&
authdecrypt(sys_authkey, (u_int32 *)rpkt, LEN_PKT_NOMAC,
- (int)(rbufp->recv_length - LEN_PKT_NOMAC)))
+ (size_t)(rbufp->recv_length - LEN_PKT_NOMAC)))
is_authentic = 1;
if (debug)
printf("receive: authentication %s\n",
#else
fd_set fds;
#endif
- int fdc = 0;
+ SOCKET fdc = 0;
/*
* Do a poll to see if we have data
#else
fds = fdmask;
- n = select(maxfd, &fds, (fd_set *)0, (fd_set *)0, &tvzero);
+ n = select(maxfd, &fds, NULL, NULL, &tvzero);
/*
* Determine which socket received data
#include "ntp_libopts.h"
#include "ntpdc-opts.h"
+#include "safecast.h"
#ifdef SYS_VXWORKS
/* vxWorks needs mode flag -casey*/
static int openhost (const char *);
static int sendpkt (void *, size_t);
static void growpktdata (void);
-static int getresponse (int, int, int *, int *, char **, int);
-static int sendrequest (int, int, int, u_int, size_t, char *);
+static int getresponse (int, int, size_t *, size_t *, const char **, size_t);
+static int sendrequest (int, int, int, size_t, size_t, const char *);
static void getcmds (void);
static RETSIGTYPE abortcmd (int);
static void docmd (const char *);
#ifdef SYS_VXWORKS
if (connect(sockfd, (struct sockaddr *)&hostaddr,
- sizeof(hostaddr)) == -1) {
+ sizeof(hostaddr)) == -1)
#else
- if (connect(sockfd, ai->ai_addr, ai->ai_addrlen) == -1) {
+ if (connect(sockfd, ai->ai_addr, ai->ai_addrlen) == -1)
#endif /* SYS_VXWORKS */
+ {
error("connect");
exit(-1);
}
getresponse(
int implcode,
int reqcode,
- int *ritems,
- int *rsize,
- char **rdata,
- int esize
+ size_t *ritems,
+ size_t *rsize,
+ const char **rdata,
+ size_t esize
)
{
struct resp_pkt rpkt;
struct sock_timeval tvo;
- int items;
- int i;
- int size;
- int datasize;
+ size_t items;
+ size_t i;
+ size_t size;
+ size_t datasize;
char *datap;
char *tmp_data;
char haveseq[MAXSEQ+1];
int seq;
fd_set fds;
ssize_t n;
- int pad;
+ size_t pad;
/*
* This is pretty tricky. We may get between 1 and many packets
tvo = tvsout;
FD_SET(sockfd, &fds);
- n = select(sockfd+1, &fds, (fd_set *)0, (fd_set *)0, &tvo);
-
+ n = select(sockfd+1, &fds, NULL, NULL, &tvo);
if (n == -1) {
warning("select fails");
return -1;
*/
if (firstpkt) {
(void) fprintf(stderr,
- "%s: timed out, nothing received\n", currenthost);
+ "%s: timed out, nothing received\n",
+ currenthost);
return ERR_TIMEOUT;
} else {
(void) fprintf(stderr,
if ((size_t)datasize > (n-RESP_HEADER_SIZE)) {
if (debug)
printf(
- "Received items %d, size %d (total %d), data in packet is %zu\n",
+ "Received items %zu, size %zu (total %zu), data in packet is %zu\n",
items, size, datasize, n-RESP_HEADER_SIZE);
goto again;
}
*/
if (!firstpkt && size != *rsize) {
if (debug)
- printf("Received itemsize %d, previous %d\n",
+ printf("Received itemsize %zu, previous %zu\n",
size, *rsize);
goto again;
}
* So far, so good. Copy this data into the output array.
*/
if ((datap + datasize + (pad * items)) > (pktdata + pktdatasize)) {
- int offset = datap - pktdata;
+ size_t offset = datap - pktdata;
growpktdata();
*rdata = pktdata; /* might have been realloced ! */
datap = pktdata + offset;
int implcode,
int reqcode,
int auth,
- u_int qitems,
+ size_t qitems,
size_t qsize,
- char *qdata
+ const char *qdata
)
{
struct req_pkt qpkt;
u_long key_id;
l_fp ts;
l_fp * ptstamp;
- int maclen;
+ size_t maclen;
char * pass;
ZERO(qpkt);
get_systime(&ts);
L_ADD(&ts, &delay_time);
HTONL_FP(&ts, ptstamp);
- maclen = authencrypt(info_auth_keyid, (void *)&qpkt, reqsize);
+ maclen = authencrypt(
+ info_auth_keyid, (void *)&qpkt, size2int_chk(reqsize));
if (!maclen) {
fprintf(stderr, "Key not found\n");
return 1;
} else if (maclen != (int)(info_auth_hashlen + sizeof(keyid_t))) {
fprintf(stderr,
- "%d octet MAC, %zu expected with %zu octet digest\n",
+ "%zu octet MAC, %zu expected with %zu octet digest\n",
maclen, (info_auth_hashlen + sizeof(keyid_t)),
info_auth_hashlen);
return 1;
int implcode,
int reqcode,
int auth,
- int qitems,
- int qsize,
- char *qdata,
- int *ritems,
- int *rsize,
- char **rdata,
+ size_t qitems,
+ size_t qsize,
+ const char *qdata,
+ size_t *ritems,
+ size_t *rsize,
+ const char **rdata,
int quiet_mask,
int esize
)
tvzero.tv_sec = tvzero.tv_usec = 0;
FD_ZERO(&fds);
FD_SET(sockfd, &fds);
- res = select(sockfd+1, &fds, (fd_set *)0, (fd_set *)0, &tvzero);
-
+ res = select(sockfd+1, &fds, NULL, NULL, &tvzero);
if (res == -1) {
warning("polling select");
return -1;
)
{
register struct xcmd *cl;
- register int clen;
+ size_t clen;
int nmatch;
struct xcmd *nearmatch = NULL;
struct xcmd *clist;
return 0;
}
argp->uval *= 10;
- argp->uval += (cp - digits);
+ argp->uval += (u_long)(cp - digits);
} while (*(++np) != '\0');
if (isneg) {
extern int showhostnames;
extern int s_port;
-extern int doquery (int, int, int, int, int, char *, int *, int *, char **, int, int);
+extern int doquery (int, int, int, size_t, size_t, const char *, size_t *, size_t *, const char **, int, int);
extern const char * nntohost (sockaddr_u *);
/*
* utility functions
*/
-static int checkitems (int, FILE *);
-static int checkitemsize (int, int);
-static int check1item (int, FILE *);
+static int checkitems (size_t, FILE *);
+static int checkitemsize (size_t, size_t);
+static int check1item (size_t, FILE *);
/*
* Declarations for command handlers in here
*/
static int
checkitems(
- int items,
+ size_t items,
FILE *fp
)
{
*/
static int
checkitemsize(
- int itemsize,
- int expected
+ size_t itemsize,
+ size_t expected
)
{
if (itemsize != expected) {
(void) fprintf(stderr,
- "***Incorrect item size returned by remote host (%d should be %d)\n",
- itemsize, expected);
+ "***Incorrect item size returned by remote host (%lu should be %lu)\n",
+ (u_long)itemsize, (u_long)expected);
return 0;
}
return 1;
*/
static int
check1item(
- int items,
+ size_t items,
FILE *fp
)
{
return 0;
}
if (items > 1) {
- (void) fprintf(fp, "Expected one item in response, got %d\n",
- items);
+ (void) fprintf(fp, "Expected one item in response, got %lu\n",
+ (u_long)items);
return 0;
}
return 1;
{
struct info_peer_list *plist;
sockaddr_u paddr;
- int items;
- int itemsize;
+ size_t items;
+ size_t itemsize;
int res;
again:
struct info_peer_summary *plist;
sockaddr_u dstadr;
sockaddr_u srcadr;
- int items;
- int itemsize;
+ size_t items;
+ size_t itemsize;
int ntp_poll;
int res;
int c;
struct info_peer *pp;
/* 4 is the maximum number of peers which will fit in a packet */
struct info_peer_list *pl, plist[min(MAXARGS, 4)];
- int qitemlim;
- int qitems;
- int items;
- int itemsize;
+ size_t qitemlim;
+ size_t qitems;
+ size_t items;
+ size_t itemsize;
int res;
int sendsize;
/* 4 is the maximum number of peers which will fit in a packet */
struct info_peer_list *pl, plist[min(MAXARGS, 4)];
sockaddr_u src, dst;
- int qitemlim;
- int qitems;
- int items;
- int itemsize;
+ size_t qitemlim;
+ size_t qitems;
+ size_t items;
+ size_t itemsize;
int res;
- int sendsize;
+ size_t sendsize;
again:
if (impl_ver == IMPL_XNTPD)
)
{
struct info_loop *il;
- int items;
- int itemsize;
+ size_t items;
+ size_t itemsize;
int oneline = 0;
int res;
l_fp tempts;
{
struct info_sys *is;
sockaddr_u peeraddr;
- int items;
- int itemsize;
+ size_t items;
+ size_t itemsize;
int res;
l_fp tempts;
)
{
struct info_sys_stats *ss;
- int items;
- int itemsize;
+ size_t items;
+ size_t itemsize;
int res;
again:
)
{
struct info_io_stats *io;
- int items;
- int itemsize;
+ size_t items;
+ size_t itemsize;
int res;
again:
{
struct info_mem_stats *mem;
int i;
- int items;
- int itemsize;
+ size_t items;
+ size_t itemsize;
int res;
again:
)
{
struct info_timer_stats *tim;
- int items;
- int itemsize;
+ size_t items;
+ size_t itemsize;
int res;
again:
)
{
struct conf_peer cpeer;
- int items;
- int itemsize;
- char *dummy;
+ size_t items;
+ size_t itemsize;
+ const char *dummy;
u_long keyid;
u_int version;
u_char minpoll;
{
/* 8 is the maximum number of peers which will fit in a packet */
struct conf_unpeer *pl, plist[min(MAXARGS, 8)];
- int qitemlim;
- int qitems;
- int items;
- int itemsize;
- char *dummy;
+ size_t qitemlim;
+ size_t qitems;
+ size_t items;
+ size_t itemsize;
+ const char *dummy;
int res;
- int sendsize;
+ size_t sendsize;
again:
if (impl_ver == IMPL_XNTPD)
)
{
struct conf_sys_flags sys;
- int items;
- int itemsize;
- char *dummy;
+ size_t items;
+ size_t itemsize;
+ const char *dummy;
int res;
sys.flags = 0;
struct info_restrict *rl;
sockaddr_u resaddr;
sockaddr_u maskaddr;
- int items;
- int itemsize;
+ size_t items;
+ size_t itemsize;
int res;
int skip;
const char *addr;
)
{
struct conf_restrict cres;
- int items;
- int itemsize;
- char *dummy;
+ size_t items;
+ size_t itemsize;
+ const char *dummy;
u_int32 num;
u_long bit;
int i;
FILE *fp
)
{
- char *struct_star;
- struct info_monitor *ml;
- struct info_monitor_1 *m1;
- struct old_info_monitor *oml;
+ const char *struct_star;
+ const struct info_monitor *ml;
+ const struct info_monitor_1 *m1;
+ const struct old_info_monitor *oml;
sockaddr_u addr;
sockaddr_u dstadr;
- int items;
- int itemsize;
+ size_t items;
+ size_t itemsize;
int res;
int version = -1;
if (itemsize == sizeof(struct info_monitor_1) ||
itemsize == v4sizeof(struct info_monitor_1)) {
- m1 = (void *)struct_star;
+ m1 = (const void*)struct_star;
fprintf(fp,
"remote address port local address count m ver rstr avgint lstint\n");
fprintf(fp,
} else if (itemsize == sizeof(struct info_monitor) ||
itemsize == v4sizeof(struct info_monitor)) {
- ml = (void *) struct_star;
+ ml = (const void *)struct_star;
fprintf(fp,
" address port count mode ver rstr avgint lstint\n");
fprintf(fp,
}
} else if (itemsize == sizeof(struct old_info_monitor)) {
- oml = (void *)struct_star;
+ oml = (const void *)struct_star;
fprintf(fp,
" address port count mode version lasttime firsttime\n");
fprintf(fp,
)
{
struct reset_flags rflags;
- int items;
- int itemsize;
- char *dummy;
+ size_t items;
+ size_t itemsize;
+ const char *dummy;
int i;
size_t res;
int err;
{
/* 8 is the maximum number of peers which will fit in a packet */
struct conf_unpeer *pl, plist[min(MAXARGS, 8)];
- int qitemlim;
- int qitems;
- int items;
- int itemsize;
- char *dummy;
+ size_t qitemlim;
+ size_t qitems;
+ size_t items;
+ size_t itemsize;
+ const char *dummy;
int res;
- int sendsize;
+ size_t sendsize;
again:
if (impl_ver == IMPL_XNTPD)
FILE *fp
)
{
- int items;
- int itemsize;
- char *dummy;
+ size_t items;
+ size_t itemsize;
+ const char *dummy;
int res;
again:
{
u_long keyids[MAXARGS];
size_t i;
- int items;
- int itemsize;
- char *dummy;
+ size_t items;
+ size_t itemsize;
+ const char *dummy;
int ritems;
int res;
)
{
struct info_auth *ia;
- int items;
- int itemsize;
+ size_t items;
+ size_t itemsize;
int res;
again:
FILE *fp
)
{
- int i;
+ size_t i;
struct info_trap *it;
sockaddr_u trap_addr, local_addr;
- int items;
- int itemsize;
+ size_t items;
+ size_t itemsize;
int res;
again:
)
{
struct conf_trap ctrap;
- int items;
- int itemsize;
- char *dummy;
+ size_t items;
+ size_t itemsize;
+ const char *dummy;
int res;
int sendsize;
)
{
u_long key;
- int items;
- int itemsize;
- char *dummy;
+ size_t items;
+ size_t itemsize;
+ const char *dummy;
int res;
)
{
struct info_control *ic;
- int items;
- int itemsize;
+ size_t items;
+ size_t itemsize;
int res;
again:
struct info_clock *cl;
/* 8 is the maximum number of clocks which will fit in a packet */
u_long clist[min(MAXARGS, 8)];
- int qitemlim;
- int qitems;
- int items;
- int itemsize;
+ size_t qitemlim;
+ size_t qitems;
+ size_t items;
+ size_t itemsize;
int res;
l_fp ts;
struct clktype *clk;
)
{
struct conf_fudge fudgedata;
- int items;
- int itemsize;
- char *dummy;
+ size_t items;
+ size_t itemsize;
+ const char *dummy;
l_fp ts;
int res;
long val;
/* 8 is the maximum number of clocks which will fit in a packet */
u_long clist[min(MAXARGS, 8)];
u_int32 ltemp;
- int qitemlim;
- int qitems;
- int items;
- int itemsize;
+ size_t qitemlim;
+ size_t qitems;
+ size_t items;
+ size_t itemsize;
int res;
int needsp;
l_fp ts;
)
{
struct info_kernel *ik;
- int items;
- int itemsize;
+ size_t items;
+ size_t itemsize;
int res;
unsigned status;
double tscale = 1e-6;
iflist(
FILE *fp,
struct info_if_stats *ifs,
- int items,
- int itemsize,
+ size_t items,
+ size_t itemsize,
int res
)
{
)
{
struct info_if_stats *ifs;
- int items;
- int itemsize;
+ size_t items;
+ size_t itemsize;
int res;
res = doquery(impl_ver, REQ_IF_STATS, 1, 0, 0, (char *)NULL, &items,
)
{
struct info_if_stats *ifs;
- int items;
- int itemsize;
+ size_t items;
+ size_t itemsize;
int res;
res = doquery(impl_ver, REQ_IF_RELOAD, 1, 0, 0, (char *)NULL, &items,
{
char * name;
char * value;
- int idatalen;
+ size_t idatalen;
value = NULL;
idatalen = (int)datalen;
{
const char *datap;
int res;
- int dsize;
- u_short rstatus;
+ size_t dsize;
+ u_short rstatus;
if ( numhosts > 0 )
res = doquery(VARSET,association,0,0, (char *)0, &rstatus, &dsize, &datap);
{
const char * datap;
int res;
- int dsize;
+ size_t dsize;
u_short rstatus;
res = doquery(CTL_OP_READVAR, associd, 0, 0, NULL, &rstatus,
{
const char * datap;
int res;
- int i_dsize;
size_t dsize;
u_short rstatus;
res = doquery(CTL_OP_READVAR, 0, 0, 0, NULL, &rstatus,
- &i_dsize, &datap);
+ &dsize, &datap);
if (res != 0)
return 0;
- if (i_dsize == 0) {
+ if (dsize == 0) {
if (numhosts > 1)
fprintf(stderr, "server=%s ", currenthost);
fprintf(stderr, "***No sysvar information returned\n");
return 0;
} else {
- dsize = max(0, i_dsize);
dsize = min(dsize, maxsize);
memcpy(resultbuf, datap, dsize);
}
{
const char *datap;
int res;
- int dsize;
+ size_t dsize;
u_short rstatus;
res = ntpq_doquerylist(ntpq_varlist, CTL_OP_READCLOCK, associd,
extern int ntpq_dogetassoc(void);
extern char ntpq_decodeaddrtype(sockaddr_u *sock);
extern int ntpq_doquerylist(struct ntpq_varlist *, int, associd_t, int,
- u_short *, int *, const char **datap);
+ u_short *, size_t *, const char **datap);
associd_t associd,
int auth,
u_short *rstatus,
- int *dsize,
+ size_t *dsize,
const char **datap
)
{
static void doaddvlist (struct varlist *, const char *);
static void dormvlist (struct varlist *, const char *);
static void doclearvlist (struct varlist *);
-static void makequerydata (struct varlist *, int *, char *);
+static void makequerydata (struct varlist *, size_t *, char *);
static int doquerylist (struct varlist *, int, associd_t, int,
- u_short *, int *, const char **);
+ u_short *, size_t *, const char **);
static void doprintvlist (struct varlist *, FILE *);
static void addvars (struct parse *, FILE *);
static void rmvars (struct parse *, FILE *);
static void pstats (struct parse *, FILE *);
static long when (l_fp *, l_fp *, l_fp *);
static char * prettyinterval (char *, size_t, long);
-static int doprintpeers (struct varlist *, int, int, int, const char *, FILE *, int);
+static int doprintpeers (struct varlist *, int, int, size_t, const char *, FILE *, int);
static int dogetpeers (struct varlist *, associd_t, FILE *, int);
static void dopeers (int, FILE *, int);
static void peers (struct parse *, FILE *);
)
{
struct varlist *vl;
- int len;
+ size_t len;
char *name;
char *value;
)
{
struct varlist *vl;
- int len;
+ size_t len;
char *name;
char *value;
static void
makequerydata(
struct varlist *vlist,
- int *datalen,
+ size_t *datalen,
char *data
)
{
register struct varlist *vl;
register char *cp, *cpend;
- register int namelen, valuelen;
- register int totallen;
+ register size_t namelen, valuelen;
+ register size_t totallen;
cp = data;
cpend = data + *datalen;
cp += valuelen;
}
}
- *datalen = cp - data;
+ *datalen = (size_t)(cp - data);
}
associd_t associd,
int auth,
u_short *rstatus,
- int *dsize,
+ size_t *dsize,
const char **datap
)
{
char data[CTL_MAX_DATA_LEN];
- int datalen;
+ size_t datalen;
datalen = sizeof(data);
makequerydata(vlist, &datalen, data);
{
const char *datap;
int res;
- int dsize;
+ size_t dsize;
u_short rstatus;
int quiet;
const char *datap;
int res;
associd_t associd;
- int dsize;
+ size_t dsize;
u_short rstatus;
if (pcmd->nargs == 0) {
)
{
associd_t associd;
- u_int tmpcount;
- u_int u;
+ size_t tmpcount;
+ size_t u;
int type;
struct varlist tmplist[MAXLIST];
int res;
associd_t associd;
int type;
- int dsize;
+ size_t dsize;
u_short rstatus;
struct varlist tmplist[MAXLIST];
const char *datap;
const u_short *pus;
int res;
- int dsize;
+ size_t dsize;
u_short rstatus;
res = doquery(CTL_OP_READSTAT, 0, 0, 0, (char *)0, &rstatus,
if (numhosts > 1)
fprintf(stderr, "server=%s ", currenthost);
fprintf(stderr,
- "***Server returned %d octets, should be multiple of 4\n",
+ "***Server returned %zu octets, should be multiple of 4\n",
dsize);
return 0;
}
{
const char *datap;
int res;
- int dsize;
+ size_t dsize;
u_short rstatus;
if (0 == pcmd->nargs)
if (0 == dsize)
fprintf(fp, "(no response message, curiously)");
else
- fprintf(fp, "%.*s", dsize, datap);
+ fprintf(fp, "%.*s", (int)dsize, datap); /* cast is wobbly */
}
struct varlist *pvl,
int associd,
int rstatus,
- int datalen,
+ size_t datalen,
const char *data,
FILE *fp,
int af
char *name;
char *value = NULL;
int c;
- int len;
+ size_t len;
int have_srchost;
int have_dstadr;
int have_da_rid;
{
const char *datap;
int res;
- int dsize;
+ size_t dsize;
u_short rstatus;
#ifdef notdef
{
const char *cfgcmd;
u_short rstatus;
- int rsize;
+ size_t rsize;
const char *rdata;
char *resp;
int res;
"Keyword = %s\n"
"Command = %s\n", pcmd->keyword, cfgcmd);
- res = doquery(CTL_OP_CONFIGURE, 0, 1, strlen(cfgcmd), cfgcmd,
+ res = doquery(CTL_OP_CONFIGURE, 0, 1,
+ strlen(cfgcmd), cfgcmd,
&rstatus, &rsize, &rdata);
if (res != 0)
)
{
u_short rstatus;
- int rsize;
+ size_t rsize;
const char *rdata;
int res;
FILE *config_fd;
rsize--;
if (rsize > 0 && '\r' == rdata[rsize - 1])
rsize--;
- printf("Line No: %d %.*s: %s", i, rsize, rdata,
+ printf("Line No: %d %.*s: %s", i, (int)rsize, rdata, /* cast is wobbly */
config_cmd);
}
printf("Done sending file\n");
const char nonce_eq[] = "nonce=";
int qres;
u_short rstatus;
- int rsize;
+ size_t rsize;
const char * rdata;
- int chars;
+ size_t chars;
/*
* Retrieve a nonce specific to this client to demonstrate to
if ((size_t)rsize <= sizeof(nonce_eq) - 1 ||
strncmp(rdata, nonce_eq, sizeof(nonce_eq) - 1)) {
fprintf(stderr, "unexpected nonce response format: %.*s\n",
- rsize, rdata);
+ (int)rsize, rdata); /* cast is wobbly */
return FALSE;
}
chars = rsize - (sizeof(nonce_eq) - 1);
char req_buf[CTL_MAX_DATA_LEN];
char *req;
char *req_end;
- int chars;
+ size_t chars;
int qres;
u_short rstatus;
- int rsize;
+ size_t rsize;
const char *rdata;
int limit;
int frags;
if (debug)
fprintf(stderr, "READ_MRU parms: %s\n", req_buf);
- qres = doqueryex(CTL_OP_READ_MRU, 0, 0, strlen(req_buf),
- req_buf, &rstatus, &rsize, &rdata, TRUE);
+ qres = doqueryex(CTL_OP_READ_MRU, 0, 0,
+ strlen(req_buf), req_buf,
+ &rstatus, &rsize, &rdata, TRUE);
if (CERR_UNKNOWNVAR == qres && ri > 0) {
/*
const char up_fmt[] = "up.%u"; /* uptime */
const char * datap;
int qres;
- int dsize;
+ size_t dsize;
u_short rstatus;
char * tag;
char * val;
const int qdata_chars = COUNTOF(qdata) - 1;
const char * datap;
int qres;
- int dsize;
+ size_t dsize;
u_short rstatus;
char * tag;
char * val;
char tagbuf[32];
vdc *pvdc;
u_short rstatus;
- int rsize;
+ size_t rsize;
const char *rdata;
int qres;
char *tag;
#include "ntp_libopts.h"
#include "ntpq-opts.h"
+#include "safecast.h"
#ifdef SYS_VXWORKS /* vxWorks needs mode flag -casey*/
# define open(name, flags) open(name, flags, 0777)
static int openhost (const char *, int);
static void dump_hex_printable(const void *, size_t);
static int sendpkt (void *, size_t);
-static int getresponse (int, int, u_short *, int *, const char **, int);
-static int sendrequest (int, associd_t, int, int, const char *);
+static int getresponse (int, int, u_short *, size_t *, const char **, int);
+static int sendrequest (int, associd_t, int, size_t, const char *);
static char * tstflags (u_long);
#ifndef BUILD_AS_LIB
static void getcmds (void);
__attribute__((__format__(__printf__, 1, 2)));
static u_long getkeyid (const char *);
static void atoascii (const char *, size_t, char *, size_t);
-static void cookedprint (int, int, const char *, int, int, FILE *);
-static void rawprint (int, int, const char *, int, int, FILE *);
+static void cookedprint (int, size_t, const char *, int, int, FILE *);
+static void rawprint (int, size_t, const char *, int, int, FILE *);
static void startoutput (void);
static void output (FILE *, const char *, const char *);
static void endoutput (FILE *);
sizeof(hostaddr)) == -1)
#else
(connect(sockfd, (struct sockaddr *)ai->ai_addr,
- ai->ai_addrlen) == -1)
+ ai->ai_addrlen) == -1)
#endif /* SYS_VXWORKS */
- {
+ {
error("connect");
freeaddrinfo(ai);
return 0;
if (debug >= 3)
printf("Sending %zu octets\n", xdatalen);
- if (send(sockfd, xdata, (size_t)xdatalen, 0) == -1) {
+ if (send(sockfd, xdata, xdatalen, 0) == -1) {
warning("write to %s failed", currenthost);
return -1;
}
int opcode,
int associd,
u_short *rstatus,
- int *rsize,
+ size_t *rsize,
const char **rdata,
int timeo
)
tvo = tvsout;
FD_SET(sockfd, &fds);
- n = select(sockfd + 1, &fds, NULL, NULL, &tvo);
-
+ n = select(sockfd+1, &fds, NULL, NULL, &tvo);
if (n == -1) {
warning("select fails");
return -1;
int opcode,
associd_t associd,
int auth,
- int qsize,
+ size_t qsize,
const char *qdata
)
{
struct ntp_control qpkt;
- int pktsize;
+ size_t pktsize;
u_long key_id;
char * pass;
- int maclen;
+ size_t maclen;
/*
* Check to make sure the data will fit in one packet
*/
if (qsize > CTL_MAX_DATA_LEN) {
fprintf(stderr,
- "***Internal error! qsize (%d) too large\n",
+ "***Internal error! qsize (%zu) too large\n",
qsize);
return 1;
}
return 1;
} else if ((size_t)maclen != (info_auth_hashlen + sizeof(keyid_t))) {
fprintf(stderr,
- "%d octet MAC, %zu expected with %zu octet digest\n",
+ "%zu octet MAC, %zu expected with %zu octet digest\n",
maclen, (info_auth_hashlen + sizeof(keyid_t)),
info_auth_hashlen);
return 1;
int opcode,
associd_t associd,
int auth,
- int qsize,
+ size_t qsize,
const char *qdata,
u_short *rstatus,
- int *rsize,
+ size_t *rsize,
const char **rdata
)
{
int opcode,
associd_t associd,
int auth,
- int qsize,
+ size_t qsize,
const char *qdata,
u_short *rstatus,
- int *rsize,
+ size_t *rsize,
const char **rdata,
int quiet
)
)
{
struct xcmd *cl;
- int clen;
+ size_t clen;
int nmatch;
struct xcmd *nearmatch = NULL;
struct xcmd *clist;
*/
void
makeascii(
- int length,
+ size_t length,
const char *data,
FILE *fp
)
*/
int
nextvar(
- int *datalen,
+ size_t *datalen,
const char **datap,
char **vname,
char **vvalue
if (cp < cpend)
cp++;
*datap = cp;
- *datalen = cpend - cp;
+ *datalen = size2int_sat(cpend - cp);
*vvalue = NULL;
return 1;
}
if (np < cpend && ',' == *np)
np++;
*datap = np;
- *datalen = cpend - np;
+ *datalen = size2int_sat(cpend - np);
*vvalue = value;
return 1;
}
*/
void
printvars(
- int length,
+ size_t length,
const char *data,
int status,
int sttype,
static void
rawprint(
int datatype,
- int length,
+ size_t length,
const char *data,
int status,
int quiet,
const char *value
)
{
- size_t len;
+ int len;
/* strlen of "name=value" */
- len = strlen(name) + 1 + strlen(value);
+ len = size2int_sat(strlen(name) + 1 + strlen(value));
if (out_chars != 0) {
out_chars += 2;
l_fp *lfp
)
{
- register char *bp;
- register char *cp;
- register int i;
- register int len;
+ char *bp;
+ char *cp;
+ size_t i;
+ size_t len;
char buf[256];
bp = buf;
static void
cookedprint(
int datatype,
- int length,
+ size_t length,
const char *data,
int status,
int quiet,
}
assoc_cache = erealloc_zero(assoc_cache, new_sz, prior_sz);
prior_sz = new_sz;
- assoc_cache_slots = new_sz / sizeof(assoc_cache[0]);
+ assoc_cache_slots = (u_int)(new_sz / sizeof(assoc_cache[0]));
}
extern void sortassoc (void);
extern void show_error_msg (int, associd_t);
extern int dogetassoc (FILE *);
-extern int doquery (int, associd_t, int, int, const char *,
- u_short *, int *, const char **);
-extern int doqueryex (int, associd_t, int, int, const char *,
- u_short *, int *, const char **, int);
+extern int doquery (int, associd_t, int, size_t, const char *,
+ u_short *, size_t *, const char **);
+extern int doqueryex (int, associd_t, int, size_t, const char *,
+ u_short *, size_t *, const char **, int);
extern const char * nntohost (sockaddr_u *);
extern const char * nntohost_col (sockaddr_u *, size_t, int);
extern const char * nntohostp (sockaddr_u *);
extern int decodets (char *, l_fp *);
extern int decodeuint (char *, u_long *);
-extern int nextvar (int *, const char **, char **, char **);
+extern int nextvar (size_t *, const char **, char **, char **);
extern int decodetime (char *, l_fp *);
-extern void printvars (int, const char *, int, int, int, FILE *);
+extern void printvars (size_t, const char *, int, int, int, FILE *);
extern int decodeint (char *, long *);
-extern void makeascii (int, const char *, FILE *);
+extern void makeascii (size_t, const char *, FILE *);
extern const char * trunc_left (const char *, size_t);
extern const char * trunc_right(const char *, size_t);
* Unix and implemented in the Windows port similarly to
* refclock_open().
*/
-extern int tty_open(char *, int, int);
+extern int tty_open(const char *, int, int);
/*
* disable use of __declspec(dllexport) by libisc routines
struct refclockio; /* in ntp_refclock.h but inclusion here triggers problems */
extern int io_completion_port_add_clock_io(struct refclockio *rio);
extern void io_completion_port_remove_clock_io(struct refclockio *rio);
-extern int io_completion_port_sendto(int, void *, size_t, sockaddr_u *);
+extern int io_completion_port_sendto(SOCKET, void *, size_t, sockaddr_u *);
extern int GetReceivedBuffers(void);
}
/* Add the Event-ID message-file name to the subkey. */
- bSuccess = RegSetValueEx(hk, /* subkey handle */
- "EventMessageFile", /* value name */
- 0, /* must be zero */
- REG_EXPAND_SZ, /* value type */
- (LPBYTE) pszMsgDLL, /* address of value data */
- strlen(pszMsgDLL) + 1); /* length of value data */
+ bSuccess = RegSetValueEx(hk, /* subkey handle */
+ "EventMessageFile", /* value name */
+ 0, /* must be zero */
+ REG_EXPAND_SZ, /* value type */
+ (LPBYTE) pszMsgDLL, /* address of value data */
+ (DWORD)(strlen(pszMsgDLL) + 1)); /* length of value data */
if(bSuccess != ERROR_SUCCESS)
{
PERR("RegSetValueEx");
* work by duplicating the handle for the 2nd open, allowing
* refclock_atom to share a GPS refclock's comm port.
*/
-HANDLE common_serial_open(
- char * dev,
- char ** pwindev
+HANDLE
+common_serial_open(
+ const char * dev,
+ char ** pwindev
)
{
- char * windev;
- HANDLE handle;
- size_t unit;
- size_t prev_c_hnds;
- size_t opens;
- char * pch;
+ char * windev;
+ HANDLE handle;
+ size_t unit;
+ size_t prev_c_hnds;
+ size_t opens;
+ const char * pch;
/*
* This is odd, but we'll take any unix device path
* file descriptor if success and -1 if failure.
*/
int tty_open(
- char *dev, /* device name pointer */
+ const char *dev, /* device name pointer */
int access, /* O_RDWR */
int mode /* unused */
)
return -1;
}
- return (int)_open_osfhandle((int)Handle, _O_TEXT);
+ return (int)_open_osfhandle((intptr_t)Handle, _O_TEXT);
}
* This routine opens a serial port for I/O and sets default options. It
* returns the file descriptor or -1 indicating failure.
*/
-int refclock_open(
- char * dev, /* device name pointer */
- u_int speed, /* serial port speed (code) */
- u_int flags /* line discipline flags */
+int
+refclock_open(
+ const char * dev, /* device name pointer */
+ u_int speed, /* serial port speed (code) */
+ u_int flags /* line discipline flags */
)
{
char * windev;
translate = (LDISC_RAW & flags)
? 0
: _O_TEXT;
- fd = _open_osfhandle((int)h, translate);
+ fd = _open_osfhandle((intptr_t)h, translate);
/* refclock_open() long returned 0 on failure, avoid it. */
if (0 == fd) {
fd = _dup(0);
#include <stdio.h>
#include <process.h>
#include <syslog.h>
+#include <limits.h>
#include "ntpd.h"
#include "ntp_machine.h"
*/
int
io_completion_port_sendto(
- int fd,
+ SOCKET fd,
void * pkt,
size_t len,
sockaddr_u * dest
int errval;
int AddrLen;
+ if (len > INT_MAX)
+ len = INT_MAX;
wsabuf.buf = (void *)pkt;
- wsabuf.len = len;
+ wsabuf.len = (DWORD)len;
AddrLen = SOCKLEN(dest);
octets_sent = 0;
return -1;
}
- if (len != (int)octets_sent) {
+ if ((DWORD)len != octets_sent) {
msyslog(LOG_ERR, "WSASendTo(%s) sent %u of %d octets",
stoa(dest), octets_sent, len);
SetLastError(ERROR_BAD_LENGTH);
DPRINTF(4, ("sendto %s %d octets\n", stoa(dest), len));
- return len;
+ return (int)len;
}
return (full_recvbuffs()); /* get received buffers */
}
-#else
+#else /*defined(HAVE_IO_COMPLETION_PORT) */
static int NonEmptyCompilationUnit;
-#endif
+#endif /*!defined(HAVE_IO_COMPLETION_PORT) */
SuppressStartupBanner="true"
DebugInformationFormat="3"
CompileAs="1"
- DisableSpecificWarnings="4996"
+ DisableSpecificWarnings="4996;4267;4244"
/>
<Tool
Name="VCLinkerTool"
/>
</Configuration>
<Configuration
- Name="Debug|Win32"
+ Name="Release|x64"
ConfigurationType="1"
- InheritedPropertySheets="..\debug.vsprops;..\common.vsprops"
+ InheritedPropertySheets="..\release-x64.vsprops;..\common.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="2"
/>
<Tool
Name="VCMIDLTool"
+ TargetEnvironment="3"
TypeLibraryName="$(IntDir)ntpd.tlb"
HeaderFileName=""
/>
/>
<Tool
Name="VCResourceCompilerTool"
- PreprocessorDefinitions="_DEBUG"
+ PreprocessorDefinitions="NDEBUG"
Culture="1033"
/>
<Tool
/>
</Configuration>
<Configuration
- Name="Release|x64"
+ Name="Debug|Win32"
ConfigurationType="1"
- InheritedPropertySheets="..\release-x64.vsprops;..\common.vsprops"
+ InheritedPropertySheets="..\debug.vsprops;..\common.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="2"
/>
<Tool
Name="VCMIDLTool"
- TargetEnvironment="3"
TypeLibraryName="$(IntDir)ntpd.tlb"
HeaderFileName=""
/>
/>
<Tool
Name="VCResourceCompilerTool"
- PreprocessorDefinitions="NDEBUG"
+ PreprocessorDefinitions="_DEBUG"
Culture="1033"
/>
<Tool
RelativePath="..\..\..\..\include\ieee754io.h"
>
</File>
- <File
- RelativePath="..\..\..\..\lib\isc\win32\include\isc\net.h"
- >
- </File>
<File
RelativePath="..\..\..\..\lib\isc\win32\include\isc\int.h"
>
RelativePath="..\..\..\..\include\mbg_gps166.h"
>
</File>
+ <File
+ RelativePath="..\..\..\..\lib\isc\win32\include\isc\net.h"
+ >
+ </File>
<File
RelativePath="..\..\..\..\lib\isc\include\isc\netaddr.h"
>
/>
</FileConfiguration>
<FileConfiguration
- Name="Debug|Win32"
+ Name="Release|x64"
>
<Tool
Name="VCCustomBuildTool"
/>
</FileConfiguration>
<FileConfiguration
- Name="Release|x64"
+ Name="Debug|Win32"
>
<Tool
Name="VCCustomBuildTool"
<File
RelativePath="..\..\..\..\ntpd\refclock_arc.c"
>
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ DisableSpecificWarnings="4307"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|x64"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ DisableSpecificWarnings="4307"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ DisableSpecificWarnings="4307"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Debug|x64"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ DisableSpecificWarnings="4307"
+ />
+ </FileConfiguration>
</File>
<File
RelativePath="..\..\..\..\ntpd\refclock_as2201.c"
/>
</FileConfiguration>
<FileConfiguration
- Name="Debug|Win32"
+ Name="Release|x64"
ExcludedFromBuild="true"
>
<Tool
/>
</FileConfiguration>
<FileConfiguration
- Name="Release|x64"
+ Name="Debug|Win32"
ExcludedFromBuild="true"
>
<Tool
/>
</FileConfiguration>
<FileConfiguration
- Name="Debug|Win32"
+ Name="Release|x64"
>
<Tool
Name="VCCustomBuildTool"
/>
</FileConfiguration>
<FileConfiguration
- Name="Release|x64"
+ Name="Debug|Win32"
>
<Tool
Name="VCCustomBuildTool"
<SuppressStartupBanner>true</SuppressStartupBanner>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<CompileAs>CompileAsC</CompileAs>
- <DisableSpecificWarnings>4996;%(DisableSpecificWarnings)</DisableSpecificWarnings>
+ <DisableSpecificWarnings>4996;4267;4244;%(DisableSpecificWarnings)</DisableSpecificWarnings>
<WarningLevel>Level3</WarningLevel>
</ClCompile>
<Link>
<ClInclude Include="..\..\..\..\include\ntp_types.h" />
<ClInclude Include="..\..\..\..\include\ntp_unixtime.h" />
<ClInclude Include="..\..\..\..\include\recvbuff.h" />
+ <ClInclude Include="..\..\..\..\include\safecast.h" />
<ClInclude Include="..\..\..\..\include\timespecops.h" />
<ClInclude Include="..\..\..\..\include\timetoa.h" />
<ClInclude Include="..\..\..\..\include\timevalops.h" />
<ClInclude Include="..\..\..\..\lib\isc\win32\include\isc\win32os.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="..\..\..\..\include\safecast.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="..\..\libntp\messages.mc">
<ClCompile Include="..\..\..\..\ntpd\rc_cmdlength.c" />
<ClCompile Include="..\..\..\..\ntpd\refclock_acts.c" />
<ClCompile Include="..\..\..\..\ntpd\refclock_arbiter.c" />
- <ClCompile Include="..\..\..\..\ntpd\refclock_arc.c" />
+ <ClCompile Include="..\..\..\..\ntpd\refclock_arc.c">
+ <DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='DebugXP|Win32'">4307;%(DisableSpecificWarnings)</DisableSpecificWarnings>
+ <DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='ReleaseXP|Win32'">4307;%(DisableSpecificWarnings)</DisableSpecificWarnings>
+ <DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">4307;%(DisableSpecificWarnings)</DisableSpecificWarnings>
+ <DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">4307;%(DisableSpecificWarnings)</DisableSpecificWarnings>
+ <DisableSpecificWarnings Condition="'$(Configuration)|$(Platform)'=='Release|x64'">4307;%(DisableSpecificWarnings)</DisableSpecificWarnings>
+ </ClCompile>
<ClCompile Include="..\..\..\..\ntpd\refclock_as2201.c" />
<ClCompile Include="..\..\..\..\ntpd\refclock_atom.c" />
<ClCompile Include="..\..\..\..\ntpd\refclock_bancomm.c" />
return PACKET_UNUSEABLE;
}
/* Note: pkt_len must be a multiple of 4 at this point! */
- packet_end = (u_int32*)((char*)rpkt + pkt_len);
+ packet_end = (void*)((char*)rpkt + pkt_len);
exten_end = skip_efields(rpkt->exten, packet_end);
if (NULL == exten_end) {
msyslog(LOG_ERR,
const keyid_t KEYNO = 5;
const char* KEY = "52a";
- TEST_ASSERT_TRUE(authusekey(KEYNO, KEYTYPE, (u_char*)KEY));
+ TEST_ASSERT_TRUE(authusekey(KEYNO, KEYTYPE, (const u_char*)KEY));
}
void
}
+void
tearDown(void) {
restrict_u *empty_restrict = malloc(sizeof(restrict_u));
memset(empty_restrict, 0, sizeof(restrict_u));
{
progname = argv[0];
UnityBegin("ntp_restrict.c");
- RUN_TEST(test_RestrictionsAreEmptyAfterInit, 59);
- RUN_TEST(test_ReturnsCorrectDefaultRestrictions, 85);
- RUN_TEST(test_HackingDefaultRestriction, 96);
- RUN_TEST(test_CantRemoveDefaultEntry, 119);
- RUN_TEST(test_AddingNewRestriction, 130);
- RUN_TEST(test_TheMostFittingRestrictionIsMatched, 143);
- RUN_TEST(test_DeletedRestrictionIsNotMatched, 165);
- RUN_TEST(test_RestrictUnflagWorks, 189);
+ RUN_TEST(test_RestrictionsAreEmptyAfterInit, 60);
+ RUN_TEST(test_ReturnsCorrectDefaultRestrictions, 86);
+ RUN_TEST(test_HackingDefaultRestriction, 97);
+ RUN_TEST(test_CantRemoveDefaultEntry, 120);
+ RUN_TEST(test_AddingNewRestriction, 131);
+ RUN_TEST(test_TheMostFittingRestrictionIsMatched, 144);
+ RUN_TEST(test_DeletedRestrictionIsNotMatched, 166);
+ RUN_TEST(test_RestrictUnflagWorks, 190);
return (UnityEnd());
}
extern void test_write_all(void);
extern void test_send_packet(void);
extern void test_recv_packet(void);
-extern void test_send_via_ntp_signd();
+extern void test_send_via_ntp_signd(void);
//=======Test Reset Option=====
{
progname = argv[0];
UnityBegin("t-ntp_signd.c");
- RUN_TEST(test_connect_incorrect_socket, 49);
- RUN_TEST(test_connect_correct_socket, 54);
- RUN_TEST(test_write_all, 74);
- RUN_TEST(test_send_packet, 84);
- RUN_TEST(test_recv_packet, 93);
- RUN_TEST(test_send_via_ntp_signd, 104);
+ RUN_TEST(test_connect_incorrect_socket, 48);
+ RUN_TEST(test_connect_correct_socket, 49);
+ RUN_TEST(test_write_all, 50);
+ RUN_TEST(test_send_packet, 51);
+ RUN_TEST(test_recv_packet, 52);
+ RUN_TEST(test_send_via_ntp_signd, 53);
return (UnityEnd());
}
void test_keywordIncorrectToken(void){
- char * temp = keyword(999);
+ const char * temp = keyword(999);
//printf("%s\n",temp);
TEST_ASSERT_EQUAL_STRING("(keyword not found)",temp);
}
void test_keywordServerToken(void){
- char * temp = keyword(T_Server);
+ const char * temp = keyword(T_Server);
//printf("%s",temp); //143 or 401 ?
TEST_ASSERT_EQUAL_STRING("server",temp);
}
temp = is_EOC(';');
TEST_ASSERT_TRUE(temp);
}
- temp = is_EOC("A");
+ temp = is_EOC('A');
TEST_ASSERT_FALSE(temp);
temp = is_EOC('1');
TEST_ASSERT_FALSE(temp);
//END OF MOCKED FUNCTIONS
-int isGE(int a,int b){
+static int
+isGE(int a,int b){
if(a >= b) {return 1;}
else {return 0;}
}
+extern void test_connect_incorrect_socket(void);
+extern void test_connect_correct_socket(void);
+extern void test_write_all(void);
+extern void test_send_packet(void);
+extern void test_recv_packet(void);
+extern void test_send_via_ntp_signd(void);
+
void
-test_connect_incorrect_socket(void){
+test_connect_incorrect_socket(void)
+{
TEST_ASSERT_EQUAL(-1, ux_socket_connect(NULL));
}
void
-test_connect_correct_socket(void){
-
-
-
+test_connect_correct_socket(void)
+{
int temp = ux_socket_connect("/socket");
//risky, what if something is listening on :123, or localhost isnt 127.0.0.1?
void
-test_write_all(void){
+test_write_all(void)
+{
int fd = ux_socket_connect("/socket");
TEST_ASSERT_TRUE(isGE(fd,0));
char * str = "TEST123";
void
-test_send_packet(void){
+test_send_packet(void)
+{
int fd = ux_socket_connect("/socket");
char * str2 = "PACKET12345";
int temp = send_packet(fd, str2, strlen(str2));
void
-test_recv_packet(void){
+test_recv_packet(void)
+{
int fd = ux_socket_connect("/socket");
- int size = 256;
- char str[size];
+ uint32_t size = 256;
+ char *str = NULL;
int temp = recv_packet(fd, &str, &size);
send_packet(fd, str, strlen(str));
+ free(str);
TEST_ASSERT_EQUAL(0,temp); //0 because nobody sent us anything (yet!)
}
void
-test_send_via_ntp_signd(){
-
+test_send_via_ntp_signd(void)
+{
struct recvbuf *rbufp = (struct recvbuf *) malloc(sizeof(struct recvbuf));
int xmode = 1;
keyid_t xkeyid = 12345;
{
progname = argv[0];
UnityBegin("uglydate.c");
- RUN_TEST(test_ConstantDateTime, 9);
+ RUN_TEST(test_ConstantDateTime, 8);
return (UnityEnd());
}
//#include "ntp_stdlib.h"
//#include "libntptest.h"
+extern void test_ConstantDateTime(void);
+
void
-test_ConstantDateTime(void) {
+test_ConstantDateTime(void)
+{
const u_int32 HALF = 2147483648UL;
l_fp e_time = {{3485080800UL}, HALF}; // 2010-06-09 14:00:00.5
failed = ( 4 != len );
if ( failed || verbose )
- printf( "remoteconfig_cmdlength(\"%s\") returned %d, expected %d: %s\n",
+ printf( "remoteconfig_cmdlength(\"%s\") returned %llu, expected %u: %s\n",
string,
- len,
+ (unsigned long long)len,
4,
failed ? "NO <<" : "yes" );
failed = ( 3 != len );
if ( failed || verbose )
- printf( "remoteconfig_cmdlength(\"%s\") returned %d, expected %d: %s\n",
+ printf( "remoteconfig_cmdlength(\"%s\") returned %llu, expected %u: %s\n",
string,
- len,
+ (unsigned long long)len,
3,
failed ? "NO <<" : "yes" );
failed = ( 14 != len );
if ( failed || verbose )
- printf( "remoteconfig_cmdlength(\"%s\") returned %d, expected %d: %s\n",
+ printf( "remoteconfig_cmdlength(\"%s\") returned %llu, expected %u: %s\n",
string,
- len,
+ (unsigned long long)len,
14,
failed ? "NO <<" : "yes" );
int len
)
{
- return strlen(file);
+ return (int)strlen(file); /* assume no overflow possible */
}
/*
X509_time_adj(X509_get_notAfter(cert), lifetime * SECSPERDAY, &epoch);
subj = X509_get_subject_name(cert);
X509_NAME_add_entry_by_txt(subj, "commonName", MBSTRING_ASC,
- (u_char *)name, strlen(name), -1, 0);
+ (u_char *)name, -1, -1, 0);
subj = X509_get_issuer_name(cert);
X509_NAME_add_entry_by_txt(subj, "commonName", MBSTRING_ASC,
- (u_char *)name, strlen(name), -1, 0);
+ (u_char *)name, -1, -1, 0);
if (!X509_set_pubkey(cert, pkey)) {
fprintf(stderr, "Assign certificate signing key fails\n%s\n",
ERR_error_string(ERR_get_error(), NULL));