$OpenBSD: patch-filters_c,v 1.2 2001/06/09 02:36:48 angelos Exp $
--- filters.c.orig	Fri Oct 30 22:58:47 1998
+++ filters.c	Fri Jun  8 22:24:01 2001
@@ -103,9 +103,12 @@ block_url(struct http_request *http, str
 					n += strlen(path);
 					n += strlen(spec);
 
-					p = malloc(n);
+					if ((p = malloc(n)) == NULL) {
+					   fprintf(stderr, "%s:%d malloc failed\n", __FILE__, __LINE__);
+					   exit(-1);
+					}
 
-					sprintf(p, CBLOCK,
+					snprintf(p, n, CBLOCK,
 						hostport, path, spec);
 
 					freez(hostport);
@@ -174,9 +177,12 @@ trust_url(struct http_request *http, str
 					n += strlen(path);
 					n += strlen(referrer);
 
-					p = malloc(n);
+					if ((p = malloc(n)) == NULL) {
+					   fprintf(stderr, "%s:%d malloc failed\n", __FILE__, __LINE__);
+					   exit(-1);
+					}
 
-					sprintf(p, CTRUST,
+					snprintf(p, n, CTRUST,
 						hostport, path, referrer);
 
 					freez(hostport);
@@ -288,8 +294,11 @@ trust_url_not_trusted:
 	n += strlen(path);
 	n += strlen(referrer);
 
-	p = malloc(n);
-	sprintf(p, CTRUST, hostport, path, referrer);
+	if ((p = malloc(n)) == NULL) {
+	   fprintf(stderr, "%s:%d malloc failed\n", __FILE__, __LINE__);
+	   exit(-1);
+	}
+	snprintf(p, n, CTRUST, hostport, path, referrer);
 
 	freez(hostport);
 	freez(path);
@@ -441,8 +450,11 @@ dsplit(char *domain)
 	/* save a copy of the pointers in dvec */
 	size = ret->dcnt * sizeof(*ret->dvec);
 		
-	if((ret->dvec = malloc(size))) {
+	if((ret->dvec = malloc(size)) != NULL) {
 		memcpy(ret->dvec, v, size);
+	} else {
+	   fprintf(stderr, "%s:%d malloc failed\n", __FILE__, __LINE__);
+	   exit(-1);
 	}
 
 	return(*ret);
@@ -562,8 +574,11 @@ ij_blocked_url(struct http_request *http
 	n += strlen(path    );
 	n += strlen(pattern );
 
-	if((p = malloc(n))) {
-		sprintf(p, template, hostport, path, pattern);
+	if((p = malloc(n)) != NULL) {
+		snprintf(p, n, template, hostport, path, pattern);
+	} else {
+	   fprintf(stderr, "%s:%d malloc failed\n", __FILE__, __LINE__);
+	   exit(-1);
 	}
 
 	freez(hostport);
@@ -618,8 +633,11 @@ ij_untrusted_url(struct http_request *ht
 	n += strlen(hostport);
 	n += strlen(path    );
 
-	if((p = malloc(n))) {
-		sprintf(p, template, hostport, path);
+	if((p = malloc(n)) != NULL) {
+		snprintf(p, n, template, hostport, path);
+	} else {
+	   fprintf(stderr, "%s:%d malloc failed\n", __FILE__, __LINE__);
+	   exit(-1);
 	}
 
 	freez(hostport);
@@ -632,25 +650,25 @@ ij_untrusted_url(struct http_request *ht
 	p = strsav(p, "<h3>The following referrers are trusted</h3>\n");
 
 	for(tl = trust_list; (t = *tl) ; tl++) {
-		sprintf(buf, "%s<br>\n", t->spec);
+		snprintf(buf, sizeof(buf), "%s<br>\n", t->spec);
 		p = strsav(p, buf);
 	}
 
 	if(trust_info->next) {
 		struct list *l;
 
-		strcpy(buf,
+		strlcpy(buf,
 			"<p>"
 			"You can learn more about what this means "
 			"and what you may be able to do about it by "
 			"reading the following documents:<br>\n"
-			"<ol>\n"
+			"<ol>\n", sizeof(buf)
 		);
 
 		p = strsav(p, buf);
 		
 		for(l = trust_info->next; l ; l = l->next) {
-			sprintf(buf,
+			snprintf(buf, sizeof(buf),
 				"<li> <a href=%s>%s</a><br>\n",
 					l->str, l->str);
 			p = strsav(p, buf);
