From 6196c77a4f4facc2f6df34cdf2ce02f3d5f5083c Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Wed, 14 Jun 2017 14:06:01 +0000 Subject: [PATCH 1/2] zebra: fix divide-by-zero x % 0 = FPE Signed-off-by: Quentin Young --- zebra/irdp_interface.c | 31 +++++++++++-------------------- zebra/irdp_main.c | 3 ++- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/zebra/irdp_interface.c b/zebra/irdp_interface.c index 5cabe7e62f..6ea14b3058 100644 --- a/zebra/irdp_interface.c +++ b/zebra/irdp_interface.c @@ -476,18 +476,14 @@ DEFUN (ip_irdp_minadvertinterval, zi=ifp->info; irdp=&zi->irdp; - if( (unsigned) atoi(argv[idx_number]->arg) <= irdp->MaxAdvertInterval) { + if((unsigned) atoi(argv[idx_number]->arg) < irdp->MaxAdvertInterval) { irdp->MinAdvertInterval = atoi(argv[idx_number]->arg); - return CMD_SUCCESS; } - - vty_out (vty, "ICMP warning maxadvertinterval is greater or equal than minadvertinterval%s", - VTY_NEWLINE); - - vty_out (vty, "Please correct!%s", - VTY_NEWLINE); - return CMD_WARNING; + else { + vty_out (vty, "%% MinAdvertInterval must be less than MaxAdvertInterval"); + return CMD_WARNING; + } } DEFUN (ip_irdp_maxadvertinterval, @@ -506,19 +502,14 @@ DEFUN (ip_irdp_maxadvertinterval, zi=ifp->info; irdp=&zi->irdp; - - if( irdp->MinAdvertInterval <= (unsigned) atoi(argv[idx_number]->arg) ) { - irdp->MaxAdvertInterval = atoi(argv[idx_number]->arg); - + if(irdp->MinAdvertInterval < (unsigned) atoi(argv[idx_number]->arg)) { + irdp->MaxAdvertInterval = atoi(argv[idx_number]->arg); return CMD_SUCCESS; } - - vty_out (vty, "ICMP warning maxadvertinterval is greater or equal than minadvertinterval%s", - VTY_NEWLINE); - - vty_out (vty, "Please correct!%s", - VTY_NEWLINE); - return CMD_WARNING; + else { + vty_out (vty, "%% MaxAdvertInterval must be greater than MinAdvertInterval"); + return CMD_WARNING; + } } /* DEFUN needs to be fixed for negative ranages... diff --git a/zebra/irdp_main.c b/zebra/irdp_main.c index 7fa4ad4cbe..8f1647c9db 100644 --- a/zebra/irdp_main.c +++ b/zebra/irdp_main.c @@ -234,7 +234,8 @@ int irdp_send_thread(struct thread *t_advert) } tmp = irdp->MaxAdvertInterval-irdp->MinAdvertInterval; - timer = (random () % tmp ) + 1; + assert (tmp > 0); + timer = (random () % tmp) + 1; timer = irdp->MinAdvertInterval + timer; if(irdp->irdp_sent < MAX_INITIAL_ADVERTISEMENTS && From 11e2897282839b66f7566b056c14b2558d2df354 Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Fri, 16 Jun 2017 16:18:54 +0000 Subject: [PATCH 2/2] zebra: more dbzing Revert to the previous <= restrictions, improve error messages, fix the divide by zero. Signed-off-by: Quentin Young --- zebra/irdp_interface.c | 10 ++++++---- zebra/irdp_main.c | 3 +-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/zebra/irdp_interface.c b/zebra/irdp_interface.c index 6ea14b3058..407738d80f 100644 --- a/zebra/irdp_interface.c +++ b/zebra/irdp_interface.c @@ -476,12 +476,13 @@ DEFUN (ip_irdp_minadvertinterval, zi=ifp->info; irdp=&zi->irdp; - if((unsigned) atoi(argv[idx_number]->arg) < irdp->MaxAdvertInterval) { + if((unsigned) atoi(argv[idx_number]->arg) <= irdp->MaxAdvertInterval) { irdp->MinAdvertInterval = atoi(argv[idx_number]->arg); return CMD_SUCCESS; } else { - vty_out (vty, "%% MinAdvertInterval must be less than MaxAdvertInterval"); + vty_out (vty, "%% MinAdvertInterval must be less than or equal to " + "MaxAdvertInterval%s", VTY_NEWLINE); return CMD_WARNING; } } @@ -502,12 +503,13 @@ DEFUN (ip_irdp_maxadvertinterval, zi=ifp->info; irdp=&zi->irdp; - if(irdp->MinAdvertInterval < (unsigned) atoi(argv[idx_number]->arg)) { + if(irdp->MinAdvertInterval <= (unsigned) atoi(argv[idx_number]->arg)) { irdp->MaxAdvertInterval = atoi(argv[idx_number]->arg); return CMD_SUCCESS; } else { - vty_out (vty, "%% MaxAdvertInterval must be greater than MinAdvertInterval"); + vty_out (vty, "%% MaxAdvertInterval must be greater than or equal to " + "MinAdvertInterval%s", VTY_NEWLINE); return CMD_WARNING; } } diff --git a/zebra/irdp_main.c b/zebra/irdp_main.c index 8f1647c9db..6965dca3e4 100644 --- a/zebra/irdp_main.c +++ b/zebra/irdp_main.c @@ -234,8 +234,7 @@ int irdp_send_thread(struct thread *t_advert) } tmp = irdp->MaxAdvertInterval-irdp->MinAdvertInterval; - assert (tmp > 0); - timer = (random () % tmp) + 1; + timer = random () % (tmp + 1); timer = irdp->MinAdvertInterval + timer; if(irdp->irdp_sent < MAX_INITIAL_ADVERTISEMENTS &&