bugfix
Hezekiah <[email protected]>
| Newsgroups | gmane.comp.security.invisiblenet.iip.devel |
|---|---|
| Message-ID | <[email protected]> |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
The following bug was mentioned in yesterday's meeting:
When isproxy is already running, and another instance is started, the second
instance will comlain of not being able to bind to the right port, but won't
bomb out.
This was because the error wasn't checked for. I have added a little code
that causes isproxy to check for failure to bind the socket and exits if it
can't. I have pasted the cvs diff thingy I was able to make below. (Sorry
that I couldn't come up with a real patch, but I had a small nightmare with
cvs diff. Let's just say that I haven't had a lot of experiance working with
it.) :)
You might want to check this code to make sure it does any necisarry cleanup
correctly. I'm not really familiar with IIP's code yet, so I might have made a
few mistakes.
Sincerely,
Hezekiah
Index: iip/iip.c
===================================================================
RCS file: /cvsroot/invisibleip/iip/src/iip/iip.c,v
retrieving revision 1.28
diff -u -3 -p -r1.28 iip.c
- --- iip/iip.c 9 Oct 2002 01:44:42 -0000 1.28
+++ iip/iip.c 9 Oct 2002 15:53:19 -0000
@@ -292,9 +292,7 @@ int init() {
#endif
// enter the main loop
- - coreMainLoop();
- -
- - return 0;
+ return !coreMainLoop() ? 0 : 30; //todo: what exit code should this
be?
}
Index: msgcore/core.c
===================================================================
RCS file: /cvsroot/invisibleip/iip/src/msgcore/core.c,v
retrieving revision 1.9
diff -u -3 -p -r1.9 core.c
- --- msgcore/core.c 9 Oct 2002 01:44:26 -0000 1.9
+++ msgcore/core.c 9 Oct 2002 15:53:32 -0000
@@ -216,23 +216,25 @@ void coreProcessMessageQueue(void) {
}
}
- -void coreStart(void) {
+int coreStart(void) {
// NodeRef *nr = noderefMake();
sockservInit(coreAddInSock);
coreInit();
- - sockservStartListen();
+ // abort if we couldn't start up the socket(s)
+ if(sockservStartListen()) {return -1;}
// noderefInit(nr, "0.0.0.0", "plain", localPort);
// sockservListen(nr);
// noderefFree(nr);
+ return 0; // success
}
- -void coreMainLoop(void) {
+int coreMainLoop(void) {
//int i = 0;
- - coreStart();
+ if(coreStart()) {return -1;}
while(1) {
#ifdef _WINDOZE_
if(dowindows()) {
@@ -241,6 +243,8 @@ void coreMainLoop(void) {
#endif
coreMainPoll(0);
}
+
+ return 0; // success
}
void coreMainPoll(int shortdelay) {
Index: msgcore/core.h
===================================================================
RCS file: /cvsroot/invisibleip/iip/src/msgcore/core.h,v
retrieving revision 1.3
diff -u -3 -p -r1.3 core.h
- --- msgcore/core.h 9 Oct 2002 01:44:26 -0000 1.3
+++ msgcore/core.h 9 Oct 2002 15:53:38 -0000
@@ -11,12 +11,12 @@ void coreInit(void);
void coreAddInSock(SockHandle *sh, int *result);
PipeFace *coreMakeConnection(int retries);
void coreSwapPipeFace(PipeFace *oldpf, PipeFace *newpf);
- -void coreMainLoop(void);
+int coreMainLoop(void);
void coreMainPoll(int shortdelay);
void coreProcessMessageQueue(void);
void coreProcessPipeFace(void);
- -void coreStart(void);
+int coreStart(void);
#endif //CORE_CORE_H
Index: net/sockserv.c
===================================================================
RCS file: /cvsroot/invisibleip/iip/src/net/sockserv.c,v
retrieving revision 1.5
diff -u -3 -p -r1.5 sockserv.c
- --- net/sockserv.c 9 Oct 2002 01:46:12 -0000 1.5
+++ net/sockserv.c 9 Oct 2002 15:55:39 -0000
@@ -285,11 +285,11 @@ SockHandle *sockservListen(NodeRef *nr)
return sh;
}
- -void sockservStartListen(void) {
+int sockservStartListen(void) {
int i;
//sockservInit();
if(SocksListening == NULL) {
- - return;
+ return 1;
}
//close any open listening sockets
for(i = 0; i < SocksListening->size; i++) {
@@ -312,7 +312,26 @@ void sockservStartListen(void) {
")",
ptrToString(&LNRA->data[i]),
NULL));
- - sockservListen(&LNRA->data[i]);
+ if(!sockservListen(&LNRA->data[i])) { // if the listen failed
+ //close any open listening sockets
+ for(i = 0; i < SocksListening->size; i++) {
+ if(SocksListening->data[i] != NULL) {
+ LOGDEBUG(stringJoinMany(
+ "sockservStartListen:Close:(",
+ intToString(i),
+ ")",
+ ptrToString(SocksListening->data[i]),
+ NULL));
+
+ sockClose(SocksListening->data[i]);
+ sockFree(SocksListening->data[i]);
+ SocksListening->data[i] = NULL;
+ }
+ }
+
+ return -1; // can't bind the socket; bail out
+ }
}
+ return 0; // success
}
Index: net/sockserv.h
===================================================================
RCS file: /cvsroot/invisibleip/iip/src/net/sockserv.h,v
retrieving revision 1.2
diff -u -3 -p -r1.2 sockserv.h
- --- net/sockserv.h 9 Oct 2002 01:46:12 -0000 1.2
+++ net/sockserv.h 9 Oct 2002 15:55:43 -0000
@@ -28,7 +28,7 @@ void sockservProcess(int shortdelay);
SockHandle *sockservConnect(void);
SockHandle *sockservListen(NodeRef *nr);
- -void sockservStartListen(void);
+int sockservStartListen(void);
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
iD8DBQE9pFgHeHiZTMH32ioRAtodAJ9iMSCEOp5XGsEU6forJyhTZ85PEQCdEsal
8YfotOZPqHf0TrsCY7K8ytY=
=aHT4
-----END PGP SIGNATURE-----