summaryrefslogtreecommitdiffstats
path: root/plugins/t
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/t')
0 files changed, 0 insertions, 0 deletions
diff --git a/plugins/check_ntp.c b/plugins/check_ntp.c
index 99fa9a2..8a08af5 100644
--- a/plugins/check_ntp.c
+++ b/plugins/check_ntp.c
@@ -501,7 +501,7 @@ setup_control_request(ntp_control_message *p, uint8_t opcode, uint16_t seq){
501double jitter_request(const char *host, int *status){ 501double jitter_request(const char *host, int *status){
502 int conn=-1, i, npeers=0, num_candidates=0, syncsource_found=0; 502 int conn=-1, i, npeers=0, num_candidates=0, syncsource_found=0;
503 int run=0, min_peer_sel=PEER_INCLUDED, num_selected=0, num_valid=0; 503 int run=0, min_peer_sel=PEER_INCLUDED, num_selected=0, num_valid=0;
504 int peer_offset=0; 504 int peers_size=0, peer_offset=0;
505 ntp_assoc_status_pair *peers=NULL; 505 ntp_assoc_status_pair *peers=NULL;
506 ntp_control_message req; 506 ntp_control_message req;
507 double rval = 0.0, jitter = -1.0; 507 double rval = 0.0, jitter = -1.0;
@@ -539,11 +539,12 @@ double jitter_request(const char *host, int *status){
539 /* Each peer identifier is 4 bytes in the data section, which 539 /* Each peer identifier is 4 bytes in the data section, which
540 * we represent as a ntp_assoc_status_pair datatype. 540 * we represent as a ntp_assoc_status_pair datatype.
541 */ 541 */
542 npeers+=(ntohs(req.count)/sizeof(ntp_assoc_status_pair)); 542 peers_size+=ntohs(req.count);
543 if((tmp=realloc(peers, sizeof(ntp_assoc_status_pair)*npeers)) == NULL) 543 if((tmp=realloc(peers, peers_size)) == NULL)
544 free(peers), die(STATE_UNKNOWN, "can not (re)allocate 'peers' buffer\n"); 544 free(peers), die(STATE_UNKNOWN, "can not (re)allocate 'peers' buffer\n");
545 peers=tmp; 545 peers=tmp;
546 memcpy((void*)((ptrdiff_t)peers+peer_offset), (void*)req.data, ntohs(req.count)); 546 memcpy((void*)((ptrdiff_t)peers+peer_offset), (void*)req.data, ntohs(req.count));
547 npeers=peers_size/sizeof(ntp_assoc_status_pair);
547 peer_offset+=ntohs(req.count); 548 peer_offset+=ntohs(req.count);
548 } while(req.op&REM_MORE); 549 } while(req.op&REM_MORE);
549 550
@@ -596,8 +597,8 @@ double jitter_request(const char *host, int *status){
596 printf("parsing jitter from peer %.2x: ", ntohs(peers[i].assoc)); 597 printf("parsing jitter from peer %.2x: ", ntohs(peers[i].assoc));
597 } 598 }
598 startofvalue = strchr(req.data, '='); 599 startofvalue = strchr(req.data, '=');
599 if(startofvalue != NULL) startofvalue++;
600 if(startofvalue != NULL) { 600 if(startofvalue != NULL) {
601 startofvalue++;
601 jitter = strtod(startofvalue, &nptr); 602 jitter = strtod(startofvalue, &nptr);
602 } 603 }
603 if(startofvalue == NULL || startofvalue==nptr){ 604 if(startofvalue == NULL || startofvalue==nptr){
@@ -618,7 +619,7 @@ double jitter_request(const char *host, int *status){
618 rval = num_valid ? rval / num_valid : -1.0; 619 rval = num_valid ? rval / num_valid : -1.0;
619 620
620 close(conn); 621 close(conn);
621 free(peers); 622 if(peers!=NULL) free(peers);
622 /* If we return -1.0, it means no synchronization source was found */ 623 /* If we return -1.0, it means no synchronization source was found */
623 return rval; 624 return rval;
624} 625}