[PATCH] fix some (hypothetic) null pointer dereference

Urs Janßen <[email protected]> Sun, 14 Nov 2010 19:38:04 +0100
Newsgroups gmane.network.tin.devel
Organization tin.org
Message-ID <[email protected]>
--- src/cook.c	2010-10-03 10:58:09 +0000
+++ src/cook.c	2010-11-14 10:53:47 +0000
@@ -455,7 +455,7 @@
 				if (max_line_len < strlen(buf) + 2) {
 					max_line_len = strlen(buf) + 2;
 					line = my_realloc(line, max_line_len);
-				};
+				}
 				strcpy(line, buf);
 
 				/*

--- src/filter.c	2010-09-08 21:25:42 +0000
+++ src/filter.c	2010-11-12 23:41:57 +0000
@@ -517,11 +517,11 @@
 							FreeIfNeeded(ptr[i].subj);
 							ptr[i].subj = my_strdup(subj);
 						}
-					}
 #ifdef DEBUG
-					if (debug & DEBUG_FILTER)
-						debug_print_file("FILTER","buf=[%s]  Gsubj=[%s]", ptr[i].subj, glob_filter.filter[i].subj);
+						if (debug & DEBUG_FILTER)
+							debug_print_file("FILTER","buf=[%s]  Gsubj=[%s]", ptr[i].subj, glob_filter.filter[i].subj);
 #endif /* DEBUG */
+					}
 					break;
 				}
 

--- src/nntplib.c	2010-11-03 19:17:32 +0000
+++ src/nntplib.c	2010-11-10 01:13:35 +0000
@@ -1053,6 +1053,8 @@
 			nntp_caps.authinfo_sasl = FALSE;
 			nntp_caps.authinfo_state = FALSE;
 			nntp_caps.sasl = SASL_NONE;
+			nntp_caps.compress = FALSE;
+			nntp_caps.compress_algorithm = COMPRESS_NONE;
 #if 0
 			nntp_caps.streaming = FALSE;
 			nntp_caps.ihave = FALSE;

--- src/post.c	2010-10-17 19:03:17 +0000
+++ src/post.c	2010-11-13 18:00:58 +0000
@@ -414,10 +414,11 @@
 		if (msg_headers[i].name) {
 			fprintf(fp, "%s: %s\n", msg_headers[i].name, BlankIfNull(msg_headers[i].text));
 			wrote++;
-			p = msg_headers[i].text;
-			while((p = strchr(p, '\n'))) {
-				p++;
-				wrote++;
+			if ((p = msg_headers[i].text)) {
+				while((p = strchr(p, '\n'))) {
+					p++;
+					wrote++;
+				}
 			}
 		}
 	}
@@ -2795,15 +2796,17 @@
 			msg_add_header("Distribution", my_distribution);
 	}
 
-	msg_add_x_headers(group->attribute->x_headers);
+	if (group && group->attribute->x_headers)
+		msg_add_x_headers(group->attribute->x_headers);
 
 	start_line_offset = msg_write_headers(fp) + 1;
 	msg_free_headers();
-	start_line_offset += msg_add_x_body(fp, group->attribute->x_body);
+	if (group && group->attribute->x_body)
+		start_line_offset += msg_add_x_body(fp, group->attribute->x_body);
 
 	if (copy_text) {
 		if (arts[respnum].xref && is_crosspost(arts[respnum].xref)) {
-			if (strfquote(group->name, respnum, buf, sizeof(buf), tinrc.xpost_quote_format))
+			if (strfquote(group ? group->name : groupname, respnum, buf, sizeof(buf), tinrc.xpost_quote_format))
 				fprintf(fp, "%s\n", buf);
 		} else if (strfquote(groupname, respnum, buf, sizeof(buf), (group && group->attribute->news_quote_format != NULL) ? group->attribute->news_quote_format : tinrc.news_quote_format))
 			fprintf(fp, "%s\n", buf);
@@ -2937,10 +2940,10 @@
 		 * put in the file in the first place, so we don't do it.
 		 */
 		if (!address_in_list(to, strlen(from_address) ? from_address : userid)) {
-			if ((curr_group && (curr_group->attribute->auto_cc_bcc & AUTO_CC)) || (!curr_group && (tinrc.auto_cc_bcc & AUTO_CC)))
+			if ((curr_group && curr_group->attribute && (curr_group->attribute->auto_cc_bcc & AUTO_CC)) || (!curr_group && (tinrc.auto_cc_bcc & AUTO_CC)))
 				msg_add_header("Cc", strlen(from_address) ? from_address : userid);
 
-			if ((curr_group && (curr_group->attribute->auto_cc_bcc & AUTO_BCC)) || (!curr_group && (tinrc.auto_cc_bcc & AUTO_BCC)))
+			if ((curr_group && curr_group->attribute && (curr_group->attribute->auto_cc_bcc & AUTO_BCC)) || (!curr_group && (tinrc.auto_cc_bcc & AUTO_BCC)))
 				msg_add_header("Bcc", strlen(from_address) ? from_address : userid);
 		}
 
@@ -2963,7 +2966,7 @@
 			msg_add_header("X-Newsgroups", extra_hdrs->newsgroups);
 		}
 
-		if (curr_group && curr_group->attribute->x_headers && strlen(curr_group->attribute->x_headers))
+		if (curr_group && curr_group->attribute && curr_group->attribute->x_headers && strlen(curr_group->attribute->x_headers))
 			msg_add_x_headers(curr_group->attribute->x_headers);
 	}
 	start_line_offset = msg_write_headers(fp) + 1;

--- src/save.c	2010-11-03 19:17:32 +0000
+++ src/save.c	2010-11-12 23:56:52 +0000
@@ -1865,7 +1865,7 @@
 	t_bool found = FALSE;
 	t_partl *lptr, *lptr2;
 
-	lptr = lptr2 = find_part(i);
+	lptr2 = find_part(i);
 	prefix_ptr = depth * 2 - 1;
 	if (prefix_ptr > maxlen - 1 - !(maxlen % 2)) {
 		int odd = ((maxlen % 2) ? 0 : 1);

--- src/sigfile.c	2009-12-01 15:16:55 +0000
+++ src/sigfile.c	2010-11-13 17:55:02 +0000
@@ -135,25 +135,25 @@
 			my_chdir(cwd);
 			return;
 		}
-	}
-
-	if ((sigfp = fopen(path, "r")) != NULL) {
-		fprintf(fp, "\n%s", thisgroup->attribute->sigdashes ? SIGDASHES : "\n");
-		copy_fp(sigfp, fp);
-		fclose(sigfp);
-		return;
-	}
-
-	/*
-	 * Use ~/.signature as a last resort, but only if mailing or
-	 * using internal inews (external inews appends it automagically).
-	 */
-	if ((sigfp = fopen(default_signature, "r")) != NULL) {
-		if (include_dot_signature) {
+
+		if ((sigfp = fopen(path, "r")) != NULL) {
 			fprintf(fp, "\n%s", thisgroup->attribute->sigdashes ? SIGDASHES : "\n");
 			copy_fp(sigfp, fp);
-		}
-		fclose(sigfp);
+			fclose(sigfp);
+			return;
+		}
+
+		/*
+		 * Use ~/.signature as a last resort, but only if mailing or
+		 * using internal inews (external inews appends it automagically).
+		 */
+		if ((sigfp = fopen(default_signature, "r")) != NULL) {
+			if (include_dot_signature) {
+				fprintf(fp, "\n%s", thisgroup->attribute->sigdashes ? SIGDASHES : "\n");
+				copy_fp(sigfp, fp);
+			}
+			fclose(sigfp);
+		}
 	}
 }
 
@@ -197,7 +197,7 @@
 	DIR_BUF *dp;
 	char *cwd;
 	int safeguard, recurse;
-	int c = 0, numentries, pick;
+	int c = 0, numentries = 0, pick;
 	struct stat st;
 
 	sigfile[0] = '\0';
@@ -205,8 +205,7 @@
 	if ((dirp = opendir(CURRENTDIR)) == NULL)
 		return 1;
 
-	numentries = 0;
-	while ((dp = readdir(dirp)) != NULL)
+	while (readdir(dirp) != NULL)
 		numentries++;
 
 	/*