[Nagiosplug-checkins] nagiosplug/plugins check_ntp.c,1.17,1.18

Holger Weiss hweiss at users.sourceforge.net
Sat Mar 31 20:48:19 CEST 2007


Update of /cvsroot/nagiosplug/nagiosplug/plugins
In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv1141

Modified Files:
	check_ntp.c 
Log Message:
Fix an out-of-bounds memcpy(3) and add a realloc(3) error check in
jitter_request().


Index: check_ntp.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_ntp.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- check_ntp.c	31 Mar 2007 17:35:08 -0000	1.17
+++ check_ntp.c	31 Mar 2007 18:48:17 -0000	1.18
@@ -506,6 +506,7 @@
 	ntp_control_message req;
 	double rval = 0.0, jitter = -1.0;
 	char *startofvalue=NULL, *nptr=NULL;
+	void *tmp;
 
 	/* Long-winded explanation:
 	 * Getting the jitter requires a number of steps:
@@ -539,8 +540,10 @@
 	 	 * we represent as a ntp_assoc_status_pair datatype.
 	 	 */
 		npeers+=(ntohs(req.count)/sizeof(ntp_assoc_status_pair));
-		peers=(ntp_assoc_status_pair*)realloc(peers, sizeof(ntp_assoc_status_pair)*npeers);
-		memcpy((void*)((ptrdiff_t)peers+peer_offset), (void*)req.data, sizeof(ntp_assoc_status_pair)*npeers);
+		if((tmp=realloc(peers, sizeof(ntp_assoc_status_pair)*npeers)) == NULL)
+			free(peers), die(STATE_UNKNOWN, "can not (re)allocate 'peers' buffer\n");
+		peers=tmp;
+		memcpy((void*)((ptrdiff_t)peers+peer_offset), (void*)req.data, ntohs(req.count));
 		peer_offset+=ntohs(req.count);
 	} while(req.op&REM_MORE);
 





More information about the Commits mailing list