[Raw Msg Headers][Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Race condition in smtpserver?
On Thu, 6 Nov 1997, Swen Thuemmler wrote:
> The patch is below, I think it is correct.
Since the patch is very large because i changend indentation, here is a
minimal patch (diff -bu):
diff -ubr zmailer-2.99.49p8.orig/smtpserver/smtpserver.c zmailer-2.99.49p8/smtpserver/smtpserver.c
--- zmailer-2.99.49p8.orig/smtpserver/smtpserver.c Tue Oct 14 01:21:56 1997
+++ zmailer-2.99.49p8/smtpserver/smtpserver.c Thu Nov 6 11:06:47 1997
@@ -757,6 +757,12 @@
sameipcount = childsameip(&SS.raddr);
+ /* We simply -- and FAST -- reject the
+ remote when it exceeds 4 times the
+ limit */
+ if (sameipcount > 4 * MaxSameIpSource) {
+ close(msgfd);
+ } else {
if ((childpid = fork()) < 0) { /* can't fork! */
close(msgfd);
fprintf(stderr,
@@ -768,14 +774,6 @@
close(s); /* Listening socket.. */
pid = getpid();
- /* We query, and warn the remote when
- the count exceeds the limit, and we
- simply -- and FAST -- reject the
- remote when it exceeds 4 times the
- limit */
- if (sameipcount > 4 * MaxSameIpSource)
- exit(0);
-
if (msgfd != 0)
dup2(msgfd, 0);
dup2(0, 1);
@@ -849,6 +847,9 @@
strcpy(msg, "450 Come again latter\r\n");
len = strlen(msg);
write(msgfd, msg, len);
+ sleep(1); /* not so fast, but tries to avoid a race
+ * condition: the child may exit before the
+ * parent calls childregister - bummer */
exit(0); /* Now exit.. */
}
smtpserver(&SS, 1);
@@ -856,9 +857,11 @@
if (routerpid > 0)
killr(&SS, routerpid);
_exit(0);
- } else
+ } else {
close(msgfd);
+ }
childregister(childpid, &SS.raddr);
+ }
}
}
#else /* !USE_INET */