freebsd-ports/games/golddig/files/patch-aa
Jean-Marc Zucconi b30183952a Avoid buffer overflows.
Submitted by:	Niels Heinen <niels.heinen@ubizen.com>
2004-12-02 10:55:58 +00:00

43 lines
1.4 KiB
Text

--- shared.c.orig Thu Dec 2 11:49:23 2004
+++ shared.c Thu Dec 2 11:52:16 2004
@@ -58,7 +58,7 @@
#include "bitmap/window.bits"
#include "bitmap/anti.bits"
-char *sprintf(); /* UNIX brain damage */
+/* char *sprintf(); /* UNIX brain damage */
/* All in and out movements except up */
#define NOUPBITS DLEAVE | LLEAVE | RLEAVE | HENTER | VENTER
@@ -312,21 +312,25 @@
FILE *levelfile;
register int i,j;
int x,y;
- char buf[300];
+ char buf[1300];
/* Manufaction the file name by starting with the world name and */
/* appending the level number to it. */
- strcpy(filename,LIB);
- strcat(filename,"/");
- strcat(filename,worldname);
+ if (strchr (worldname, '/'))
+ *filename = 0;
+ else {
+ strncpy(filename,LIB,sizeof(filename) - 3);
+ strncat(filename,"/",sizeof(filename) - 3);
+ }
+ strncat(filename,worldname,sizeof(filename) - 3);
sprintf(filename + strlen(filename),"%03d",levelnum);
/* Open level file for reading */
levelfile = fopen(filename,"r");
/* If level file does not exist, use the default level file. */
if(levelfile == NULL) {
/* Build the default level name */
- strcpy(buf,LIB);
- strcat(buf,"/default");
+ strncpy(buf,LIB,sizeof(filename));
+ strncat(buf,"/default",sizeof(filename));
/* Open default level file for reading */
levelfile = fopen(buf,"r");
if(levelfile == NULL) {