Yahoo Groups archive

Milter-greylist

Index last updated: 2026-04-28 23:32 UTC

Message

Re: [milter-greylist] cutting off sender-string

2004-09-12 by Hajimu UMEMOTO

Hi,

>>>>> On Wed, 8 Sep 2004 21:04:50 +0200
>>>>> manu@... said:

manu> hans hm04 <hm04.yer@...> wrote:

> so, for me is a very good solution with 64 chars.
> if there should be an email-address 
> with more than 64 char - ok kismet. 
> but this will fit in more than 99.99 %

manu> The right way is to malloc the string, we should move forward to this
manu> solution.

How about this patch?  It allocates a memory for a sender address and
a recipient address for autowhite, except and pending lists.  Instead,
ADDRLEN is enlarged to 127 to handle input string well, and to guard
against very large address in milter-greylist.c, conf_yacc.y and
dump_yacc.y.

Index: autowhite.c
diff -u -p autowhite.c.orig autowhite.c
--- autowhite.c.orig	Mon Aug  2 21:11:48 2004
+++ autowhite.c	Mon Sep 13 02:57:58 2004
@@ -138,8 +138,8 @@ autowhite_add(sa, salen, from, rcpt, dat
 		 */
 		if (ip_equal(sa, aw->a_sa) &&
 		    ((conf.c_lazyaw == 1) ||
-		    ((strncasecmp(from, aw->a_from, ADDRLEN) == 0) &&
-		    (strncasecmp(rcpt, aw->a_rcpt, ADDRLEN) == 0)))) {
+		    ((strcasecmp(from, aw->a_from) == 0) &&
+		    (strcasecmp(rcpt, aw->a_rcpt) == 0)))) {
 			timeradd(&now, &delay, &aw->a_tv);
 
 			dirty++;
@@ -241,8 +241,8 @@ autowhite_check(sa, salen, from, rcpt, q
 		}
 		if (ip_match(sa, aw->a_sa, mask) &&
 		    ((conf.c_lazyaw == 1) ||
-		    ((strncasecmp(from, aw->a_from, ADDRLEN) == 0) &&
-		    (strncasecmp(rcpt, aw->a_rcpt, ADDRLEN) == 0)))) {
+		    ((strcasecmp(from, aw->a_from) == 0) &&
+		    (strcasecmp(rcpt, aw->a_rcpt) == 0)))) {
 			timeradd(&now, &delay, &aw->a_tv);
 
 			dirty++;
@@ -275,7 +275,7 @@ autowhite_textdump(stream)
 	struct tm tm;
 
 	fprintf(stream, "\n\n#\n# Auto-whitelisted tuples\n#\n");
-	fprintf(stream, "# Sender IP    %32s    %32s    Expire\n",
+	fprintf(stream, "# Sender IP\t%s\t%s\tExpire\n",
 	    "Sender e-mail", "Recipient e-mail");
 
 	AUTOWHITE_RDLOCK;
@@ -286,7 +286,7 @@ autowhite_textdump(stream)
 		iptostring(aw->a_sa, aw->a_salen, textaddr, sizeof(textaddr));
 
 		fprintf(stream, 
-		    "%s     %32s    %32s    %ld AUTO # %s\n",
+		    "%s\t%s\t%s\t%ld AUTO # %s\n",
 		    textaddr, aw->a_from, aw->a_rcpt, 
 		    (long)aw->a_tv.tv_sec, textdate);
 
@@ -320,17 +320,15 @@ autowhite_get(sa, salen, from, rcpt, dat
 
 	bzero((void *)aw, sizeof(*aw));
 
-	if ((aw->a_sa = malloc(salen)) == NULL) {
+	if ((aw->a_sa = malloc(salen)) == NULL ||
+	    (aw->a_from = strdup(from)) == NULL ||
+	    (aw->a_rcpt = strdup(rcpt)) == NULL) {
 		syslog(LOG_ERR, "malloc failed: %s", strerror(errno));
 		exit(EX_OSERR);
 	}
 
 	memcpy(aw->a_sa, sa, salen);
 	aw->a_salen = salen;
-	strncpy(aw->a_from, from, ADDRLEN);
-	aw->a_from[ADDRLEN] = '\0';
-	strncpy(aw->a_rcpt, rcpt, ADDRLEN);
-	aw->a_rcpt[ADDRLEN] = '\0';
 
 	if (date == NULL)
 		timeradd(&now, &delay, &aw->a_tv);
@@ -348,6 +346,8 @@ autowhite_put(aw)	/* autowhite list must
 {
 	TAILQ_REMOVE(&autowhite_head, aw, a_list);	
 	free(aw->a_sa);
+	free(aw->a_from);
+	free(aw->a_rcpt);
 	free(aw);
 
 	return;
Index: autowhite.h
diff -u autowhite.h.orig autowhite.h
--- autowhite.h.orig	Sun Aug  1 18:27:03 2004
+++ autowhite.h	Sun Sep 12 23:36:05 2004
@@ -47,8 +47,8 @@
 struct autowhite {
 	struct sockaddr *a_sa;
 	socklen_t a_salen;
-	char a_from[ADDRLEN + 1];
-	char a_rcpt[ADDRLEN + 1];
+	char *a_from;
+	char *a_rcpt;
 	struct timeval a_tv;
 	TAILQ_ENTRY(autowhite) a_list;
 };
Index: dump.h
diff -u dump.h.orig dump.h
--- dump.h.orig	Tue Jun  8 23:47:47 2004
+++ dump.h	Mon Sep 13 03:00:18 2004
@@ -54,7 +54,7 @@
 #endif
 
 #define DATELEN 40
-#define ADDRLEN	31
+#define ADDRLEN	127
 #define IPADDRLEN sizeof("255.255.255.255")
 
 #include "milter-greylist.h"
Index: except.c
diff -u -p except.c.orig except.c
--- except.c.orig	Tue Aug 10 05:29:08 2004
+++ except.c	Mon Sep 13 02:50:12 2004
@@ -167,14 +167,13 @@ except_add_from(email)	/* exceptlist mus
 {
 	struct except *except;
 
-	if ((except = malloc(sizeof(*except))) == NULL) {
+	if ((except = malloc(sizeof(*except))) == NULL ||
+	    (except->e_from = strdup(email)) == NULL) {
 		syslog(LOG_ERR, "except malloc failed: %s", strerror(errno));
 		exit(EX_OSERR);
 	}
 		
 	except->e_type = E_FROM;
-	strncpy(except->e_from, email, ADDRLEN);
-	except->e_from[ADDRLEN] = '\0';
 	LIST_INSERT_HEAD(&except_head, except, e_list);
 
 	if (conf.c_debug)
@@ -189,14 +188,13 @@ except_add_rcpt(email)	/* exceptlist mus
 {
 	struct except *except;
 
-	if ((except = malloc(sizeof(*except))) == NULL) {
+	if ((except = malloc(sizeof(*except))) == NULL ||
+	    (except->e_rcpt = strdup(email)) == NULL) {
 		syslog(LOG_ERR, "except malloc failed: %s", strerror(errno));
 		exit(EX_OSERR);
 	}
 		
 	except->e_type = E_RCPT;
-	strncpy(except->e_rcpt, email, ADDRLEN);
-	except->e_rcpt[ADDRLEN] = '\0';
 	LIST_INSERT_HEAD(&except_head, except, e_list);
 
 	if (conf.c_debug)
@@ -211,14 +209,13 @@ except_add_domain(domain)	/* exceptlist 
 {
 	struct except *except;
 
-	if ((except = malloc(sizeof(*except))) == NULL) {
+	if ((except = malloc(sizeof(*except))) == NULL ||
+	    (except->e_domain = strdup(domain)) == NULL) {
 		syslog(LOG_ERR, "except malloc failed: %s", strerror(errno));
 		exit(EX_OSERR);
 	}
 		
 	except->e_type = E_DOMAIN;
-	strncpy(except->e_domain, domain, ADDRLEN);
-	except->e_domain[ADDRLEN] = '\0';
 	LIST_INSERT_HEAD(&except_head, except, e_list);
 
 	if (conf.c_debug)
@@ -498,7 +495,7 @@ emailcmp(big, little)
 		if (tolower(big[0]) != tolower(little[0]))
 			big++;
 
-		for (i = 0; big[0] && little[i] && (i < ADDRLEN); i++) {
+		for (i = 0; big[0] && little[i]; i++) {
 			if (tolower(big[0]) != tolower(little[i]))
 				break;
 			big++;
@@ -519,20 +516,30 @@ except_clear(void) {	/* exceptlist must 
 		except = LIST_FIRST(&except_head);
 		LIST_REMOVE(except, e_list);
 
-		if (except->e_type == E_NETBLOCK) {
+		switch (except->e_type) {
+		case E_NETBLOCK:
 			free(except->e_addr);
 			free(except->e_mask);
-		}
-
-		if (except->e_type == E_FROM_RE)
+			break;
+		case E_FROM:
+			free(except->e_from);
+			break;
+		case E_RCPT:
+			free(except->e_rcpt);
+			break;
+		case E_DOMAIN:
+			free(except->e_domain);
+			break;
+		case E_FROM_RE:
 			regfree(&except->e_from_re);
-
-		if (except->e_type == E_RCPT_RE)
+			break;
+		case E_RCPT_RE:
 			regfree(&except->e_rcpt_re);
-
-		if (except->e_type == E_DOMAIN_RE)
+			break;
+		case E_DOMAIN_RE:
 			regfree(&except->e_domain_re);
-
+			break;
+		}
 		free(except);
 	}
 
Index: except.h
diff -u except.h.orig except.h
--- except.h.orig	Mon Aug  2 21:11:48 2004
+++ except.h	Mon Sep 13 02:39:04 2004
@@ -85,9 +85,9 @@
 			socklen_t nb_addrlen;
 			ipaddr *nb_mask;
 		} d_netblock;
-		char d_from[ADDRLEN + 1];
-		char d_rcpt[ADDRLEN + 1];
-		char d_domain[ADDRLEN + 1];
+		char *d_from;
+		char *d_rcpt;
+		char *d_domain;
 		regex_t d_from_re;
 		regex_t d_rcpt_re;
 		regex_t d_domain_re;
Index: pending.c
diff -u -p pending.c.orig pending.c
--- pending.c.orig	Wed Aug  4 06:56:07 2004
+++ pending.c	Mon Sep 13 02:56:50 2004
@@ -134,10 +134,21 @@ pending_get(sa, salen, from, rcpt, date)
 		pending = NULL;
 		goto out;
 	}
-	strncpy(pending->p_from, from, ADDRLEN);
-	pending->p_from[ADDRLEN] = '\0';
-	strncpy(pending->p_rcpt, rcpt, ADDRLEN);
-	pending->p_rcpt[ADDRLEN] = '\0';
+	if ((pending->p_from = strdup(from)) == NULL) {
+		free(pending->p_addr);
+		free(pending->p_sa);
+		free(pending);
+		pending = NULL;
+		goto out;
+	}
+	if ((pending->p_rcpt = strdup(rcpt)) == NULL) {
+		free(pending->p_from);
+		free(pending->p_addr);
+		free(pending->p_sa);
+		free(pending);
+		pending = NULL;
+		goto out;
+	}
 
 	pending->p_refcnt = 1;
 
@@ -198,8 +209,8 @@ pending_del(sa, salen, from, rcpt, time)
 		 * Look for our entry.
 		 */
 		if ((strncmp(addr, pending->p_addr, sizeof(addr)) == 0) &&
-		    (strncmp(from, pending->p_from, ADDRLEN) == 0) &&
-		    (strncmp(rcpt, pending->p_rcpt, ADDRLEN) == 0) &&
+		    (strcmp(from, pending->p_from) == 0) &&
+		    (strcmp(rcpt, pending->p_rcpt) == 0) &&
 		    (pending->p_tv.tv_sec == time)) {
 			pending_put(pending);
 			break;
@@ -287,8 +298,8 @@ pending_check(sa, salen, from, rcpt, rem
 #endif
 		}
 		if (ip_match(sa, pending->p_sa, mask) &&
-		    (strncmp(from, pending->p_from, ADDRLEN) == 0) &&
-		    (strncmp(rcpt, pending->p_rcpt, ADDRLEN) == 0)) {
+		    (strcmp(from, pending->p_from) == 0) &&
+		    (strcmp(rcpt, pending->p_rcpt) == 0)) {
 			rest = accepted - now;
 
 			if (rest < 0) {
@@ -341,7 +352,7 @@ pending_textdump(stream)
 	struct tm tm;
 
 	fprintf(stream, "\n\n#\n# greylisted tuples\n#\n");
-	fprintf(stream, "# Sender IP	%32s	%32s	Time accepted\n", 
+	fprintf(stream, "# Sender IP\t%s\t%s\tTime accepted\n", 
 	    "Sender e-mail", "Recipient e-mail");
 
 	PENDING_RDLOCK;
@@ -349,7 +360,7 @@ pending_textdump(stream)
 		localtime_r((time_t *)&pending->p_tv.tv_sec, &tm);
 		strftime(textdate, DATELEN, "%Y-%m-%d %T", &tm);
 
-		fprintf(stream, "%s	%32s	%32s	%ld # %s\n", 
+		fprintf(stream, "%s\t%s\t%s\t%ld # %s\n", 
 		    pending->p_addr, pending->p_from, 
 		    pending->p_rcpt, (long)pending->p_tv.tv_sec, textdate);
 		
@@ -383,6 +394,8 @@ pending_free(pending)
 	UNLOCK(refcnt_lock);
 	free(pending->p_sa);
 	free(pending->p_addr);
+	free(pending->p_from);
+	free(pending->p_rcpt);
 	free(pending);
 }
 
Index: pending.h
diff -u pending.h.orig pending.h
--- pending.h.orig	Mon Aug  2 21:11:48 2004
+++ pending.h	Mon Sep 13 02:51:36 2004
@@ -65,8 +65,8 @@
 	char *p_addr;
 	struct sockaddr *p_sa;
 	socklen_t p_salen;
-	char p_from[ADDRLEN + 1];
-	char p_rcpt[ADDRLEN + 1];
+	char *p_from;
+	char *p_rcpt;
 	struct timeval p_tv;
 	int p_refcnt;
 	TAILQ_ENTRY(pending) p_list;

Sincerely,

--
Hajimu UMEMOTO @ Internet Mutual Aid Society Yokohama, Japan
ume@...  ume@{,jp.}FreeBSD.org
http://www.imasy.org/~ume/

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.