changeset 775:d0bf2135ab34

Check the server gives a reply before reading it to avoid segfaulting
author Ben Schmidt
date Fri, 12 Nov 2010 02:27:50 +1100
parents 62f9b36df5a5
children de31a9e15c5b
files ChangeLog src/checkwait_smtpreply.c
diffstat 2 files changed, 7 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Nov 12 02:26:49 2010 +1100
+++ b/ChangeLog	Fri Nov 12 02:27:50 2010 +1100
@@ -1,3 +1,4 @@
+ o Check the relayhost gives a reply before reading it to avoid a crash
  o Avoid checking addresses multiple times for notmetoo and make it work even
    when delivering messages individually
  o Fixed small memory leaks when SMTP errors occur
--- a/src/checkwait_smtpreply.c	Fri Nov 12 02:26:49 2010 +1100
+++ b/src/checkwait_smtpreply.c	Fri Nov 12 02:27:50 2010 +1100
@@ -36,6 +36,12 @@
 	char *smtpreply;
 
 	smtpreply = mygetline(sockfd);
+	if(smtpreply == NULL) {
+		/* This will never be a valid SMTP response so will always be returned,
+		 * but is more descriptive than an empty string. */
+		smtpreply = mystrdup("none / error / closed connection");
+	}
+
 #if 0
 	printf("replytype = [%d], smtpreply = [%s]\n", replytype, smtpreply);
 	fprintf(stderr, "%s", smtpreply);