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

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