[mw-devel] MW3 r1153 - trunk/src

welshbyte at sucs.org welshbyte at sucs.org
Fri Jul 16 12:17:01 BST 2010


Author: welshbyte
Date: 2010-07-16 12:17:01 +0100 (Fri, 16 Jul 2010)
New Revision: 1153

Modified:
   trunk/src/read.c
Log:
Fix a stack smash which happens when the path to a folder file doesn't fit in 20 (FOLNAMESIZE + 10) chars. Silly rabbit.


Modified: trunk/src/read.c
===================================================================
--- trunk/src/read.c	2010-07-15 23:38:33 UTC (rev 1152)
+++ trunk/src/read.c	2010-07-16 11:17:01 UTC (rev 1153)
@@ -175,7 +175,7 @@
 	int afile;
 	struct folder fold;
 	struct Header head;
-	char tmp[FOLNAMESIZE+10];
+	char *tmp;
 	char buff[SUBJECTSIZE+1];	
 	int linecount=0;
 	int listpoint;
@@ -184,12 +184,17 @@
 	if (!get_folder_number(&fold,folnum))
 		return;
 
-	sprintf(tmp,"%s/%s%s",STATEDIR,fold.name,INDEX_END);
+	if (asprintf(&tmp, "%s/%s%s", STATEDIR, fold.name, INDEX_END) < 0)
+	{
+		return;
+	}
 	if ((afile=open(tmp,O_RDONLY))<0)
 	{
 		printf("There are no messages in folder %s\n",fold.name);
+		free(tmp);
 		return;
 	}
+	free(tmp);
 	if (many>0)
 	{
 		listpoint=fold.first+many;




More information about the mw-devel mailing list