Blame SOURCES/ntp-4.2.6p5-cve-2015-8158.patch

6e16f6
diff -U0 ntp-4.2.6p5/ChangeLog.cve-2015-8158 ntp-4.2.6p5/ChangeLog
6e16f6
diff -up ntp-4.2.6p5/ntpdc/ntpdc.c.cve-2015-8158 ntp-4.2.6p5/ntpdc/ntpdc.c
6e16f6
--- ntp-4.2.6p5/ntpdc/ntpdc.c.cve-2015-8158	2016-01-20 14:06:21.035659659 +0100
6e16f6
+++ ntp-4.2.6p5/ntpdc/ntpdc.c	2016-01-20 14:25:39.734622168 +0100
6e16f6
@@ -657,6 +657,10 @@ getresponse(
6e16f6
 	fd_set fds;
6e16f6
 	int n;
6e16f6
 	int pad;
6e16f6
+	/* absolute timeout checks. Not 'time_t' by intention! */
6e16f6
+	uint32_t tobase;	/* base value for timeout */
6e16f6
+	uint32_t tospan;	/* timeout span (max delay) */
6e16f6
+	uint32_t todiff;	/* current delay */
6e16f6
 
6e16f6
 	/*
6e16f6
 	 * This is pretty tricky.  We may get between 1 and many packets
6e16f6
@@ -673,12 +677,14 @@ getresponse(
6e16f6
 	lastseq = 999;	/* too big to be a sequence number */
6e16f6
 	memset(haveseq, 0, sizeof(haveseq));
6e16f6
 	FD_ZERO(&fds);
6e16f6
+	tobase = (uint32_t)time(NULL);
6e16f6
 
6e16f6
     again:
6e16f6
 	if (firstpkt)
6e16f6
 		tvo = tvout;
6e16f6
 	else
6e16f6
 		tvo = tvsout;
6e16f6
+	tospan = (uint32_t)tvo.tv_sec + (tvo.tv_usec != 0);
6e16f6
 	
6e16f6
 	FD_SET(sockfd, &fds);
6e16f6
 	n = select(sockfd+1, &fds, (fd_set *)0, (fd_set *)0, &tvo);
6e16f6
@@ -687,6 +693,17 @@ getresponse(
6e16f6
 		warning("select fails", "", "");
6e16f6
 		return -1;
6e16f6
 	}
6e16f6
+	
6e16f6
+	/*
6e16f6
+	 * Check if this is already too late. Trash the data and fake a
6e16f6
+	 * timeout if this is so.
6e16f6
+	 */
6e16f6
+	todiff = (((uint32_t)time(NULL)) - tobase) & 0x7FFFFFFFu;
6e16f6
+	if ((n > 0) && (todiff > tospan)) {
6e16f6
+		n = recv(sockfd, (char *)&rpkt, sizeof(rpkt), 0);
6e16f6
+		n = 0; /* faked timeout return from 'select()'*/
6e16f6
+	}
6e16f6
+	
6e16f6
 	if (n == 0) {
6e16f6
 		/*
6e16f6
 		 * Timed out.  Return what we have
6e16f6
@@ -831,8 +848,10 @@ getresponse(
6e16f6
 	}
6e16f6
 
6e16f6
 	/*
6e16f6
-	 * So far, so good.  Copy this data into the output array.
6e16f6
+	 * So far, so good.  Copy this data into the output array. Bump
6e16f6
+	 * the timeout base, in case we expect more data.
6e16f6
 	 */
6e16f6
+	tobase = (uint32_t)time(NULL);
6e16f6
 	if ((datap + datasize + (pad * items)) > (pktdata + pktdatasize)) {
6e16f6
 		int offset = datap - pktdata;
6e16f6
 		growpktdata();
6e16f6
diff -up ntp-4.2.6p5/ntpq/ntpq.c.cve-2015-8158 ntp-4.2.6p5/ntpq/ntpq.c
6e16f6
--- ntp-4.2.6p5/ntpq/ntpq.c.cve-2015-8158	2016-01-20 14:06:21.493660755 +0100
6e16f6
+++ ntp-4.2.6p5/ntpq/ntpq.c	2016-01-20 14:13:56.132819820 +0100
6e16f6
@@ -836,6 +836,10 @@ getresponse(
6e16f6
 	int len;
6e16f6
 	int first;
6e16f6
 	char *data;
6e16f6
+	/* absolute timeout checks. Not 'time_t' by intention! */
6e16f6
+	uint32_t tobase;	/* base value for timeout */
6e16f6
+	uint32_t tospan;	/* timeout span (max delay) */
6e16f6
+	uint32_t todiff;	/* current delay */
6e16f6
 
6e16f6
 	/*
6e16f6
 	 * This is pretty tricky.  We may get between 1 and MAXFRAG packets
6e16f6
@@ -852,6 +856,8 @@ getresponse(
6e16f6
 	numfrags = 0;
6e16f6
 	seenlastfrag = 0;
6e16f6
 
6e16f6
+	tobase = (uint32_t)time(NULL);
6e16f6
+	
6e16f6
 	FD_ZERO(&fds);
6e16f6
 
6e16f6
 	/*
6e16f6
@@ -864,7 +870,8 @@ getresponse(
6e16f6
 			tvo = tvout;
6e16f6
 		else
6e16f6
 			tvo = tvsout;
6e16f6
-		
6e16f6
+		tospan = (uint32_t)tvo.tv_sec + (tvo.tv_usec != 0);
6e16f6
+
6e16f6
 		FD_SET(sockfd, &fds);
6e16f6
 		n = select(sockfd + 1, &fds, NULL, NULL, &tvo);
6e16f6
 
6e16f6
@@ -872,6 +879,17 @@ getresponse(
6e16f6
 			warning("select fails", "", "");
6e16f6
 			return -1;
6e16f6
 		}
6e16f6
+
6e16f6
+		/*
6e16f6
+		 * Check if this is already too late. Trash the data and
6e16f6
+		 * fake a timeout if this is so.
6e16f6
+		 */
6e16f6
+		todiff = (((uint32_t)time(NULL)) - tobase) & 0x7FFFFFFFu;
6e16f6
+		if ((n > 0) && (todiff > tospan)) {
6e16f6
+			n = recv(sockfd, (char *)&rpkt, sizeof(rpkt), 0);
6e16f6
+			n = 0; /* faked timeout return from 'select()'*/
6e16f6
+		}
6e16f6
+
6e16f6
 		if (n == 0) {
6e16f6
 			/*
6e16f6
 			 * Timed out.  Return what we have
6e16f6
@@ -1166,10 +1184,13 @@ getresponse(
6e16f6
 		}
6e16f6
 
6e16f6
 		/*
6e16f6
-		 * Copy the data into the data buffer.
6e16f6
+		 * Copy the data into the data buffer, and bump the
6e16f6
+		 * timout base in case we need more.
6e16f6
 		 */
6e16f6
 		memcpy((char *)pktdata + offset, rpkt.data, count);
6e16f6
 
6e16f6
+		tobase = (uint32_t)time(NULL);
6e16f6
+		
6e16f6
 		/*
6e16f6
 		 * If we've seen the last fragment, look for holes in the sequence.
6e16f6
 		 * If there aren't any, we're done.