]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 2614] use 'unsigned long' consistently in 'ntp_random.c' to avoid undefined...
authorJuergen Perlinger <perlinger@ntp.org>
Fri, 20 Jun 2014 08:59:35 +0000 (10:59 +0200)
committerJuergen Perlinger <perlinger@ntp.org>
Fri, 20 Jun 2014 08:59:35 +0000 (10:59 +0200)
bk: 53a3f7f7qk_lca6aq2yDT1X0wRntpA

ChangeLog
libntp/ntp_random.c

index 72669a26da045956cb67eca6320c225eaddcecfc..15c62f5a99c0dc8ad024659df26e34c455ef3726 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,5 @@
+* [Bug 2614] use 'unsigned long' consistently in ntp_random.c
+  to avoid possibly undefined behaviour in signed int overflow
 (4.2.7p445) 2014/06/12 Released by Harlan Stenn <stenn@ntp.org>
 * [Bug 2556] mrulist isn't mentioned in the ntpq man page.
 (4.2.7p444) 2014/05/19 Released by Harlan Stenn <stenn@ntp.org>
index 9765679a8a767ea8d2aca8cea9e560de4af6128d..0ada44f256b042fc5f6c7286013890dc5a7e8cdc 100644 (file)
@@ -191,8 +191,8 @@ static unsigned long randtbl[DEG_3 + 1] = {
  * in the initialization of randtbl) because the state table pointer is set
  * to point to randtbl[1] (as explained below).
  */
-static long *fptr = (long *)&randtbl[SEP_3 + 1];
-static long *rptr = (long *)&randtbl[1];
+static unsigned long *fptr = &randtbl[SEP_3 + 1];
+static unsigned long *rptr = &randtbl[1];
 
 /*
  * The following things are the pointer to the state information table, the
@@ -204,11 +204,11 @@ static long *rptr = (long *)&randtbl[1];
  * this is more efficient than indexing every time to find the address of
  * the last element to see if the front and rear pointers have wrapped.
  */
-static long *state = (long *)&randtbl[1];
+static unsigned long *state = &randtbl[1];
 static long rand_type = TYPE_3;
 static long rand_deg = DEG_3;
 static long rand_sep = SEP_3;
-static long *end_ptr = (long *)&randtbl[DEG_3 + 1];
+static unsigned long *end_ptr = &randtbl[DEG_3 + 1];
 
 static inline long good_rand (long);
 
@@ -384,7 +384,7 @@ ntp_initstate(
                rand_deg = DEG_4;
                rand_sep = SEP_4;
        }
-       state = (long *) (long_arg_state + 1); /* first location */
+       state = (unsigned long *) (long_arg_state + 1); /* first location */
        end_ptr = &state[rand_deg];     /* must set end_ptr before srandom */
        ntp_srandom(seed);
        if (rand_type == TYPE_0)
@@ -418,7 +418,7 @@ ntp_setstate(
        char *arg_state                 /* pointer to state array */
        )
 {
-       register long *new_state = (long *) arg_state;
+       register unsigned long *new_state = (unsigned long *) arg_state;
        register long type = new_state[0] % MAX_TYPES;
        register long rear = new_state[0] / MAX_TYPES;
        char *ostate = (char *)(&state[-1]);
@@ -441,7 +441,7 @@ ntp_setstate(
                (void)fprintf(stderr,
                    "random: state info corrupted; not changed.\n");
        }
-       state = (long *) (new_state + 1);
+       state = (new_state + 1);
        if (rand_type != TYPE_0) {
                rptr = &state[rear];
                fptr = &state[(rear + rand_sep) % rand_deg];
@@ -473,7 +473,7 @@ long
 ntp_random( void )
 {
        register long i;
-       register long *f, *r;
+       register unsigned long *f, *r;
 
        if (rand_type == TYPE_0) {
                i = state[0];