diff options
author | Cy Schubert <cy@FreeBSD.org> | 2015-04-10 01:26:02 +0000 |
---|---|---|
committer | Cy Schubert <cy@FreeBSD.org> | 2015-04-10 01:26:02 +0000 |
commit | 4ba32eb5a8bf3455c09d1513ed2af8d2c861a6ba (patch) | |
tree | f0f951897eebdd4e1fe1c8d47d866fa6c128828d /libntp | |
parent | f7cba3a80d9ebefc57776fffd17a4ae68f72e494 (diff) | |
download | src-4ba32eb5a8bf3455c09d1513ed2af8d2c861a6ba.tar.gz src-4ba32eb5a8bf3455c09d1513ed2af8d2c861a6ba.zip |
Vendor import ntp 4.2.8p2vendor/ntp/4.2.8p2
Approved by: delphij
Security: CVE-2015-1798, CVE-2015-1799
Security: VuXML ebd84c96-dd7e-11e4-854e-3c970e169bc2
Notes
Notes:
svn path=/vendor/ntp/dist/; revision=281348
svn path=/vendor/ntp/4.2.8p2/; revision=281349; tag=vendor/ntp/4.2.8p2
Diffstat (limited to 'libntp')
-rw-r--r-- | libntp/Makefile.in | 10 | ||||
-rw-r--r-- | libntp/ntp_calendar.c | 74 | ||||
-rw-r--r-- | libntp/work_fork.c | 2 |
3 files changed, 49 insertions, 37 deletions
diff --git a/libntp/Makefile.in b/libntp/Makefile.in index ca8b13c50ba6..bb680423ae70 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 \ @@ -71,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 @@ -444,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@ diff --git a/libntp/ntp_calendar.c b/libntp/ntp_calendar.c index 94ca0e9ee154..ff91fcfc678d 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; -} +} /* *--------------------------------------------------------------------- @@ -170,7 +170,7 @@ ntpcal_get_build_date( #ifdef DEBUG static int ignore = 0; #endif - + ZERO(*jd); jd->year = 1970; jd->month = 1; @@ -255,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 @@ -351,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; @@ -407,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 */ @@ -465,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(); @@ -492,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 @@ -532,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); @@ -572,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. @@ -632,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 @@ -652,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 @@ -665,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; } @@ -724,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; @@ -794,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]; @@ -817,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]; @@ -946,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) { @@ -957,7 +963,7 @@ ntpcal_dayjoin( } M_ADD(res.D_s.hi, res.D_s.lo, p2, p1); -#endif +#endif return res; } @@ -1279,7 +1285,7 @@ ntpcal_ntp64_to_date( ) { ntpcal_split ds; - + ds = ntpcal_daysplit(ntp); ds.hi += ntpcal_daysec_to_date(jd, ds.lo); @@ -1294,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 @@ -1516,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; } @@ -1538,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. @@ -1576,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/work_fork.c b/libntp/work_fork.c index 10329e70be8f..dab02bc6af14 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; |