summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbrian <brian@FreeBSD.org>1997-05-10 01:22:19 +0000
committerbrian <brian@FreeBSD.org>1997-05-10 01:22:19 +0000
commit82bac13560d095243e9988bfb770da73089749c1 (patch)
tree262cfd051516c08f29f6f133a950e9de9f2d42fd
parent1da867bda76bc701006945dfbc4733f550c91c2d (diff)
downloadFreeBSD-src-82bac13560d095243e9988bfb770da73089749c1.zip
FreeBSD-src-82bac13560d095243e9988bfb770da73089749c1.tar.gz
Tidy up the code - bounds checking, return
value checking etc. Submitted by: eivind
-rw-r--r--usr.sbin/ppp/auth.c18
-rw-r--r--usr.sbin/ppp/ccp.c7
-rw-r--r--usr.sbin/ppp/chap.c6
-rw-r--r--usr.sbin/ppp/chat.c50
-rw-r--r--usr.sbin/ppp/command.c41
-rw-r--r--usr.sbin/ppp/filter.c4
-rw-r--r--usr.sbin/ppp/filter.h4
-rw-r--r--usr.sbin/ppp/fsm.c4
-rw-r--r--usr.sbin/ppp/hdlc.c11
-rw-r--r--usr.sbin/ppp/ip.c6
-rw-r--r--usr.sbin/ppp/ipcp.c12
-rw-r--r--usr.sbin/ppp/lcp.c8
-rw-r--r--usr.sbin/ppp/main.c49
-rw-r--r--usr.sbin/ppp/mbuf.c12
-rw-r--r--usr.sbin/ppp/modem.c49
-rw-r--r--usr.sbin/ppp/pred.c11
-rw-r--r--usr.sbin/ppp/route.c4
-rw-r--r--usr.sbin/ppp/systems.c46
-rw-r--r--usr.sbin/ppp/timer.c10
19 files changed, 221 insertions, 131 deletions
diff --git a/usr.sbin/ppp/auth.c b/usr.sbin/ppp/auth.c
index 4ab98f2..29eb776 100644
--- a/usr.sbin/ppp/auth.c
+++ b/usr.sbin/ppp/auth.c
@@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: auth.c,v 1.10 1997/02/22 16:10:01 peter Exp $
+ * $Id: auth.c,v 1.11 1997/05/07 23:01:21 brian Exp $
*
* TODO:
* o Implement check against with registered IP addresses.
@@ -112,8 +112,12 @@ char *fname, *system, *key;
bzero(&DefHisAddress, sizeof(DefHisAddress));
n -= 2;
if (n > 0) {
- ParseAddr(n--, &vector[2],
- &DefHisAddress.ipaddr, &DefHisAddress.mask, &DefHisAddress.width);
+ if (ParseAddr(n--, &vector[2],
+ &DefHisAddress.ipaddr,
+ &DefHisAddress.mask,
+ &DefHisAddress.width) == 0) {
+ return(0); /* Invalid */
+ }
}
IpcpInit();
return(1); /* Valid */
@@ -156,9 +160,11 @@ int len, setaddr;
#ifdef DEBUG
LogPrintf(LOG_LCP_BIT, "*** n = %d, %s\n", n, vector[2]);
#endif
- ParseAddr(n--, &vector[2],
- &DefHisAddress.ipaddr, &DefHisAddress.mask, &DefHisAddress.width);
- IpcpInit();
+ if (ParseAddr(n--, &vector[2],
+ &DefHisAddress.ipaddr,
+ &DefHisAddress.mask,
+ &DefHisAddress.width) != 0)
+ IpcpInit();
}
return(passwd);
}
diff --git a/usr.sbin/ppp/ccp.c b/usr.sbin/ppp/ccp.c
index d50d367..99981fe 100644
--- a/usr.sbin/ppp/ccp.c
+++ b/usr.sbin/ppp/ccp.c
@@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id$
+ * $Id: ccp.c,v 1.10 1997/02/22 16:10:03 peter Exp $
*
* TODO:
* o Support other compression protocols
@@ -31,8 +31,6 @@
#include "pred.h"
#include "cdefs.h"
-extern void PutConfValue __P((void));
-
struct ccpstate CcpInfo;
static void CcpSendConfigReq __P((struct fsm *));
@@ -78,7 +76,7 @@ static char const *cftypes[] = {
/* 20 */ "V42BIS", "BSD",
};
-void
+int
ReportCcpStatus()
{
struct ccpstate *icp = &CcpInfo;
@@ -89,6 +87,7 @@ ReportCcpStatus()
cftypes[icp->want_proto], cftypes[icp->his_proto]);
printf("Input: %ld --> %ld, Output: %ld --> %ld\n",
icp->orgin, icp->compin, icp->orgout, icp->compout);
+ return 0;
}
void
diff --git a/usr.sbin/ppp/chap.c b/usr.sbin/ppp/chap.c
index f5bffb4..be677f56 100644
--- a/usr.sbin/ppp/chap.c
+++ b/usr.sbin/ppp/chap.c
@@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: chap.c,v 1.12 1997/03/17 14:47:55 ache Exp $
+ * $Id: chap.c,v 1.13 1997/03/24 16:01:42 ache Exp $
*
* TODO:
*/
@@ -153,6 +153,10 @@ struct mbuf *bp;
name = VarAuthName;
namelen = strlen(VarAuthName);
argp = malloc(1 + valsize + namelen + 16);
+ if (argp == NULL) {
+ ChapOutput(CHAP_FAILURE, chp->id, "Out of memory!", 14);
+ return;
+ }
digest = argp;
*digest++ = 16; /* value size */
ap = answer;
diff --git a/usr.sbin/ppp/chat.c b/usr.sbin/ppp/chat.c
index 4e1a24f..a0b7ae6 100644
--- a/usr.sbin/ppp/chat.c
+++ b/usr.sbin/ppp/chat.c
@@ -18,7 +18,7 @@
* Columbus, OH 43221
* (614)451-1883
*
- * $Id: chat.c,v 1.22 1997/03/13 12:45:28 brian Exp $
+ * $Id: chat.c,v 1.23 1997/05/07 23:01:23 brian Exp $
*
* TODO:
* o Support more UUCP compatible control sequences.
@@ -38,6 +38,7 @@
#include <sys/wait.h>
#include "timeout.h"
#include "vars.h"
+#include "chat.h"
#include "sig.h"
#include "chat.h"
@@ -255,8 +256,8 @@ char *estr;
char *s, *str, ch;
char *inp;
fd_set rfds;
- int i, nfds, nb, msg;
- char buff[200];
+ int i, nfds, nb;
+ char buff[IBSIZE];
#ifdef SIGALRM
@@ -270,13 +271,12 @@ char *estr;
inp = inbuff;
if (strlen(str)>=IBSIZE){
- str[IBSIZE]=0;
+ str[IBSIZE-1]=0;
LogPrintf(LOG_CHAT_BIT, "Truncating String to %d character: %s\n", IBSIZE, str);
}
nfds = modem + 1;
s = str;
- msg = FALSE;
for (;;) {
FD_ZERO(&rfds);
FD_SET(modem, &rfds);
@@ -302,7 +302,7 @@ char *estr;
} else if (i == 0) { /* Timeout reached! */
*inp = 0;
if (inp != inbuff)
- LogPrintf(LOG_CHAT_BIT, "got: %s\n", inbuff);
+ LogPrintf(LOG_CHAT_BIT, "got: %s\n", inbuff);
LogPrintf(LOG_CHAT_BIT, "can't get (%d).\n", timeout.tv_sec);
#ifdef SIGALRM
sigsetmask(omask);
@@ -337,7 +337,11 @@ char *estr;
}
}
} else {
- read(modem, &ch, 1);
+ if (read(modem, &ch, 1) < 0) {
+ perror("read error");
+ *inp = '\0';
+ return(NOMATCH);
+ }
connect_log(&ch,1);
*inp++ = ch;
if (ch == *s) {
@@ -376,9 +380,6 @@ char *estr;
}
}
}
-#ifdef SIGALRM
- sigsetmask(omask);
-#endif
}
void
@@ -401,10 +402,19 @@ char *command, *out;
}
cp--;
}
- snprintf(tmp, sizeof tmp, "%s %s", command, cp);
+ if (snprintf(tmp, sizeof tmp, "%s %s", command, cp) >= sizeof tmp) {
+ LogPrintf(LOG_CHAT_BIT, "Too long string to ExecStr: \"%s\"\n",
+ command);
+ return;
+ }
(void) MakeArgs(tmp, vector, VECSIZE(vector));
- pipe(fids);
+ if (pipe(fids) < 0) {
+ LogPrintf(LOG_CHAT_BIT, "Unable to create pipe in ExecStr: %s\n",
+ strerror(errno));
+ return;
+ }
+
pid = fork();
if (pid == 0) {
TermTimerService();
@@ -414,10 +424,18 @@ char *command, *out;
signal(SIGHUP, SIG_DFL);
signal(SIGALRM, SIG_DFL);
close(fids[0]);
- dup2(fids[1], 1);
+ if (dup2(fids[1], 1) < 0) {
+ LogPrintf(LOG_CHAT_BIT, "dup2(fids[1], 1) in ExecStr: %s\n",
+ strerror(errno));
+ return;
+ }
close(fids[1]);
nb = open("/dev/tty", O_RDWR);
- dup2(nb, 0);
+ if (dup2(nb, 0) < 0) {
+ LogPrintf(LOG_CHAT_BIT, "dup2(nb, 0) in ExecStr: %s\n",
+ strerror(errno));
+ return;
+ }
LogPrintf(LOG_CHAT_BIT, "exec: %s\n", command);
/* switch back to original privileges */
if (setgid(getgid()) < 0) {
@@ -451,7 +469,7 @@ SendString(str)
char *str;
{
char *cp;
- int nb, on;
+ int on;
char buff[200];
if (abort_next) {
@@ -481,7 +499,7 @@ char *str;
else
cp += 2;
on = strlen(cp);
- nb = write(modem, cp, on);
+ write(modem, cp, on);
}
}
diff --git a/usr.sbin/ppp/command.c b/usr.sbin/ppp/command.c
index 36d398c..64d5f80 100644
--- a/usr.sbin/ppp/command.c
+++ b/usr.sbin/ppp/command.c
@@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: command.c,v 1.41 1997/05/08 01:26:31 brian Exp $
+ * $Id: command.c,v 1.42 1997/05/09 23:34:56 brian Exp $
*
*/
#include <sys/types.h>
@@ -34,7 +34,8 @@
#include "command.h"
#include "hdlc.h"
#include "vars.h"
-#include "auth.h"
+#include "systems.h"
+#include "chat.h"
#include <netdb.h>
#include <sys/socket.h>
#include <arpa/inet.h>
@@ -223,10 +224,10 @@ char **argv;
argv[i] = strdup(inet_ntoa(IpcpInfo.want_ipaddr));
}
}
- execvp(argv[0], argv);
+ (void)execvp(argv[0], argv);
}
else
- execl(shell, shell, NULL);
+ (void)execl(shell, shell, NULL);
fprintf(stdout, "exec() of %s failed\n", argc > 0? argv[0]: shell);
exit(255);
@@ -563,7 +564,7 @@ int prompt;
}
}
if (val && prompt)
- Prompt(0);
+ Prompt();
}
static int
@@ -884,19 +885,30 @@ char **argv;
{
DefMyAddress.ipaddr.s_addr = DefHisAddress.ipaddr.s_addr = 0L;
+ if (argc > 4) {
+ printf("set ifaddr: too many arguments (%d > 4)\n", argc);
+ return(0);
+ }
if (argc > 0) {
- ParseAddr(argc, argv++,
- &DefMyAddress.ipaddr, &DefMyAddress.mask, &DefMyAddress.width);
+ if (ParseAddr(argc, argv++,
+ &DefMyAddress.ipaddr,
+ &DefMyAddress.mask,
+ &DefMyAddress.width) == 0)
+ return(0);
if (--argc > 0) {
- ParseAddr(argc, argv++,
- &DefHisAddress.ipaddr, &DefHisAddress.mask, &DefHisAddress.width);
+ if (ParseAddr(argc, argv++,
+ &DefHisAddress.ipaddr,
+ &DefHisAddress.mask,
+ &DefHisAddress.width) == 0)
+ return(0);
if (--argc > 0) {
ifnetmask = GetIpAddr(*argv);
if (--argc > 0) {
- ParseAddr(argc, argv++,
- &DefTriggerAddress.ipaddr,
- &DefTriggerAddress.mask,
- &DefTriggerAddress.width);
+ if (ParseAddr(argc, argv++,
+ &DefTriggerAddress.ipaddr,
+ &DefTriggerAddress.mask,
+ &DefTriggerAddress.width) == 0)
+ return(0);
}
}
}
@@ -915,7 +927,8 @@ char **argv;
if ((mode & MODE_AUTO) ||
((mode & MODE_DEDICATED) && dstsystem)) {
- OsSetIpaddress(DefMyAddress.ipaddr, DefHisAddress.ipaddr, ifnetmask);
+ if (OsSetIpaddress(DefMyAddress.ipaddr, DefHisAddress.ipaddr, ifnetmask) < 0)
+ return(0);
}
return(1);
}
diff --git a/usr.sbin/ppp/filter.c b/usr.sbin/ppp/filter.c
index 7aef281..4fd4a67 100644
--- a/usr.sbin/ppp/filter.c
+++ b/usr.sbin/ppp/filter.c
@@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id$
+ * $Id: filter.c,v 1.8 1997/02/22 16:10:12 peter Exp $
*
* TODO: Shoud send ICMP error message when we discard packets.
*/
@@ -67,7 +67,7 @@ int *pwidth;
return(0);
}
- pmask->s_addr = -1; /* Assume 255.255.255.255 as default */
+ pmask->s_addr = 0xffffffff; /* Assume 255.255.255.255 as default */
cp = index(*argv, '/');
if (cp) *cp++ = '\0';
addr = inet_addr(*argv);
diff --git a/usr.sbin/ppp/filter.h b/usr.sbin/ppp/filter.h
index e087ee0..365412b 100644
--- a/usr.sbin/ppp/filter.h
+++ b/usr.sbin/ppp/filter.h
@@ -15,7 +15,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id$
+ * $Id: filter.h,v 1.6 1997/02/22 16:10:12 peter Exp $
*
* TODO:
*/
@@ -80,4 +80,4 @@ struct filterent dfilters[MAXFILTERS];
struct filterent afilters[MAXFILTERS]; /* keep Alive packet filter */
extern int ParseAddr __P((int, char **, struct in_addr *, struct in_addr *, int*));
-#endif _FILTER_H_
+#endif /* _FILTER_H_ */
diff --git a/usr.sbin/ppp/fsm.c b/usr.sbin/ppp/fsm.c
index 550e78d..e923511 100644
--- a/usr.sbin/ppp/fsm.c
+++ b/usr.sbin/ppp/fsm.c
@@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id$
+ * $Id: fsm.c,v 1.9 1997/02/22 16:10:13 peter Exp $
*
* TODO:
* o Refer loglevel for log output
@@ -350,7 +350,7 @@ struct mbuf *bp;
return;
case ST_CLOSING:
case ST_STOPPING:
-logprintf("## state = %d\n", fp->state);
+ logprintf("## state = %d\n", fp->state);
pfree(bp);
return;
}
diff --git a/usr.sbin/ppp/hdlc.c b/usr.sbin/ppp/hdlc.c
index ab2048f..8b44981 100644
--- a/usr.sbin/ppp/hdlc.c
+++ b/usr.sbin/ppp/hdlc.c
@@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: hdlc.c,v 1.12 1997/04/19 09:25:58 phk Exp $
+ * $Id: hdlc.c,v 1.13 1997/04/19 11:31:38 ache Exp $
*
* TODO:
*/
@@ -108,10 +108,7 @@ HdlcInit()
* 2.27 for further details.
*/
inline u_short
-HdlcFcs(fcs, cp, len)
-u_short fcs;
-u_char *cp;
-int len;
+HdlcFcs(u_short fcs, u_char *cp, int len)
{
while (len--)
fcs = (fcs >> 8) ^ fcstab[(fcs ^ *cp++) & 0xff];
@@ -200,9 +197,7 @@ HdlcOutput(int pri, u_short proto, struct mbuf *bp)
}
void
-DecodePacket(proto, bp)
-u_short proto;
-struct mbuf *bp;
+DecodePacket(u_short proto, struct mbuf *bp)
{
#ifdef DEBUG
logprintf("proto = %04x\n", proto);
diff --git a/usr.sbin/ppp/ip.c b/usr.sbin/ppp/ip.c
index 8d13cc5..3d73275 100644
--- a/usr.sbin/ppp/ip.c
+++ b/usr.sbin/ppp/ip.c
@@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: ip.c,v 1.14 1997/02/22 16:10:18 peter Exp $
+ * $Id: ip.c,v 1.15 1997/04/21 01:01:45 brian Exp $
*
* TODO:
* o Return ICMP message for filterd packet
@@ -389,11 +389,10 @@ IpStartOutput()
{
struct mqueue *queue;
struct mbuf *bp;
- int pri, cnt;
+ int cnt;
if (IpcpFsm.state != ST_OPENED)
return;
- pri = PRI_FAST;
for (queue = &IpOutputQueues[PRI_FAST]; queue >= IpOutputQueues; queue--) {
if (queue->top) {
bp = Dequeue(queue);
@@ -405,6 +404,5 @@ IpStartOutput()
break;
}
}
- pri--;
}
}
diff --git a/usr.sbin/ppp/ipcp.c b/usr.sbin/ppp/ipcp.c
index 3f13f1f..fc00b62 100644
--- a/usr.sbin/ppp/ipcp.c
+++ b/usr.sbin/ppp/ipcp.c
@@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id$
+ * $Id: ipcp.c,v 1.13 1997/02/22 16:10:20 peter Exp $
*
* TODO:
* o More RFC1772 backwoard compatibility
@@ -118,7 +118,7 @@ IpcpStartReport()
StartTimer(&IpcpReportTimer);
}
-void
+int
ReportIpcpStatus()
{
struct ipcpstate *icp = &IpcpInfo;
@@ -137,6 +137,7 @@ ReportIpcpStatus()
inet_ntoa(DefHisAddress.ipaddr), DefHisAddress.width);
printf(" Negotiation: %s/%d\n",
inet_ntoa(DefTriggerAddress.ipaddr), DefTriggerAddress.width);
+ return 0;
}
void
@@ -267,12 +268,15 @@ struct fsm *fp;
#ifdef VERBOSE
fprintf(stderr, "%s: LayerUp(%d).\r\n", fp->name, fp->state);
#endif
- Prompt(1);
+ Prompt();
LogPrintf(LOG_LCP_BIT, "%s: LayerUp.\n", fp->name);
snprintf(tbuff, sizeof(tbuff), "myaddr = %s ",
inet_ntoa(IpcpInfo.want_ipaddr));
LogPrintf(LOG_LCP_BIT|LOG_LINK_BIT, " %s hisaddr = %s\n", tbuff, inet_ntoa(IpcpInfo.his_ipaddr));
- OsSetIpaddress(IpcpInfo.want_ipaddr, IpcpInfo.his_ipaddr, ifnetmask);
+ if (OsSetIpaddress(IpcpInfo.want_ipaddr, IpcpInfo.his_ipaddr, ifnetmask) < 0) {
+ printf("unable to set ip address\n");
+ return;
+ }
OsLinkup();
IpcpStartReport();
StartIdleTimer();
diff --git a/usr.sbin/ppp/lcp.c b/usr.sbin/ppp/lcp.c
index 5b5a5c6..4bc0ebf 100644
--- a/usr.sbin/ppp/lcp.c
+++ b/usr.sbin/ppp/lcp.c
@@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: lcp.c,v 1.13 1997/03/13 21:22:06 brian Exp $
+ * $Id: lcp.c,v 1.14 1997/05/05 23:45:15 brian Exp $
*
* TODO:
* o Validate magic number received from peer.
@@ -350,7 +350,7 @@ struct fsm *fp;
#ifdef VERBOSE
fprintf(stderr, "%s: LayerFinish\r\n", fp->name);
#endif
- Prompt(1);
+ Prompt();
LogPrintf(LOG_LCP_BIT, "%s: LayerFinish\n", fp->name);
#ifdef notdef
OsCloseLink(0);
@@ -359,7 +359,7 @@ struct fsm *fp;
#endif
NewPhase(PHASE_DEAD);
StopAllTimers();
- OsInterfaceDown(0);
+ (void)OsInterfaceDown(0);
}
static void
@@ -388,7 +388,7 @@ struct fsm *fp;
StopAllTimers();
OsLinkdown();
NewPhase(PHASE_TERMINATE);
- Prompt(1);
+ Prompt();
}
void
diff --git a/usr.sbin/ppp/main.c b/usr.sbin/ppp/main.c
index 8c50561..755c449 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.45 1997/04/21 01:01:48 brian Exp $
+ * $Id: main.c,v 1.46 1997/05/04 02:39:03 ache Exp $
*
* TODO:
* o Add commands for traffic summary, version display, etc.
@@ -61,13 +61,12 @@
#endif
extern void VjInit(), AsyncInit();
-extern void AsyncInput(), IpOutput();
+extern void AsyncInput();
extern int SelectSystem();
extern void DecodeCommand(), Prompt();
extern int aft_cmd;
extern int IsInteractive();
-extern struct in_addr ifnetmask;
static void DoLoop(void);
static void TerminalStop();
@@ -87,8 +86,10 @@ TtyInit()
int stat;
stat = fcntl(0, F_GETFL, 0);
- stat |= O_NONBLOCK;
- fcntl(0, F_SETFL, stat);
+ if (stat > 0) {
+ stat |= O_NONBLOCK;
+ (void)fcntl(0, F_SETFL, stat);
+ }
newtio = oldtio;
newtio.c_lflag &= ~(ECHO|ISIG|ICANON);
newtio.c_iflag = 0;
@@ -120,10 +121,12 @@ int prompt;
newtio.c_oflag |= OPOST;
tcsetattr(0, TCSADRAIN, &newtio);
stat = fcntl(0, F_GETFL, 0);
- stat |= O_NONBLOCK;
- fcntl(0, F_SETFL, stat);
+ if (stat > 0) {
+ stat |= O_NONBLOCK;
+ (void)fcntl(0, F_SETFL, stat);
+ }
TermMode = 0;
- if(prompt) Prompt(0);
+ if(prompt) Prompt();
}
/*
@@ -136,8 +139,10 @@ TtyTermMode()
tcsetattr(0, TCSADRAIN, &comtio);
stat = fcntl(0, F_GETFL, 0);
- stat &= ~O_NONBLOCK;
- fcntl(0, F_SETFL, stat);
+ if (stat > 0) {
+ stat &= ~O_NONBLOCK;
+ (void)fcntl(0, F_SETFL, stat);
+ }
TermMode = 1;
}
@@ -147,8 +152,10 @@ TtyOldMode()
int stat;
stat = fcntl(0, F_GETFL, 0);
- stat &= ~O_NONBLOCK;
- fcntl(0, F_SETFL, stat);
+ if (stat > 0) {
+ stat &= ~O_NONBLOCK;
+ (void)fcntl(0, F_SETFL, stat);
+ }
tcsetattr(0, TCSANOW, &oldtio);
}
@@ -390,12 +397,6 @@ char **argv;
if (mode & MODE_DIRECT)
printf("Packet mode enabled.\n");
-#ifdef notdef
- if (mode & MODE_AUTO) {
- OsSetIpaddress(IpcpInfo.want_ipaddr, IpcpInfo.his_ipaddr, ifnetmask);
- }
-#endif
-
if (!(mode & MODE_INTER)) {
int port = SERVER_PORT + tunno;
if (mode & MODE_BACKGROUND) {
@@ -422,7 +423,9 @@ char **argv;
fprintf(stderr, "Wait for a while, then try again.\n");
Cleanup(EX_SOCK);
}
- listen(server, 5);
+ if (listen(server, 5) != 0) {
+ fprintf(stderr, "Unable to listen to socket - OS overload?\n");
+ }
}
DupLog();
@@ -927,7 +930,7 @@ DoLoop()
break;
}
(void) IsInteractive();
- Prompt(0);
+ Prompt();
}
if ((mode & MODE_INTER) && (netfd >= 0 && FD_ISSET(netfd, &rfds)) &&
@@ -963,18 +966,12 @@ DoLoop()
write(1, "\r\n", 2);
}
PacketMode();
-#ifdef notdef
- AsyncInput(cp, n - (cp - rbuff));
-#endif
} else
write(1, rbuff, n);
}
} else {
if (n > 0)
AsyncInput(rbuff, n);
-#ifdef notdef
- continue; /* THIS LINE RESULT AS POOR PERFORMANCE */
-#endif
}
}
}
diff --git a/usr.sbin/ppp/mbuf.c b/usr.sbin/ppp/mbuf.c
index e3d9004..7454726 100644
--- a/usr.sbin/ppp/mbuf.c
+++ b/usr.sbin/ppp/mbuf.c
@@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id$
+ * $Id: mbuf.c,v 1.5 1997/02/22 16:10:34 peter Exp $
*
*/
#include "defs.h"
@@ -51,8 +51,18 @@ int type;
if (type > MB_MAX)
logprintf("bad type %d\n", type);
bp = (struct mbuf *)malloc(sizeof(struct mbuf));
+ if (bp == NULL) {
+ logprintf("failed to allocate memory: %u\n", sizeof(struct mbuf));
+ fprintf(stderr,"failed to allocate memory: %u\n", sizeof(struct mbuf));
+ exit(0);
+ }
bzero(bp, sizeof(struct mbuf));
p = (u_char *)malloc(cnt);
+ if (p == NULL) {
+ logprintf("failed to allocate memory: %d\n", cnt);
+ fprintf(stderr,"failed to allocate memory: %d\n", cnt);
+ exit(0);
+ }
MemMap[type].count += cnt;
totalalloced += cnt;
bp->base = p;
diff --git a/usr.sbin/ppp/modem.c b/usr.sbin/ppp/modem.c
index fb0bb3c..ce36331 100644
--- a/usr.sbin/ppp/modem.c
+++ b/usr.sbin/ppp/modem.c
@@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: modem.c,v 1.33 1997/04/13 00:54:44 brian Exp $
+ * $Id: modem.c,v 1.34 1997/04/21 01:01:53 brian Exp $
*
* TODO:
*/
@@ -238,7 +238,11 @@ ModemTimeout()
StartTimer(&ModemTimer);
if (dev_is_modem) {
- ioctl(modem, TIOCMGET, &mbits);
+ if (ioctl(modem, TIOCMGET, &mbits) < 0) {
+ LogPrintf(LOG_PHASE_BIT, "ioctl error (%s)!\n", strerror(errno));
+ DownConnection();
+ return;
+ }
change = ombits ^ mbits;
if (change & TIOCM_CD) {
if (Online) {
@@ -475,7 +479,10 @@ int mode;
*/
rstio.c_cflag &= ~(CSIZE|PARODD|PARENB);
rstio.c_cflag |= VarParity;
- cfsetspeed(&rstio, IntToSpeed(VarSpeed));
+ if (cfsetspeed(&rstio, IntToSpeed(VarSpeed)) == -1) {
+ logprintf("Unable to set modem speed (modem %d to %d)\n",
+ modem, VarSpeed);
+ }
}
tcsetattr(modem, TCSADRAIN, &rstio);
#ifdef DEBUG
@@ -484,13 +491,16 @@ int mode;
#endif
if (!(mode & MODE_DIRECT))
- ioctl(modem, TIOCMGET, &mbits);
+ if (ioctl(modem, TIOCMGET, &mbits))
+ return(-1);
#ifdef DEBUG
fprintf(stderr, "modem control = %o\n", mbits);
#endif
oldflag = fcntl(modem, F_GETFL, 0);
- fcntl(modem, F_SETFL, oldflag & ~O_NONBLOCK);
+ if (oldflag < 0)
+ return(-1);
+ (void)fcntl(modem, F_SETFL, oldflag & ~O_NONBLOCK);
}
StartModemTimer();
@@ -537,7 +547,9 @@ int modem;
rstio.c_cflag |= HUPCL;
tcsetattr(modem, TCSADRAIN, &rstio);
oldflag = fcntl(modem, F_GETFL, 0);
- fcntl(modem, F_SETFL, oldflag | O_NONBLOCK);
+ if (oldflag < 0)
+ return(-1);
+ (void)fcntl(modem, F_SETFL, oldflag | O_NONBLOCK);
#ifdef DEBUG
oldflag = fcntl(modem, F_GETFL, 0);
logprintf("modem (put2): iflag = %x, oflag = %x, cflag = %x\n",
@@ -556,7 +568,9 @@ int modem;
if (isatty(modem) && !DEV_IS_SYNC) {
tcsetattr(modem, TCSAFLUSH, &modemios);
oldflag = fcntl(modem, F_GETFL, 0);
- fcntl(modem, F_SETFL, oldflag & ~O_NONBLOCK);
+ if (oldflag < 0)
+ return;
+ (void)fcntl(modem, F_SETFL, oldflag & ~O_NONBLOCK);
}
}
@@ -579,7 +593,9 @@ int flag;
ioctl(modem, TIOCMSET, &mbits);
#else
tcgetattr(modem, &tio);
- cfsetspeed(&tio, B0);
+ if (cfsetspeed(&tio, B0) == -1) {
+ logprintf("Unable to set modem to speed 0\n");
+ }
tcsetattr(modem, TCSANOW, &tio);
#endif
sleep(1);
@@ -685,12 +701,17 @@ ModemStartOutput(fd)
int fd;
{
struct mqueue *queue;
- int nb, nw, i;
+ int nb, nw;
+#ifdef QDEBUG
+ int i;
+#endif
if (modemout == NULL && ModemQlen() == 0)
IpStartOutput();
if (modemout == NULL) {
+#ifdef QDEBUG
i = PRI_LINK;
+#endif
for (queue = &OutputQueues[PRI_LINK]; queue >= OutputQueues; queue--) {
if (queue->top) {
modemout = Dequeue(queue);
@@ -705,7 +726,9 @@ int fd;
#endif
break;
}
+#ifdef QDEBUG
i--;
+#endif
}
}
if (modemout) {
@@ -764,7 +787,7 @@ DialModem()
}
}
HangupModem(0);
- return(0);
+ return(excode);
}
int
@@ -803,8 +826,10 @@ ShowModemStatus()
#endif
printf("connect count: %d\n", connect_count);
#ifdef TIOCOUTQ
- ioctl(modem, TIOCOUTQ, &nb);
- printf("outq: %d\n", nb);
+ if (ioctl(modem, TIOCOUTQ, &nb) > 0)
+ printf("outq: %d\n", nb);
+ else
+ printf("outq: ioctl probe failed.\n");
#endif
printf("outqlen: %d\n", ModemQlen());
printf("DialScript = %s\n", VarDialScript);
diff --git a/usr.sbin/ppp/pred.c b/usr.sbin/ppp/pred.c
index 587f8bf..e9b76a2 100644
--- a/usr.sbin/ppp/pred.c
+++ b/usr.sbin/ppp/pred.c
@@ -5,7 +5,7 @@
/*
*
- * $Id$
+ * $Id: pred.c,v 1.9 1997/02/22 16:10:47 peter Exp $
*
* pred.c -- Test program for Dave Rand's rendition of the
* predictor algorithm
@@ -20,8 +20,8 @@
* A better hash function would result in additional compression,
* at the expense of time.
*/
-#define IHASH(x) iHash = (iHash << 4) ^ (x)
-#define OHASH(x) oHash = (oHash << 4) ^ (x)
+#define IHASH(x) do {iHash = (iHash << 4) ^ (x);} while(0)
+#define OHASH(x) do {oHash = (oHash << 4) ^ (x);} while(0)
static unsigned short int iHash, oHash;
static unsigned char InputGuessTable[65536];
@@ -111,10 +111,7 @@ int direction;
}
void
-Pred1Output(pri, proto, bp)
-int pri;
-u_short proto;
-struct mbuf *bp;
+Pred1Output(int pri, u_short proto, struct mbuf *bp)
{
struct mbuf *mwp;
u_char *cp, *wp, *hp;
diff --git a/usr.sbin/ppp/route.c b/usr.sbin/ppp/route.c
index da143d8..c475935 100644
--- a/usr.sbin/ppp/route.c
+++ b/usr.sbin/ppp/route.c
@@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id$
+ * $Id: route.c,v 1.12 1997/02/22 16:10:49 peter Exp $
*
*/
#include <sys/types.h>
@@ -412,7 +412,7 @@ char *name;
#endif
if (strcmp(ifrp->ifr_name, name) == 0) {
IfIndex = index;
- free(buffer);
+ free(buffer);
return(index);
}
index++;
diff --git a/usr.sbin/ppp/systems.c b/usr.sbin/ppp/systems.c
index 0e7be24..dc59e3c 100644
--- a/usr.sbin/ppp/systems.c
+++ b/usr.sbin/ppp/systems.c
@@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id$
+ * $Id: systems.c,v 1.9 1997/02/22 16:10:56 peter Exp $
*
* TODO:
*/
@@ -47,8 +47,14 @@ static void
SetUserId()
{
if (!usermode) {
- setreuid(euid, uid);
- setregid(egid, gid);
+ if (setreuid(euid, uid) == -1) {
+ logprintf("unable to setreuid!\n");
+ exit(1);
+ }
+ if (setregid(egid, gid) == -1) {
+ logprintf("unable to setregid!\n");
+ exit(1);
+ }
usermode = 1;
}
}
@@ -57,8 +63,14 @@ static void
SetPppId()
{
if (usermode) {
- setreuid(uid, euid);
- setregid(gid, egid);
+ if (setreuid(uid, euid) == -1) {
+ logprintf("unable to setreuid!\n");
+ exit(1);
+ }
+ if (setregid(gid, egid) == -1) {
+ logprintf("unable to setregid!\n");
+ exit(1);
+ }
usermode = 0;
}
}
@@ -110,30 +122,35 @@ char *file;
int val = -1;
u_char olauth;
char line[200];
+ char filename[200];
+ int linenum;
fp = NULL;
cp = getenv("HOME");
if (cp) {
SetUserId();
- snprintf(line, sizeof line, "%s/.%s", cp, file);
- fp = fopen(line, "r");
+ snprintf(filename, sizeof filename, "%s/.%s", cp, file);
+ fp = fopen(filename, "r");
}
if (fp == NULL) {
SetPppId(); /* fix from pdp@ark.jr3uom.iijnet.or.jp */
- snprintf(line, sizeof line, "%s/%s", _PATH_PPP, file);
- fp = fopen(line, "r");
+ snprintf(filename, sizeof filename, "%s/%s", _PATH_PPP, file);
+ fp = fopen(filename, "r");
}
if (fp == NULL) {
#ifdef DEBUG
- fprintf(stderr, "can't open %s.\n", line);
+ fprintf(stderr, "can't open %s.\n", filename);
#endif
SetPppId();
return(-1);
}
#ifdef DEBUG
- fprintf(stderr, "checking %s (%s).\n", name, line);
+ fprintf(stderr, "checking %s (%s).\n", name, filename);
#endif
+
+ linenum = 0;
while (fgets(line, sizeof(line), fp)) {
+ linenum++;
cp = line;
switch (*cp) {
case '#': /* comment */
@@ -143,6 +160,11 @@ char *file;
break;
default:
wp = strpbrk(cp, ":\n");
+ if (wp == NULL) {
+ fprintf(stderr, "Bad rule in %s (line %d) - missing colon.\n",
+ filename, linenum);
+ exit(1);
+ }
*wp = '\0';
if (strcmp(cp, name) == 0) {
while (fgets(line, sizeof(line), fp)) {
@@ -196,8 +218,6 @@ char **argv;
return(1);
}
-extern struct in_addr ifnetmask;
-
int
SaveCommand(list, argc, argv)
struct cmdtab *list;
diff --git a/usr.sbin/ppp/timer.c b/usr.sbin/ppp/timer.c
index 116de6a..fbc46d9 100644
--- a/usr.sbin/ppp/timer.c
+++ b/usr.sbin/ppp/timer.c
@@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: timer.c,v 1.14 1997/03/13 12:45:26 brian Exp $
+ * $Id: timer.c,v 1.15 1997/05/09 20:48:21 brian Exp $
*
* TODO:
*/
@@ -274,7 +274,9 @@ void InitTimerService( void ) {
pending_signal(SIGALRM, (void (*)(int))TimerService);
itimer.it_interval.tv_sec = itimer.it_value.tv_sec = 0;
itimer.it_interval.tv_usec = itimer.it_value.tv_usec = TICKUNIT;
- setitimer(ITIMER_REAL, &itimer, NULL);
+ if (setitimer(ITIMER_REAL, &itimer, NULL) == -1) {
+ logprintf("Unable to set itimer.\n");
+ }
}
void TermTimerService( void ) {
@@ -282,7 +284,9 @@ void TermTimerService( void ) {
itimer.it_interval.tv_usec = itimer.it_interval.tv_sec = 0;
itimer.it_value.tv_usec = itimer.it_value.tv_sec = 0;
- setitimer(ITIMER_REAL, &itimer, NULL);
+ if (setitimer(ITIMER_REAL, &itimer, NULL) == -1) {
+ logprintf("Unable to set itimer.\n");
+ }
pending_signal(SIGALRM, SIG_IGN);
}
#endif
OpenPOWER on IntegriCloud