From 1bc9b5ba8459c0f2350adc754669890bc2f8bf6e Mon Sep 17 00:00:00 2001 From: Brian Somers Date: Wed, 6 May 1998 18:50:12 +0000 Subject: [PATCH] o Make sure we don't dereference NULL when we've lost all our links. o Use srandomdev() for __FreeBSD__ >= 2, not just >2. o Use srandom((time(NULL)^getpid())+random()), random() when we haven't got srandomdev(). --- usr.sbin/ppp/bundle.c | 30 +++++++++++++++++++++++------- usr.sbin/ppp/bundle.h | 3 ++- usr.sbin/ppp/defs.c | 6 +++--- usr.sbin/ppp/main.c | 10 ++++------ usr.sbin/ppp/mp.c | 6 ++++-- 5 files changed, 36 insertions(+), 19 deletions(-) diff --git a/usr.sbin/ppp/bundle.c b/usr.sbin/ppp/bundle.c index 4aa8f66b9ea6..5fb8a218acab 100644 --- a/usr.sbin/ppp/bundle.c +++ b/usr.sbin/ppp/bundle.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: bundle.c,v 1.1.2.72 1998/05/05 23:29:55 brian Exp $ + * $Id: bundle.c,v 1.1.2.73 1998/05/06 18:49:36 brian Exp $ */ #include @@ -347,6 +347,15 @@ bundle_Close(struct bundle *bundle, const char *name, int staydown) datalink_Close(this_dl, staydown); } +void +bundle_Down(struct bundle *bundle) +{ + struct datalink *dl; + + for (dl = bundle->links; dl; dl = dl->next) + datalink_Down(dl, 1); +} + static int bundle_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e, int *n) { @@ -363,7 +372,7 @@ bundle_UpdateSet(struct descriptor *d, fd_set *r, fd_set *w, fd_set *e, int *n) result += descriptor_UpdateSet(desc, r, w, e, n); /* If there are aren't many packets queued, look for some more. */ - if (bundle_FillQueues(bundle) < 20) { + if (bundle->links && bundle_FillQueues(bundle) < 20) { if (*n < bundle->tun_fd + 1) *n = bundle->tun_fd + 1; FD_SET(bundle->tun_fd, r); @@ -904,12 +913,19 @@ bundle_FillQueues(struct bundle *bundle) { int total; - if (bundle->ncp.mp.active) { + if (bundle->ncp.mp.active) total = mp_FillQueues(bundle); - } else { - total = link_QueueLen(&bundle->links->physical->link); - if (total == 0 && bundle->links->physical->out == NULL) - total = ip_FlushPacket(&bundle->links->physical->link, bundle); + else { + struct datalink *dl; + int add; + + for (total = 0, dl = bundle->links; dl; dl = dl->next) + if (dl->state == DATALINK_OPEN) { + add = link_QueueLen(&dl->physical->link); + if (add == 0 && dl->physical->out == NULL) + add = ip_FlushPacket(&dl->physical->link, bundle); + total += add; + } } return total + ip_QueueLen(); diff --git a/usr.sbin/ppp/bundle.h b/usr.sbin/ppp/bundle.h index b89e8908bd53..3714ee84d903 100644 --- a/usr.sbin/ppp/bundle.h +++ b/usr.sbin/ppp/bundle.h @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: bundle.h,v 1.1.2.35 1998/05/02 21:57:44 brian Exp $ + * $Id: bundle.h,v 1.1.2.36 1998/05/05 23:29:57 brian Exp $ */ #define PHASE_DEAD 0 /* Link is dead */ @@ -113,6 +113,7 @@ extern int bundle_LinkIsUp(const struct bundle *); extern int bundle_SetRoute(struct bundle *, int, struct in_addr, struct in_addr, struct in_addr, int); extern void bundle_Close(struct bundle *, const char *, int); +extern void bundle_Down(struct bundle *); extern void bundle_Open(struct bundle *, const char *, int); extern void bundle_LinkClosed(struct bundle *, struct datalink *); diff --git a/usr.sbin/ppp/defs.c b/usr.sbin/ppp/defs.c index e55c648454cc..6a6a361ca7e2 100644 --- a/usr.sbin/ppp/defs.c +++ b/usr.sbin/ppp/defs.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: defs.c,v 1.11.4.9 1998/04/23 03:22:50 brian Exp $ + * $Id: defs.c,v 1.11.4.10 1998/04/30 23:53:35 brian Exp $ */ @@ -37,7 +37,7 @@ void randinit() { -#if __FreeBSD__ > 2 +#if __FreeBSD__ >= 2 static int initdone; if (!initdone) { @@ -45,7 +45,7 @@ randinit() srandomdev(); } #else - srandom(time(NULL)^getpid()); + srandom((time(NULL)^getpid())+random()); #endif } diff --git a/usr.sbin/ppp/main.c b/usr.sbin/ppp/main.c index 3dbc928f9dbe..7c62cfa1316c 100644 --- a/usr.sbin/ppp/main.c +++ b/usr.sbin/ppp/main.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: main.c,v 1.121.2.54 1998/05/01 19:25:16 brian Exp $ + * $Id: main.c,v 1.121.2.55 1998/05/06 18:49:42 brian Exp $ * * TODO: */ @@ -110,12 +110,9 @@ static void CloseConnection(int signo) { /* NOTE, these are manual, we've done a setsid() */ - struct datalink *dl; - sig_signal(SIGINT, SIG_IGN); log_Printf(LogPHASE, "Caught signal %d, abort connection(s)\n", signo); - for (dl = SignalBundle->links; dl; dl = dl->next) - datalink_Down(dl, 1); + bundle_Down(SignalBundle); sig_signal(SIGINT, CloseConnection); } @@ -493,7 +490,7 @@ DoLoop(struct bundle *bundle, struct prompt *prompt) sig_Handle(); - /* This one comes first 'cos it may nuke a datalink */ + /* This may nuke a datalink */ descriptor_UpdateSet(&bundle->ncp.mp.server.desc, &rfds, &wfds, &efds, &nfds); descriptor_UpdateSet(&bundle->desc, &rfds, &wfds, &efds, &nfds); @@ -529,6 +526,7 @@ DoLoop(struct bundle *bundle, struct prompt *prompt) if (descriptor_IsSet(&bundle->desc, &wfds)) descriptor_Write(&bundle->desc, bundle, &wfds); + /* This may add a datalink */ if (descriptor_IsSet(&bundle->desc, &rfds)) descriptor_Read(&bundle->desc, bundle, &rfds); } while (bundle_CleanDatalinks(bundle), !bundle_IsDead(bundle)); diff --git a/usr.sbin/ppp/mp.c b/usr.sbin/ppp/mp.c index 4d489cf79c7e..234380674575 100644 --- a/usr.sbin/ppp/mp.c +++ b/usr.sbin/ppp/mp.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: mp.c,v 1.1.2.22 1998/05/04 03:00:08 brian Exp $ + * $Id: mp.c,v 1.1.2.23 1998/05/04 21:42:41 brian Exp $ */ #include @@ -542,6 +542,8 @@ mp_FillQueues(struct bundle *bundle) if (!fdl) { fdl = bundle->links; + if (!fdl) + return 0; thislink = 0; } @@ -859,7 +861,7 @@ mpserver_Read(struct descriptor *d, struct bundle *bundle, const fd_set *fdset) return; } - if (in.sa_family == AF_LOCAL) /* ??? */ + if (in.sa_family == AF_LOCAL) bundle_ReceiveDatalink(bundle, fd, (struct sockaddr_un *)&in); close(fd);