[cvslog] (2005-11-14 04:44:54 UTC) Module eggdrop1.9: Change committed!

cvslog cvs at tsss.org
Sun Nov 13 22:44:54 CST 2005


CVSROOT    : /usr/local/cvsroot
Module     : eggdrop1.9
Commit time: 2005-11-14 04:44:53 UTC
Commited by: Will Buckner <wcc at techmonkeys.org>

Modified files:
     lib/eggdrop/partychan.c lib/eggdrop/sockbuf.c
     modules/dccparty/dccparty.c modules/ircparty/ircparty.c
     modules/javascript/javascript.c modules/perlscript/perlscript.c
     modules/tclscript/tclscript.c modules/telnetparty/telnetparty.c

Log message:

I'll just quote Sven :)

"While working on a python scripting module for eggdrop1.9 I found a few
bugs, patch attached:

1. memcpy is used for overlapping memory areas in lib/eggdrop/partychan.c

2. Prevent reading from or writing to a socket <=0 otherwise the
following could happen: eof detected -> on_eof handlers called ->
on_quit called -> write something to the sockbuf -> eof detected ...

3. Under certain conditions some memory blocks were freed twice.
(Hopefully) fixed it and added a warning for developers. This part is
extremely non-obvious I'm not 100% sure I got it right but at least it
doesn't crah anymore if you disconnect and reconnect a telnet connection
on AMD32 archs.

4. The my_scriptname_callbacker functions used some kind of pointer
magic on the stack to get their parameters. This worked on IA32 but not
on architectures that don't pass their function parameters over the
stack, like AMD64. It uses the stdarg macros now."

---------------------- diff included ----------------------
Index: eggdrop1.9/lib/eggdrop/partychan.c
diff -u eggdrop1.9/lib/eggdrop/partychan.c:1.20 eggdrop1.9/lib/eggdrop/partychan.c:1.21
--- eggdrop1.9/lib/eggdrop/partychan.c:1.20	Wed Jun 22 14:45:11 2005
+++ eggdrop1.9/lib/eggdrop/partychan.c	Sun Nov 13 22:44:43 2005
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: partychan.c,v 1.20 2005/06/22 19:45:11 darko Exp $";
+static const char rcsid[] = "$Id: partychan.c,v 1.21 2005/11/14 04:44:43 wcc Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -307,7 +307,7 @@
 	/* Remove the channel entry from the member. */
 	if (!(p->flags & PARTY_DELETED)) for (i = 0; i < p->nchannels; i++) {
 		if (p->channels[i] == chan) {
-			memcpy(p->channels+i, p->channels+i+1, sizeof(chan) * (p->nchannels-i-1));
+			memmove(p->channels+i, p->channels+i+1, sizeof(chan) * (p->nchannels-i-1));
 			p->nchannels--;
 			break;
 		}
Index: eggdrop1.9/lib/eggdrop/sockbuf.c
diff -u eggdrop1.9/lib/eggdrop/sockbuf.c:1.18 eggdrop1.9/lib/eggdrop/sockbuf.c:1.19
--- eggdrop1.9/lib/eggdrop/sockbuf.c:1.18	Mon May 30 22:35:08 2005
+++ eggdrop1.9/lib/eggdrop/sockbuf.c	Sun Nov 13 22:44:43 2005
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: sockbuf.c,v 1.18 2005/05/31 03:35:08 stdarg Exp $";
+static const char rcsid[] = "$Id: sockbuf.c,v 1.19 2005/11/14 04:44:43 wcc Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -174,6 +174,7 @@
 	int nbytes = 0;
 	sockbuf_t *sbuf = &sockbufs[idx];
 
+	if (sbuf->sock <= 0) return 0;
 	/* If it's not blocked already, write as much as we can. */
 	if (!(sbuf->flags & SOCKBUF_BLOCK)) {		
 		nbytes = write (sbuf->sock, data, len);
@@ -414,6 +415,7 @@
 	char buf[4097];
 	int nbytes;
 
+	if (sbuf->sock <= 0) return;
 	errno = 0;
 	nbytes = read(sbuf->sock, buf, sizeof(buf)-1);
 	if (nbytes > 0) {
Index: eggdrop1.9/modules/dccparty/dccparty.c
diff -u eggdrop1.9/modules/dccparty/dccparty.c:1.9 eggdrop1.9/modules/dccparty/dccparty.c:1.10
--- eggdrop1.9/modules/dccparty/dccparty.c:1.9	Sun Oct 17 00:14:06 2004
+++ eggdrop1.9/modules/dccparty/dccparty.c	Sun Nov 13 22:44:43 2005
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: dccparty.c,v 1.9 2004/10/17 05:14:06 stdarg Exp $";
+static const char rcsid[] = "$Id: dccparty.c,v 1.10 2005/11/14 04:44:43 wcc Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -217,9 +217,12 @@
 		if (!err) errmsg = "Client disconnected";
 		else if (!errmsg) errmsg = "Unknown error";
 		partymember_delete(session->party, errmsg);
-		session->party = NULL;
+		/* This will call our on_quit handler which will delete the sockbuf
+		 * which will call our on_delete handler which will kill the session.
+		 * Summery: All the data is gone, don't touch any of the variables */
+	} else {
+		sockbuf_delete(idx);
 	}
-	sockbuf_delete(idx);
 	return(0);
 }
 
Index: eggdrop1.9/modules/ircparty/ircparty.c
diff -u eggdrop1.9/modules/ircparty/ircparty.c:1.13 eggdrop1.9/modules/ircparty/ircparty.c:1.14
--- eggdrop1.9/modules/ircparty/ircparty.c:1.13	Sun Oct 17 00:14:06 2004
+++ eggdrop1.9/modules/ircparty/ircparty.c	Sun Nov 13 22:44:43 2005
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: ircparty.c,v 1.13 2004/10/17 05:14:06 stdarg Exp $";
+static const char rcsid[] = "$Id: ircparty.c,v 1.14 2005/11/14 04:44:43 wcc Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -319,9 +319,12 @@
 		if (!err) errmsg = "Client disconnected";
 		else if (!errmsg) errmsg = "Unknown error";
 		partymember_delete(session->party, errmsg);
-		session->party = NULL;
+		/* This will call our on_quit handler which will delete the sockbuf
+		 * which will call our on_delete handler which will kill the session.
+		 * Summery: All the data is gone, don't touch any of the variables */
+	} else {
+		sockbuf_delete(idx);
 	}
-	sockbuf_delete(idx);
 	return(0);
 }
 
Index: eggdrop1.9/modules/javascript/javascript.c
diff -u eggdrop1.9/modules/javascript/javascript.c:1.25 eggdrop1.9/modules/javascript/javascript.c:1.26
--- eggdrop1.9/modules/javascript/javascript.c:1.25	Wed Jun 23 06:19:52 2004
+++ eggdrop1.9/modules/javascript/javascript.c	Sun Nov 13 22:44:43 2005
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: javascript.c,v 1.25 2004/06/23 11:19:52 wingman Exp $";
+static const char rcsid[] = "$Id: javascript.c,v 1.26 2005/11/14 04:44:43 wcc Exp $";
 #endif
 
 #include <stdio.h>
@@ -271,23 +271,24 @@
 	script_var_t var;
 	my_callback_cd_t *cd; /* My callback client data */
 	int i, n, retval = 0;
-	void **al;
+	va_list va;
 
 	/* This struct contains the interp and the obj command. */
 	cd = (my_callback_cd_t *)me->callback_data;
 
-	al = (void **)&me;
-	al++;
 	if (me->syntax) n = strlen(me->syntax);
 	else n = 0;
 
 	argv = (jsval *)malloc(n * sizeof(jsval));
+	va_start(va, me);
 	for (i = 0; i < n; i++) {
 		var.type = me->syntax[i];
-		var.value = al[i];
+		if (var.type == SCRIPT_INTEGER || var.type == SCRIPT_UNSIGNED) var.value = (void *) (va_arg(va, int));
+		else var.value = va_arg(va, void *);
 		var.len = -1;
 		c_to_js_var(cd->mycx, &var, argv+i);
 	}
+	va_end(va);
 
 	mycx = cd->mycx;
 	myobj = cd->myobj;
Index: eggdrop1.9/modules/perlscript/perlscript.c
diff -u eggdrop1.9/modules/perlscript/perlscript.c:1.29 eggdrop1.9/modules/perlscript/perlscript.c:1.30
--- eggdrop1.9/modules/perlscript/perlscript.c:1.29	Sat Dec 20 02:13:41 2003
+++ eggdrop1.9/modules/perlscript/perlscript.c	Sun Nov 13 22:44:43 2005
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: perlscript.c,v 1.29 2003/12/20 08:13:41 stdarg Exp $";
+static const char rcsid[] = "$Id: perlscript.c,v 1.30 2005/11/14 04:44:43 wcc Exp $";
 #endif
 
 #ifdef DEBUG
@@ -204,24 +204,25 @@
 	int retval, i, n, count;
 	script_var_t var;
 	SV *cmd, *arg;
-	int *al;
+	va_list va;
 	dSP;
 
 	ENTER;
 	SAVETMPS;
 	PUSHMARK(SP);
 
-	al = (int *)&me;
-	al++;
 	if (me->syntax) n = strlen(me->syntax);
 	else n = 0;
+	va_start(va, me);
 	for (i = 0; i < n; i++) {
 		var.type = me->syntax[i];
-		var.value = (void *)al[i];
+		if (var.type == SCRIPT_INTEGER || var.type == SCRIPT_UNSIGNED) var.value = (void *) (va_arg(va, int));
+		else var.value = va_arg(va, void *);
 		var.len = -1;
 		arg = c_to_perl_var(&var);
 		XPUSHs(sv_2mortal(arg));
 	}
+	va_end(va);
 	PUTBACK;
 
 	/* If it's a one-time callback, delete it. */
Index: eggdrop1.9/modules/tclscript/tclscript.c
diff -u eggdrop1.9/modules/tclscript/tclscript.c:1.47 eggdrop1.9/modules/tclscript/tclscript.c:1.48
--- eggdrop1.9/modules/tclscript/tclscript.c:1.47	Wed Jun 23 06:19:52 2004
+++ eggdrop1.9/modules/tclscript/tclscript.c	Sun Nov 13 22:44:43 2005
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: tclscript.c,v 1.47 2004/06/23 11:19:52 wingman Exp $";
+static const char rcsid[] = "$Id: tclscript.c,v 1.48 2005/11/14 04:44:43 wcc Exp $";
 #endif
 
 #include <string.h>
@@ -236,7 +236,7 @@
 	script_var_t var;
 	my_callback_cd_t *cd; /* My callback client data */
 	int i, n, retval;
-	script_callback_t **al;
+	va_list va;
 
 	/* This struct contains the interp and the obj command. */
 	cd = (my_callback_cd_t *)me->callback_data;
@@ -244,18 +244,19 @@
 	/* Get a copy of the command, then append args. */
 	final_command = Tcl_DuplicateObj(cd->command);
 
-	al = &me;
-	al++;
 	if (me->syntax) n = strlen(me->syntax);
 	else n = 0;
 
+	va_start(va, me);
 	for (i = 0; i < n; i++) {
 		var.type = me->syntax[i];
-		var.value = al[i];
+		if (var.type == SCRIPT_INTEGER || var.type == SCRIPT_UNSIGNED) var.value = (void *) (va_arg(va, int));
+		else var.value = va_arg(va, void *);
 		var.len = -1;
 		arg = c_to_tcl_var(cd->myinterp, &var);
 		Tcl_ListObjAppendElement(cd->myinterp, final_command, arg);
 	}
+	va_end(va);
 
 	interp = cd->myinterp;
 
Index: eggdrop1.9/modules/telnetparty/telnetparty.c
diff -u eggdrop1.9/modules/telnetparty/telnetparty.c:1.19 eggdrop1.9/modules/telnetparty/telnetparty.c:1.20
--- eggdrop1.9/modules/telnetparty/telnetparty.c:1.19	Sun Oct 17 00:14:07 2004
+++ eggdrop1.9/modules/telnetparty/telnetparty.c	Sun Nov 13 22:44:43 2005
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
-static const char rcsid[] = "$Id: telnetparty.c,v 1.19 2004/10/17 05:14:07 stdarg Exp $";
+static const char rcsid[] = "$Id: telnetparty.c,v 1.20 2005/11/14 04:44:43 wcc Exp $";
 #endif
 
 #include <eggdrop/eggdrop.h>
@@ -425,9 +425,12 @@
 		if (!err) errmsg = "Client disconnected";
 		else if (!errmsg) errmsg = "Unknown error";
 		partymember_delete(session->party, errmsg);
-		session->party = NULL;
+		/* This will call our on_quit handler which will delete the sockbuf
+		 * which will call our on_delete handler which will kill the session.
+		 * Summery: All the data is gone, don't touch any of the variables */
+	} else {
+		sockbuf_delete(idx);
 	}
-	sockbuf_delete(idx);
 	return(0);
 }
 
----------------------- End of diff -----------------------



More information about the Changes mailing list