summaryrefslogtreecommitdiff
path: root/libntp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@baserock.org>2015-04-07 08:29:34 +0000
committer <>2015-04-13 18:52:43 +0000
commitb2ccf8dd31d1457ae9f0ae270054117179220370 (patch)
tree4ccd4a16d5e9ef5869630ba624e822665a6e248c /libntp
parentbdab5265fcbf3f472545073a23f8999749a9f2b9 (diff)
downloadntp-master.tar.gz
Imported from /home/lorry/working-area/delta_ntp/ntp-4.2.8p2.tar.gz.HEADntp-4.2.8p2master
Diffstat (limited to 'libntp')
-rw-r--r--libntp/Makefile.am3
-rw-r--r--libntp/Makefile.in70
-rw-r--r--libntp/atoint.c2
-rw-r--r--libntp/atolfp.c10
-rw-r--r--libntp/atouint.c2
-rw-r--r--libntp/audio.c24
-rw-r--r--libntp/authkeys.c3
-rw-r--r--libntp/authreadkeys.c8
-rw-r--r--libntp/emalloc.c2
-rw-r--r--libntp/hextoint.c2
-rw-r--r--libntp/hextolfp.c4
-rw-r--r--libntp/humandate.c4
-rw-r--r--libntp/icom.c4
-rw-r--r--libntp/modetoa.c6
-rw-r--r--libntp/mstolfp.c10
-rw-r--r--libntp/ntp_calendar.c80
-rw-r--r--libntp/ntp_crypto_rnd.c113
-rw-r--r--libntp/ntp_intres.c19
-rw-r--r--libntp/ntp_lineedit.c13
-rw-r--r--libntp/octtoint.c2
-rw-r--r--libntp/prettydate.c14
-rw-r--r--libntp/ssl_init.c4
-rw-r--r--libntp/timetoa.c9
-rw-r--r--libntp/work_fork.c2
24 files changed, 265 insertions, 145 deletions
diff --git a/libntp/Makefile.am b/libntp/Makefile.am
index 515fa9a..c12658f 100644
--- a/libntp/Makefile.am
+++ b/libntp/Makefile.am
@@ -78,16 +78,17 @@ libntp_a_SRCS = \
msyslog.c \
netof.c \
ntp_calendar.c \
+ ntp_crypto_rnd.c \
ntp_intres.c \
ntp_libopts.c \
ntp_lineedit.c \
+ ntp_random.c \
ntp_rfc2553.c \
ntp_worker.c \
numtoa.c \
numtohost.c \
octtoint.c \
prettydate.c \
- ntp_random.c \
recvbuff.c \
refnumtoa.c \
snprintf.c \
diff --git a/libntp/Makefile.in b/libntp/Makefile.in
index 87645ca..bb68042 100644
--- a/libntp/Makefile.in
+++ b/libntp/Makefile.in
@@ -41,8 +41,7 @@ subdir = libntp
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/sntp/libopts/m4/libopts.m4 \
$(top_srcdir)/sntp/libopts/m4/stdnoreturn.m4 \
- $(top_srcdir)/sntp/libevent/m4/openldap-thread-check.m4 \
- $(top_srcdir)/sntp/libevent/m4/openldap.m4 \
+ $(top_srcdir)/sntp/m4/ax_c99_struct_init.m4 \
$(top_srcdir)/sntp/m4/define_dir.m4 \
$(top_srcdir)/sntp/m4/hms_search_lib.m4 \
$(top_srcdir)/sntp/m4/libtool.m4 \
@@ -53,6 +52,7 @@ am__aclocal_m4_deps = $(top_srcdir)/sntp/libopts/m4/libopts.m4 \
$(top_srcdir)/sntp/m4/ntp_cacheversion.m4 \
$(top_srcdir)/sntp/m4/ntp_compiler.m4 \
$(top_srcdir)/sntp/m4/ntp_crosscompile.m4 \
+ $(top_srcdir)/sntp/m4/ntp_crypto_rand.m4 \
$(top_srcdir)/sntp/m4/ntp_debug.m4 \
$(top_srcdir)/sntp/m4/ntp_dir_sep.m4 \
$(top_srcdir)/sntp/m4/ntp_facilitynames.m4 \
@@ -70,6 +70,8 @@ am__aclocal_m4_deps = $(top_srcdir)/sntp/libopts/m4/libopts.m4 \
$(top_srcdir)/sntp/m4/ntp_sntp.m4 \
$(top_srcdir)/sntp/m4/ntp_ver_suffix.m4 \
$(top_srcdir)/sntp/m4/ntp_vpathhack.m4 \
+ $(top_srcdir)/sntp/m4/openldap-thread-check.m4 \
+ $(top_srcdir)/sntp/m4/openldap.m4 \
$(top_srcdir)/sntp/m4/os_cflags.m4 \
$(top_srcdir)/sntp/m4/snprintf.m4 \
$(top_srcdir)/sntp/m4/version.m4 $(top_srcdir)/configure.ac
@@ -96,13 +98,14 @@ am__libntp_a_SOURCES_DIST = systime.c a_md5encrypt.c adjtime.c \
dofptoa.c dolfptoa.c emalloc.c findconfig.c getopt.c \
hextoint.c hextolfp.c humandate.c icom.c iosignal.c \
lib_strbuf.c machines.c mktime.c modetoa.c mstolfp.c msyslog.c \
- netof.c ntp_calendar.c ntp_intres.c ntp_libopts.c \
- ntp_lineedit.c ntp_rfc2553.c ntp_worker.c numtoa.c numtohost.c \
- octtoint.c prettydate.c ntp_random.c recvbuff.c refnumtoa.c \
- snprintf.c socket.c socktoa.c socktohost.c ssl_init.c \
- statestr.c strdup.c strl_obsd.c syssignal.c timetoa.c \
- timevalops.c uglydate.c vint64ops.c work_fork.c work_thread.c \
- ymd2yd.c $(srcdir)/../lib/isc/assertions.c \
+ netof.c ntp_calendar.c ntp_crypto_rnd.c ntp_intres.c \
+ ntp_libopts.c ntp_lineedit.c ntp_random.c ntp_rfc2553.c \
+ ntp_worker.c numtoa.c numtohost.c octtoint.c prettydate.c \
+ recvbuff.c refnumtoa.c snprintf.c socket.c socktoa.c \
+ socktohost.c ssl_init.c statestr.c strdup.c strl_obsd.c \
+ syssignal.c timetoa.c timevalops.c uglydate.c vint64ops.c \
+ work_fork.c work_thread.c ymd2yd.c \
+ $(srcdir)/../lib/isc/assertions.c \
$(srcdir)/../lib/isc/buffer.c \
$(srcdir)/../lib/isc/backtrace-emptytbl.c \
$(srcdir)/../lib/isc/backtrace.c \
@@ -153,17 +156,19 @@ am__objects_4 = a_md5encrypt.$(OBJEXT) adjtime.$(OBJEXT) \
humandate.$(OBJEXT) icom.$(OBJEXT) iosignal.$(OBJEXT) \
lib_strbuf.$(OBJEXT) machines.$(OBJEXT) mktime.$(OBJEXT) \
modetoa.$(OBJEXT) mstolfp.$(OBJEXT) msyslog.$(OBJEXT) \
- netof.$(OBJEXT) ntp_calendar.$(OBJEXT) ntp_intres.$(OBJEXT) \
+ netof.$(OBJEXT) ntp_calendar.$(OBJEXT) \
+ ntp_crypto_rnd.$(OBJEXT) ntp_intres.$(OBJEXT) \
ntp_libopts.$(OBJEXT) ntp_lineedit.$(OBJEXT) \
- ntp_rfc2553.$(OBJEXT) ntp_worker.$(OBJEXT) numtoa.$(OBJEXT) \
- numtohost.$(OBJEXT) octtoint.$(OBJEXT) prettydate.$(OBJEXT) \
- ntp_random.$(OBJEXT) recvbuff.$(OBJEXT) refnumtoa.$(OBJEXT) \
- snprintf.$(OBJEXT) socket.$(OBJEXT) socktoa.$(OBJEXT) \
- socktohost.$(OBJEXT) ssl_init.$(OBJEXT) statestr.$(OBJEXT) \
- strdup.$(OBJEXT) strl_obsd.$(OBJEXT) syssignal.$(OBJEXT) \
- timetoa.$(OBJEXT) timevalops.$(OBJEXT) uglydate.$(OBJEXT) \
- vint64ops.$(OBJEXT) work_fork.$(OBJEXT) work_thread.$(OBJEXT) \
- ymd2yd.$(OBJEXT) $(am__objects_3) $(am__objects_1)
+ ntp_random.$(OBJEXT) ntp_rfc2553.$(OBJEXT) \
+ ntp_worker.$(OBJEXT) numtoa.$(OBJEXT) numtohost.$(OBJEXT) \
+ octtoint.$(OBJEXT) prettydate.$(OBJEXT) recvbuff.$(OBJEXT) \
+ refnumtoa.$(OBJEXT) snprintf.$(OBJEXT) socket.$(OBJEXT) \
+ socktoa.$(OBJEXT) socktohost.$(OBJEXT) ssl_init.$(OBJEXT) \
+ statestr.$(OBJEXT) strdup.$(OBJEXT) strl_obsd.$(OBJEXT) \
+ syssignal.$(OBJEXT) timetoa.$(OBJEXT) timevalops.$(OBJEXT) \
+ uglydate.$(OBJEXT) vint64ops.$(OBJEXT) work_fork.$(OBJEXT) \
+ work_thread.$(OBJEXT) ymd2yd.$(OBJEXT) $(am__objects_3) \
+ $(am__objects_1)
am_libntp_a_OBJECTS = systime.$(OBJEXT) $(am__objects_4)
libntp_a_OBJECTS = $(am_libntp_a_OBJECTS)
libntpsim_a_AR = $(AR) $(ARFLAGS)
@@ -175,13 +180,14 @@ am__libntpsim_a_SOURCES_DIST = systime_s.c a_md5encrypt.c adjtime.c \
dofptoa.c dolfptoa.c emalloc.c findconfig.c getopt.c \
hextoint.c hextolfp.c humandate.c icom.c iosignal.c \
lib_strbuf.c machines.c mktime.c modetoa.c mstolfp.c msyslog.c \
- netof.c ntp_calendar.c ntp_intres.c ntp_libopts.c \
- ntp_lineedit.c ntp_rfc2553.c ntp_worker.c numtoa.c numtohost.c \
- octtoint.c prettydate.c ntp_random.c recvbuff.c refnumtoa.c \
- snprintf.c socket.c socktoa.c socktohost.c ssl_init.c \
- statestr.c strdup.c strl_obsd.c syssignal.c timetoa.c \
- timevalops.c uglydate.c vint64ops.c work_fork.c work_thread.c \
- ymd2yd.c $(srcdir)/../lib/isc/assertions.c \
+ netof.c ntp_calendar.c ntp_crypto_rnd.c ntp_intres.c \
+ ntp_libopts.c ntp_lineedit.c ntp_random.c ntp_rfc2553.c \
+ ntp_worker.c numtoa.c numtohost.c octtoint.c prettydate.c \
+ recvbuff.c refnumtoa.c snprintf.c socket.c socktoa.c \
+ socktohost.c ssl_init.c statestr.c strdup.c strl_obsd.c \
+ syssignal.c timetoa.c timevalops.c uglydate.c vint64ops.c \
+ work_fork.c work_thread.c ymd2yd.c \
+ $(srcdir)/../lib/isc/assertions.c \
$(srcdir)/../lib/isc/buffer.c \
$(srcdir)/../lib/isc/backtrace-emptytbl.c \
$(srcdir)/../lib/isc/backtrace.c \
@@ -263,6 +269,7 @@ CHUTEST = @CHUTEST@
CONFIG_SHELL = @CONFIG_SHELL@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
+CPPFLAGS_LIBEVENT = @CPPFLAGS_LIBEVENT@
CPPFLAGS_NTP = @CPPFLAGS_NTP@
CXX = @CXX@
CXXCPP = @CXXCPP@
@@ -297,7 +304,9 @@ INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
LD = @LD@
+LDADD_LIBEVENT = @LDADD_LIBEVENT@
LDADD_LIBNTP = @LDADD_LIBNTP@
+LDADD_LIBUTIL = @LDADD_LIBUTIL@
LDADD_NLIST = @LDADD_NLIST@
LDADD_NTP = @LDADD_NTP@
LDFLAGS = @LDFLAGS@
@@ -436,6 +445,11 @@ TIMETRIM_DL = @TIMETRIM_DL@
TIMETRIM_DS = @TIMETRIM_DS@
TIMETRIM_MS = @TIMETRIM_MS@
TIMETRIM_NI = @TIMETRIM_NI@
+UPDATE_LEAP_DB = @UPDATE_LEAP_DB@
+UPDATE_LEAP_DL = @UPDATE_LEAP_DL@
+UPDATE_LEAP_DS = @UPDATE_LEAP_DS@
+UPDATE_LEAP_MS = @UPDATE_LEAP_MS@
+UPDATE_LEAP_NI = @UPDATE_LEAP_NI@
VERSION = @VERSION@
VER_SUFFIX = @VER_SUFFIX@
YACC = @YACC@
@@ -559,16 +573,17 @@ libntp_a_SRCS = \
msyslog.c \
netof.c \
ntp_calendar.c \
+ ntp_crypto_rnd.c \
ntp_intres.c \
ntp_libopts.c \
ntp_lineedit.c \
+ ntp_random.c \
ntp_rfc2553.c \
ntp_worker.c \
numtoa.c \
numtohost.c \
octtoint.c \
prettydate.c \
- ntp_random.c \
recvbuff.c \
refnumtoa.c \
snprintf.c \
@@ -709,6 +724,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/netof.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/netscope.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ntp_calendar.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ntp_crypto_rnd.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ntp_intres.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ntp_libopts.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ntp_lineedit.Po@am__quote@
diff --git a/libntp/atoint.c b/libntp/atoint.c
index 1064b36..9da8c13 100644
--- a/libntp/atoint.c
+++ b/libntp/atoint.c
@@ -35,7 +35,7 @@ atoint(
u = 0;
while (*cp != '\0') {
- if (!isdigit((int)*cp))
+ if (!isdigit((unsigned char)*cp))
return 0;
if (u > 214748364 || (u == 214748364 && *cp > oflow_digit))
return 0; /* overflow */
diff --git a/libntp/atolfp.c b/libntp/atolfp.c
index 4afeb23..3a65f6b 100644
--- a/libntp/atolfp.c
+++ b/libntp/atolfp.c
@@ -52,7 +52,7 @@ atolfp(
*
* [spaces][-|+][digits][.][digits][spaces|\n|\0]
*/
- while (isspace((int)*cp))
+ while (isspace((unsigned char)*cp))
cp++;
if (*cp == '-') {
@@ -63,7 +63,7 @@ atolfp(
if (*cp == '+')
cp++;
- if (*cp != '.' && !isdigit((int)*cp))
+ if (*cp != '.' && !isdigit((unsigned char)*cp))
return 0;
while (*cp != '\0' && (ind = strchr(digits, *cp)) != NULL) {
@@ -72,7 +72,7 @@ atolfp(
cp++;
}
- if (*cp != '\0' && !isspace((int)*cp)) {
+ if (*cp != '\0' && !isspace((unsigned char)*cp)) {
if (*cp++ != '.')
return 0;
@@ -84,10 +84,10 @@ atolfp(
cp++;
}
- while (isdigit((int)*cp))
+ while (isdigit((unsigned char)*cp))
cp++;
- if (*cp != '\0' && !isspace((int)*cp))
+ if (*cp != '\0' && !isspace((unsigned char)*cp))
return 0;
}
diff --git a/libntp/atouint.c b/libntp/atouint.c
index ab86130..0a61639 100644
--- a/libntp/atouint.c
+++ b/libntp/atouint.c
@@ -28,7 +28,7 @@ atouint(
u = 0;
while ('\0' != *cp) {
- if (!isdigit(*cp))
+ if (!isdigit((unsigned char)*cp))
return 0;
if (u > 429496729 || (u == 429496729 && *cp >= '6'))
return 0; /* overflow */
diff --git a/libntp/audio.c b/libntp/audio.c
index 2a56619..6f2262c 100644
--- a/libntp/audio.c
+++ b/libntp/audio.c
@@ -67,7 +67,7 @@ static struct audio_info info; /* audio device info */
static int ctl_fd; /* audio control file descriptor */
#ifdef PCM_STYLE_SOUND
-static void audio_config_read (int, char **, char **);
+static void audio_config_read (int, const char **, const char **);
static int mixer_name (const char *, int);
@@ -114,8 +114,8 @@ mixer_name(
static void
audio_config_read(
int unit,
- char **c_dev, /* Control device */
- char **i_dev /* input device */
+ const char **c_dev, /* Control device */
+ const char **i_dev /* input device */
)
{
FILE *fd;
@@ -148,12 +148,12 @@ audio_config_read(
/* Remove any trailing spaces */
for (i = strlen(line);
- i > 0 && isascii((int)line[i - 1]) && isspace((int)line[i - 1]);
+ i > 0 && isascii((unsigned char)line[i - 1]) && isspace((unsigned char)line[i - 1]);
)
line[--i] = '\0';
/* Remove leading space */
- for (cc = line; *cc && isascii((int)*cc) && isspace((int)*cc); cc++)
+ for (cc = line; *cc && isascii((unsigned char)*cc) && isspace((unsigned char)*cc); cc++)
continue;
/* Stop if nothing left */
@@ -162,16 +162,16 @@ audio_config_read(
/* Uppercase the command and find the arg */
for (ca = cc; *ca; ca++) {
- if (isascii((int)*ca)) {
- if (islower((int)*ca)) {
- *ca = toupper(*ca);
- } else if (isspace((int)*ca) || (*ca == '='))
+ if (isascii((unsigned char)*ca)) {
+ if (islower((unsigned char)*ca)) {
+ *ca = toupper((unsigned char)*ca);
+ } else if (isspace((unsigned char)*ca) || (*ca == '='))
break;
}
}
/* Remove space (and possible =) leading the arg */
- for (; *ca && isascii((int)*ca) && (isspace((int)*ca) || (*ca == '=')); ca++)
+ for (; *ca && isascii((unsigned char)*ca) && (isspace((unsigned char)*ca) || (*ca == '=')); ca++)
continue;
if (!strncmp(cc, "IDEV", 4) &&
@@ -210,7 +210,7 @@ audio_config_read(
*/
int
audio_init(
- char *dname, /* device name */
+ const char *dname, /* device name */
int bufsiz, /* buffer size */
int unit /* device unit (0-3) */
)
@@ -227,7 +227,7 @@ audio_init(
#endif
int fd;
int rval;
- char *actl =
+ const char *actl =
#ifdef PCM_STYLE_SOUND
actl_dev
#else
diff --git a/libntp/authkeys.c b/libntp/authkeys.c
index 7b4427c..68771ff 100644
--- a/libntp/authkeys.c
+++ b/libntp/authkeys.c
@@ -517,7 +517,7 @@ MD5auth_setkey(
keyid_t keyno,
int keytype,
const u_char *key,
- int len
+ size_t len
)
{
symkey * sk;
@@ -527,7 +527,6 @@ MD5auth_setkey(
DEBUG_ENSURE(keytype <= USHRT_MAX);
DEBUG_ENSURE(len < 4 * 1024);
- len = max(0, len);
/*
* See if we already have the key. If so just stick in the
* new value.
diff --git a/libntp/authreadkeys.c b/libntp/authreadkeys.c
index 9b02119..e8ddc94 100644
--- a/libntp/authreadkeys.c
+++ b/libntp/authreadkeys.c
@@ -77,8 +77,8 @@ authreadkeys(
int keytype;
char buf[512]; /* lots of room for line */
u_char keystr[32]; /* Bug 2537 */
- int len;
- int j;
+ size_t len;
+ size_t j;
/*
* Open file. Complain and return if it can't be opened.
@@ -181,11 +181,11 @@ authreadkeys(
char hex[] = "0123456789abcdef";
u_char temp;
char *ptr;
- int jlim;
+ size_t jlim;
jlim = min(len, 2 * sizeof(keystr));
for (j = 0; j < jlim; j++) {
- ptr = strchr(hex, tolower(token[j]));
+ ptr = strchr(hex, tolower((unsigned char)token[j]));
if (ptr == NULL)
break; /* abort decoding */
temp = (u_char)(ptr - hex);
diff --git a/libntp/emalloc.c b/libntp/emalloc.c
index c49c5c1..6c1c678 100644
--- a/libntp/emalloc.c
+++ b/libntp/emalloc.c
@@ -86,6 +86,7 @@ estrdup_impl(
}
+#if 0
#ifndef EREALLOC_CALLSITE
void *
emalloc(size_t newsz)
@@ -93,4 +94,5 @@ emalloc(size_t newsz)
return ereallocz(NULL, newsz, 0, FALSE);
}
#endif
+#endif
diff --git a/libntp/hextoint.c b/libntp/hextoint.c
index d24b5a0..980a43f 100644
--- a/libntp/hextoint.c
+++ b/libntp/hextoint.c
@@ -23,7 +23,7 @@ hextoint(
u = 0;
while (*cp != '\0') {
- if (!isxdigit(*cp))
+ if (!isxdigit((unsigned char)*cp))
return 0;
if (u & 0xF0000000)
return 0; /* overflow */
diff --git a/libntp/hextolfp.c b/libntp/hextolfp.c
index 8fbce2e..2bff929 100644
--- a/libntp/hextolfp.c
+++ b/libntp/hextolfp.c
@@ -30,7 +30,7 @@ hextolfp(
*
* [spaces]8_hex_digits[.]8_hex_digits[spaces|\n|\0]
*/
- while (isspace((int)*cp))
+ while (isspace((unsigned char)*cp))
cp++;
cpstart = cp;
@@ -59,7 +59,7 @@ hextolfp(
if ((cp - cpstart) < 8 || ind == NULL)
return 0;
- if (*cp != '\0' && !isspace((int)*cp))
+ if (*cp != '\0' && !isspace((unsigned char)*cp))
return 0;
lfp->l_ui = dec_i;
diff --git a/libntp/humandate.c b/libntp/humandate.c
index f88d8d2..d9d5e89 100644
--- a/libntp/humandate.c
+++ b/libntp/humandate.c
@@ -13,7 +13,7 @@
/* This is used in msyslog.c; we don't want to clutter up the log with
the year and day of the week, etc.; just the minimal date and time. */
-char *
+const char *
humanlogtime(void)
{
char * bp;
@@ -39,7 +39,7 @@ humanlogtime(void)
* humantime() -- like humanlogtime() but without date, and with the
* time to display given as an argument.
*/
-char *
+const char *
humantime(
time_t cursec
)
diff --git a/libntp/icom.c b/libntp/icom.c
index c981d85..8070011 100644
--- a/libntp/icom.c
+++ b/libntp/icom.c
@@ -121,17 +121,15 @@ doublefreq( /* returns void */
*/
int
icom_init(
- char *device, /* device name/link */
+ const char *device, /* device name/link */
int speed, /* line speed */
int trace /* trace flags */ )
{
TTY ttyb;
int fd;
- int flags;
int rc;
int saved_errno;
- flags = trace;
fd = tty_open(device, O_RDWR, 0777);
if (fd < 0)
return -1;
diff --git a/libntp/modetoa.c b/libntp/modetoa.c
index b476bc9..6f13d20 100644
--- a/libntp/modetoa.c
+++ b/libntp/modetoa.c
@@ -9,7 +9,7 @@
const char *
modetoa(
- int mode
+ size_t mode
)
{
char *bp;
@@ -25,9 +25,9 @@ modetoa(
"bclient",
};
- if (mode < 0 || mode >= COUNTOF(modestrings)) {
+ if (mode >= COUNTOF(modestrings)) {
LIB_GETBUF(bp);
- snprintf(bp, LIB_BUFLENGTH, "mode#%d", mode);
+ snprintf(bp, LIB_BUFLENGTH, "mode#%zu", mode);
return bp;
}
diff --git a/libntp/mstolfp.c b/libntp/mstolfp.c
index 1a1a02b..828b14c 100644
--- a/libntp/mstolfp.c
+++ b/libntp/mstolfp.c
@@ -32,7 +32,7 @@ mstolfp(
*/
bp = buf;
cp = str;
- while (isspace((int)*cp))
+ while (isspace((unsigned char)*cp))
cp++;
if (*cp == '-') {
@@ -40,7 +40,7 @@ mstolfp(
cp++;
}
- if (*cp != '.' && !isdigit((int)*cp))
+ if (*cp != '.' && !isdigit((unsigned char)*cp))
return 0;
@@ -48,7 +48,7 @@ mstolfp(
* Search forward for the decimal point or the end of the string.
*/
cpdec = cp;
- while (isdigit((int)*cpdec))
+ while (isdigit((unsigned char)*cpdec))
cpdec++;
/*
@@ -86,7 +86,7 @@ mstolfp(
if (*cp == '.') {
cp++;
- while (isdigit((int)*cp))
+ while (isdigit((unsigned char)*cp))
*bp++ = (char)*cp++;
}
*bp = '\0';
@@ -95,7 +95,7 @@ mstolfp(
* Check to make sure the string is properly terminated. If
* so, give the buffer to the decoding routine.
*/
- if (*cp != '\0' && !isspace((int)*cp))
+ if (*cp != '\0' && !isspace((unsigned char)*cp))
return 0;
return atolfp(buf, lfp);
}
diff --git a/libntp/ntp_calendar.c b/libntp/ntp_calendar.c
index e557f4e..ff91fcf 100644
--- a/libntp/ntp_calendar.c
+++ b/libntp/ntp_calendar.c
@@ -29,7 +29,7 @@ ntpcal_set_timefunc(
)
{
systime_func_ptr res;
-
+
res = systime_func;
if (NULL == nfunc)
nfunc = &time;
@@ -118,7 +118,7 @@ vint64_to_time(
#endif
return res;
-}
+}
/*
*---------------------------------------------------------------------
@@ -153,7 +153,11 @@ ntpcal_get_build_date(
* problem.
*
*/
+#ifdef MKREPRO_DATE
+ static const char build[] = MKREPRO_TIME "/" MKREPRO_DATE;
+#else
static const char build[] = __TIME__ "/" __DATE__;
+#endif
static const char mlist[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
char monstr[4];
@@ -166,7 +170,7 @@ ntpcal_get_build_date(
#ifdef DEBUG
static int ignore = 0;
#endif
-
+
ZERO(*jd);
jd->year = 1970;
jd->month = 1;
@@ -251,7 +255,7 @@ static const uint16_t real_month_table[2][13] = {
* in the proleptic Gregorian calendar. The begin of the Christian Era
* (0001-01-01) is RD(1).
*
- *
+ *
* Some notes on the implementation:
*
* Calendar algorithms thrive on the division operation, which is one of
@@ -347,7 +351,7 @@ ntpcal_periodic_extend(
char cpl = 0; /* modulo complement flag */
char neg = 0; /* sign change flag */
- /* make the cycle positive and adjust the flags */
+ /* make the cycle positive and adjust the flags */
if (cycle < 0) {
cycle = - cycle;
neg ^= 1;
@@ -403,21 +407,21 @@ ntpcal_ntp_to_time(
#ifdef HAVE_INT64
- res.q_s = (pivot != NULL)
+ res.q_s = (pivot != NULL)
? *pivot
- : now();
+ : now();
res.Q_s -= 0x80000000; /* unshift of half range */
ntp -= (uint32_t)JAN_1970; /* warp into UN*X domain */
ntp -= res.D_s.lo; /* cycle difference */
res.Q_s += (uint64_t)ntp; /* get expanded time */
#else /* no 64bit scalars */
-
+
time_t tmp;
-
- tmp = (pivot != NULL)
+
+ tmp = (pivot != NULL)
? *pivot
- : now();
+ : now();
res = time_to_vint64(&tmp);
M_SUB(res.D_s.hi, res.D_s.lo, 0, 0x80000000);
ntp -= (uint32_t)JAN_1970; /* warp into UN*X domain */
@@ -461,9 +465,9 @@ ntpcal_ntp_to_ntp(
res.Q_s += (uint64_t)ntp; /* get expanded time */
#else /* no 64bit scalars */
-
+
time_t tmp;
-
+
tmp = (pivot)
? *pivot
: now();
@@ -488,7 +492,7 @@ ntpcal_ntp_to_ntp(
*/
/*
- *-------------------------------------------------------------------
+ *-------------------------------------------------------------------
* Split a 64bit seconds value into elapsed days in 'res.hi' and
* elapsed seconds since midnight in 'res.lo' using explicit floor
* division. This function happily accepts negative time values as
@@ -528,7 +532,7 @@ ntpcal_daysplit(
isneg = M_ISNEG(op.D_s.hi);
if (isneg)
M_NEG(op.D_s.hi, op.D_s.lo);
-
+
/* save remainder of DIV 128, shift for divide */
r = op.D_s.lo & 127; /* save remainder bits */
op.D_s.lo = (op.D_s.lo >> 7) | (op.D_s.hi << 25);
@@ -568,16 +572,16 @@ ntpcal_daysplit(
} else
q = ~q + 1;
}
-
+
res.hi = q;
res.lo = r;
-#endif
+#endif
return res;
}
/*
- *-------------------------------------------------------------------
+ *-------------------------------------------------------------------
* Split a 32bit seconds value into h/m/s and excessive days. This
* function happily accepts negative time values as timestamps before
* midnight.
@@ -628,7 +632,7 @@ ntpcal_split_eradays(
{
ntpcal_split res;
int32_t n400, n100, n004, n001, yday; /* calendar year cycles */
-
+
/*
* Split off calendar cycles, using floor division in the first
* step. After that first step, simple division does it because
@@ -648,7 +652,7 @@ ntpcal_split_eradays(
yday = yday % GREGORIAN_NORMAL_LEAP_CYCLE_DAYS;
n001 = yday / DAYSPERYEAR;
yday = yday % DAYSPERYEAR;
-
+
/*
* check for leap cycle overflows and calculate the leap flag
* if needed
@@ -661,11 +665,11 @@ ntpcal_split_eradays(
*isleapyear = 1;
} else if (isleapyear)
*isleapyear = (n001 == 3) && ((n004 != 24) || (n100 == 3));
-
+
/* now merge the cycles to elapsed years, using horner scheme */
res.hi = ((4*n400 + n100)*25 + n004)*4 + n001;
res.lo = yday;
-
+
return res;
}
@@ -720,7 +724,13 @@ ntpcal_rd_to_date(
leaps = 0;
retv = 0;
- /* get day-of-week first */
+ /* Get day-of-week first. Since rd is signed, the remainder can
+ * be in the range [-6..+6], but the assignment to an unsigned
+ * variable maps the negative values to positive values >=7.
+ * This makes the sign correction look strange, but adding 7
+ * causes the needed wrap-around into the desired value range of
+ * zero to six, both inclusive.
+ */
jd->weekday = rd % 7;
if (jd->weekday >= 7) /* unsigned! */
jd->weekday += 7;
@@ -790,7 +800,7 @@ ntpcal_daysec_to_date(
{
int32_t days;
int ts[3];
-
+
days = priv_timesplit(ts, sec);
jd->hour = (uint8_t)ts[0];
jd->minute = (uint8_t)ts[1];
@@ -813,7 +823,7 @@ ntpcal_daysec_to_tm(
{
int32_t days;
int32_t ts[3];
-
+
days = priv_timesplit(ts, sec);
utm->tm_hour = ts[0];
utm->tm_min = ts[1];
@@ -942,7 +952,7 @@ ntpcal_dayjoin(
/* fix sign */
if (isneg)
M_NEG(res.D_s.hi, res.D_s.lo);
-
+
/* properly add seconds */
p2 = 0;
if (secs < 0) {
@@ -953,7 +963,7 @@ ntpcal_dayjoin(
}
M_ADD(res.D_s.hi, res.D_s.lo, p2, p1);
-#endif
+#endif
return res;
}
@@ -1275,7 +1285,7 @@ ntpcal_ntp64_to_date(
)
{
ntpcal_split ds;
-
+
ds = ntpcal_daysplit(ntp);
ds.hi += ntpcal_daysec_to_date(jd, ds.lo);
@@ -1290,7 +1300,7 @@ ntpcal_ntp_to_date(
)
{
vint64 ntp64;
-
+
/*
* Unfold ntp time around current time into NTP domain. Split
* into days and seconds, shift days into CE domain and
@@ -1512,12 +1522,12 @@ isocal_split_eraweeks(
res.lo += (res.lo >= 10435);
cents = res.lo / 5218;
res.lo %= 5218; /* res.lo is weeks in century now */
-
+
/* convert elapsed weeks in century to elapsed years and weeks */
res.lo = res.lo * 157 + bctab[cents];
res.hi += cents * 100 + res.lo / 8192;
- res.lo = (res.lo % 8192) / 157;
-
+ res.lo = (res.lo % 8192) / 157;
+
return res;
}
@@ -1534,7 +1544,7 @@ isocal_ntp64_to_date(
{
ntpcal_split ds;
int32_t ts[3];
-
+
/*
* Split NTP time into days and seconds, shift days into CE
* domain and process the parts.
@@ -1561,7 +1571,7 @@ isocal_ntp64_to_date(
id->year = (uint16_t)ds.hi + 1; /* shift to current */
id->week = (uint8_t )ds.lo + 1;
- return (ds.hi >= 0 && ds.hi < 0xFFFFU);
+ return (ds.hi >= 0 && ds.hi < 0x0000FFFF);
}
int
@@ -1572,7 +1582,7 @@ isocal_ntp_to_date(
)
{
vint64 ntp64;
-
+
/*
* Unfold ntp time around current time into NTP domain, then
* convert the full time stamp.
diff --git a/libntp/ntp_crypto_rnd.c b/libntp/ntp_crypto_rnd.c
new file mode 100644
index 0000000..96348f2
--- /dev/null
+++ b/libntp/ntp_crypto_rnd.c
@@ -0,0 +1,113 @@
+/*
+ * Crypto-quality random number functions
+ *
+ * Author: Harlan Stenn, 2014
+ *
+ * This file is Copyright (c) 2014 by Network Time Foundation.
+ * BSD terms apply: see the file COPYRIGHT in the distribution root for details.
+ */
+
+#include "config.h"
+#include <sys/types.h>
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+#include <stdio.h>
+
+#include <l_stdlib.h>
+#include <ntp_random.h>
+
+#ifdef USE_OPENSSL_CRYPTO_RAND
+#include <openssl/err.h>
+#include <openssl/rand.h>
+
+int crypto_rand_init = 0;
+#else
+
+# ifndef HAVE_ARC4RANDOM_BUF
+static void
+arc4random_buf(void *buf, size_t nbytes);
+
+void
+evutil_secure_rng_get_bytes(void *buf, size_t nbytes);
+
+static void
+arc4random_buf(void *buf, size_t nbytes)
+{
+ evutil_secure_rng_get_bytes(buf, nbytes);
+ return;
+}
+# endif
+#endif
+
+/*
+ * As of late 2014, here's how we plan to provide cryptographic-quality
+ * random numbers:
+ *
+ * - If we are building with OpenSSL, use RAND_poll() and RAND_bytes().
+ * - Otherwise, use arc4random().
+ *
+ * Use of arc4random() can be forced using configure --disable-openssl-random
+ *
+ * We can count on arc4random existing, thru the OS or thru libevent.
+ * The quality of arc4random depends on the implementor.
+ *
+ * RAND_poll() doesn't show up until XXX. If it's not present, we
+ * need to either provide our own or use arc4random().
+ */
+
+/*
+ * ntp_crypto_srandom:
+ *
+ * Initialize the random number generator, if needed by the underlying
+ * crypto random number generation mechanism.
+ */
+
+void
+ntp_crypto_srandom(
+ void
+ )
+{
+#ifdef USE_OPENSSL_CRYPTO_RAND
+ if (!crypto_rand_init) {
+ RAND_poll();
+ crypto_rand_init = 1;
+ }
+#else
+ /* No initialization needed for arc4random() */
+#endif
+}
+
+
+/*
+ * ntp_crypto_random_buf:
+ *
+ * Returns 0 on success, -1 on error.
+ */
+int
+ntp_crypto_random_buf(
+ void *buf,
+ size_t nbytes
+ )
+{
+#ifdef USE_OPENSSL_CRYPTO_RAND
+ int rc;
+
+ rc = RAND_bytes(buf, nbytes);
+ if (1 != rc) {
+ unsigned long err;
+ char *err_str;
+
+ err = ERR_get_error();
+ err_str = ERR_error_string(err, NULL);
+ /* XXX: Log the error */
+ (void)&err_str;
+
+ return -1;
+ }
+ return 0;
+#else
+ arc4random_buf(buf, nbytes);
+ return 0;
+#endif
+}
diff --git a/libntp/ntp_intres.c b/libntp/ntp_intres.c
index 2ac70c1..eea88a1 100644
--- a/libntp/ntp_intres.c
+++ b/libntp/ntp_intres.c
@@ -684,11 +684,11 @@ blocking_getnameinfo(
blocking_gni_resp * gni_resp;
size_t octets;
size_t resp_octets;
- char * host;
char * service;
char * cp;
int rc;
time_t time_now;
+ char host[1024];
gni_req = (void *)((char *)req + sizeof(*req));
@@ -699,19 +699,7 @@ blocking_getnameinfo(
* large allocations. We only need room for the host
* and service names.
*/
- NTP_REQUIRE(octets < 1024);
-
-#ifndef HAVE_ALLOCA
- host = emalloc(octets);
-#else
- host = alloca(octets);
- if (NULL == host) {
- msyslog(LOG_ERR,
- "blocking_getnameinfo unable to allocate %lu octets on stack",
- (u_long)octets);
- exit(1);
- }
-#endif
+ NTP_REQUIRE(octets < sizeof(host));
service = host + gni_req->hostoctets;
worker_ctx = get_worker_context(c, gni_req->dns_idx);
@@ -793,9 +781,6 @@ blocking_getnameinfo(
rc = queue_blocking_response(c, resp, resp_octets, req);
if (rc)
msyslog(LOG_ERR, "blocking_getnameinfo unable to queue response");
-#ifndef HAVE_ALLOCA
- free(host);
-#endif
return rc;
}
diff --git a/libntp/ntp_lineedit.c b/libntp/ntp_lineedit.c
index c5aad31..e3bc002 100644
--- a/libntp/ntp_lineedit.c
+++ b/libntp/ntp_lineedit.c
@@ -178,23 +178,22 @@ ntp_readline(
if (NULL != line) {
if (*line) {
add_history(line);
- *pcount = strlen(line);
- } else {
- free(line);
- line = NULL;
}
+ *pcount = strlen(line);
}
#endif /* LE_READLINE */
#ifdef LE_EDITLINE
cline = el_gets(ntp_el, pcount);
- if (NULL != cline && *cline) {
+ if (NULL != cline) {
history(ntp_hist, &hev, H_ENTER, cline);
- *pcount = strlen(cline);
line = estrdup(cline);
- } else
+ } else if (*pcount == -1) {
line = NULL;
+ } else {
+ line = estrdup("");
+ }
#endif /* LE_EDITLINE */
#ifdef LE_NONE
diff --git a/libntp/octtoint.c b/libntp/octtoint.c
index d189e40..e519601 100644
--- a/libntp/octtoint.c
+++ b/libntp/octtoint.c
@@ -24,7 +24,7 @@ octtoint(
u = 0;
while (*cp != '\0') {
- if (!isdigit((int)*cp) || *cp == '8' || *cp == '9')
+ if (!isdigit((unsigned char)*cp) || *cp == '8' || *cp == '9')
return 0;
if (u >= 0x20000000)
return 0; /* overflow */
diff --git a/libntp/prettydate.c b/libntp/prettydate.c
index f121297..5da5ecc 100644
--- a/libntp/prettydate.c
+++ b/libntp/prettydate.c
@@ -133,7 +133,7 @@ get_struct_tm(
if (--folds < MINFOLD)
return NULL;
ts += SOLAR_CYCLE_SECS;
- } else if (ts >= SOLAR_CYCLE_SECS) {
+ } else if (ts >= (time_t)SOLAR_CYCLE_SECS) {
if (++folds > MAXFOLD)
return NULL;
ts -= SOLAR_CYCLE_SECS;
@@ -157,10 +157,10 @@ common_prettydate(
int local
)
{
- static const char* pfmt[2] = {
- "%08lx.%08lx %s, %s %2d %4d %2d:%02d:%02d.%03u",
- "%08lx.%08lx [%s, %s %2d %4d %2d:%02d:%02d.%03u UTC]"
- };
+ static const char pfmt0[] =
+ "%08lx.%08lx %s, %s %2d %4d %2d:%02d:%02d.%03u";
+ static const char pfmt1[] =
+ "%08lx.%08lx [%s, %s %2d %4d %2d:%02d:%02d.%03u UTC]";
char *bp;
struct tm *tm;
@@ -186,13 +186,13 @@ common_prettydate(
*/
struct calendar jd;
ntpcal_time_to_date(&jd, &sec);
- snprintf(bp, LIB_BUFLENGTH, pfmt[local != 0],
+ snprintf(bp, LIB_BUFLENGTH, local ? pfmt1 : pfmt0,
(u_long)ts->l_ui, (u_long)ts->l_uf,
daynames[jd.weekday], months[jd.month-1],
jd.monthday, jd.year, jd.hour,
jd.minute, jd.second, msec);
} else
- snprintf(bp, LIB_BUFLENGTH, pfmt[0],
+ snprintf(bp, LIB_BUFLENGTH, pfmt0,
(u_long)ts->l_ui, (u_long)ts->l_uf,
daynames[tm->tm_wday], months[tm->tm_mon],
tm->tm_mday, 1900 + tm->tm_year, tm->tm_hour,
diff --git a/libntp/ssl_init.c b/libntp/ssl_init.c
index 7f1e9a0..a9d1d54 100644
--- a/libntp/ssl_init.c
+++ b/libntp/ssl_init.c
@@ -96,13 +96,13 @@ keytype_from_text(
LIB_GETBUF(upcased);
strlcpy(upcased, text, LIB_BUFLENGTH);
for (pch = upcased; '\0' != *pch; pch++)
- *pch = (char)toupper(*pch);
+ *pch = (char)toupper((unsigned char)*pch);
key_type = OBJ_sn2nid(upcased);
#else
key_type = 0;
#endif
- if (!key_type && 'm' == tolower(text[0]))
+ if (!key_type && 'm' == tolower((unsigned char)text[0]))
key_type = NID_md5;
if (!key_type)
diff --git a/libntp/timetoa.c b/libntp/timetoa.c
index c04d34e..f294e16 100644
--- a/libntp/timetoa.c
+++ b/libntp/timetoa.c
@@ -57,14 +57,12 @@ format_time_fraction(
u_int u;
long fraclimit;
int notneg; /* flag for non-negative value */
- const char * fmt;
ldiv_t qr;
DEBUG_REQUIRE(prec != 0);
LIB_GETBUF(cp);
secs_u = (u_time)secs;
- fmt = "-%" UTIME_FORMAT ".%0*ld";
/* check if we need signed or unsigned mode */
notneg = (prec < 0);
@@ -92,9 +90,7 @@ format_time_fraction(
/* Get the absolute value of the split representation time. */
notneg = notneg || ((time_t)secs_u >= 0);
- if (notneg) {
- fmt++; /* skip '-' */
- } else {
+ if (!notneg) {
secs_u = ~secs_u;
if (0 == frac)
secs_u++;
@@ -103,7 +99,8 @@ format_time_fraction(
}
/* finally format the data and return the result */
- snprintf(cp, LIB_BUFLENGTH, fmt, secs_u, prec_u, frac);
+ snprintf(cp, LIB_BUFLENGTH, "%s%" UTIME_FORMAT ".%0*ld",
+ notneg? "" : "-", secs_u, prec_u, frac);
return cp;
}
diff --git a/libntp/work_fork.c b/libntp/work_fork.c
index 10329e7..dab02bc 100644
--- a/libntp/work_fork.c
+++ b/libntp/work_fork.c
@@ -382,7 +382,7 @@ fork_blocking_child(
int rc;
int was_pipe;
int is_pipe;
- int saved_errno;
+ int saved_errno = 0;
int childpid;
int keep_fd;
int fd;