[mw-devel] MW3 r1021 - trunk/src

welshbyte at sucs.org welshbyte at sucs.org
Sat Mar 29 22:15:58 GMT 2008


Author: welshbyte
Date: 2008-03-29 22:15:57 +0000 (Sat, 29 Mar 2008)
New Revision: 1021

Modified:
   trunk/src/add.c
   trunk/src/edit.c
   trunk/src/files.c
   trunk/src/files.h
   trunk/src/proto.h
   trunk/src/read.c
Log:
Add checking to get_folder_number() to avoid using garbage folder data


Modified: trunk/src/add.c
===================================================================
--- trunk/src/add.c	2008-03-28 20:09:29 UTC (rev 1020)
+++ trunk/src/add.c	2008-03-29 22:15:57 UTC (rev 1021)
@@ -37,11 +37,17 @@
 
 	fol=(struct folder *)malloc(sizeof(*fol));
 	new=(struct Header *)malloc(sizeof(*new));
-	/* check write status of folder */
 	
-	get_folder_number(fol,folnum);
-	if (nofolders() || !allowed_w(fol,user))
+	if (!get_folder_number(fol,folnum))
 	{
+		free(fol);
+		free(new);
+		return 0;
+	}
+
+	/* check write status of folder */
+	if (!allowed_w(fol,user))
+	{
 		printf(_("Not allowed to write to this folder.\n"));
 		free(fol);
 		free(new);

Modified: trunk/src/edit.c
===================================================================
--- trunk/src/edit.c	2008-03-28 20:09:29 UTC (rev 1020)
+++ trunk/src/edit.c	2008-03-29 22:15:57 UTC (rev 1021)
@@ -524,7 +524,7 @@
 		printf(_("Unknown folder name.\n"));
 		return;
 	}
-	get_folder_number(&fold,folnum);
+	if (!get_folder_number(&fold,folnum)) return;
 	if (stringcmp(args,"status",2))
 	{
 		show_fold_stats(fold.status,tmp,TRUE);

Modified: trunk/src/files.c
===================================================================
--- trunk/src/files.c	2008-03-28 20:09:29 UTC (rev 1020)
+++ trunk/src/files.c	2008-03-29 22:15:57 UTC (rev 1021)
@@ -206,19 +206,20 @@
 	return(no);
 }
 
-void get_folder_number(struct folder *fol, int num)
+int get_folder_number(struct folder *fol, int num)
 {
 	int file;
 	int no;
 	
 	if (nofolders())
-		{printf("There are no folders !\n");return;}
+		{printf("There are no folders !\n");return 0;}
 	file=openfolderfile(O_RDONLY);
 	lseek(file,sizeof(*fol)*num,0);
 	if ((no=read(file,fol,sizeof(*fol)))<0)
 	{
 		perror("get_folder_number");
-		exit(-1);
+		return 0;
 	}
 	close(file);
+	return 1;
 }

Modified: trunk/src/files.h
===================================================================
--- trunk/src/files.h	2008-03-28 20:09:29 UTC (rev 1020)
+++ trunk/src/files.h	2008-03-29 22:15:57 UTC (rev 1021)
@@ -18,6 +18,6 @@
 void create_folder_file(void);
 int foldernumber(char *name);
 int get_folder_entry(int file, struct folder *tmp);
-void get_folder_number(struct folder *fol, int num);
+int get_folder_number(struct folder *fol, int num);
 
 #endif

Modified: trunk/src/proto.h
===================================================================
--- trunk/src/proto.h	2008-03-28 20:09:29 UTC (rev 1020)
+++ trunk/src/proto.h	2008-03-29 22:15:57 UTC (rev 1021)
@@ -164,7 +164,7 @@
 void create_folder_file(void);
 int foldernumber(char *name);
 int get_folder_entry(int file, struct folder *tmp);
-void get_folder_number(struct folder *fol, int num);
+int get_folder_number(struct folder *fol, int num);
 /* special.c
    prototypes now in "special.h" */
 /* Parse.c */

Modified: trunk/src/read.c
===================================================================
--- trunk/src/read.c	2008-03-28 20:09:29 UTC (rev 1020)
+++ trunk/src/read.c	2008-03-29 22:15:57 UTC (rev 1021)
@@ -176,7 +176,9 @@
 	int listpoint;
 	int screen_height = screen_h();
 
-	get_folder_number(&fold,folnum);
+	if (!get_folder_number(&fold,folnum))
+		return;
+
 	sprintf(tmp,"%s/%s%s",HOMEPATH,fold.name,INDEX_END);
 	if ((afile=open(tmp,O_RDONLY))<0)
 	{





More information about the mw-devel mailing list