summaryrefslogtreecommitdiff
path: root/games/phantasia
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2003-04-06 18:50:39 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2003-04-06 18:50:39 +0000
commit0f64621783b3f46a4851826b9f4284e3c9dbeb61 (patch)
tree352fcb09d9321309ec519dc3144147a24bd64bda /games/phantasia
parent997f28507be542389b846c45806474af6bbfdedc (diff)
2451 lines of strdup/sprintf/strcpy whacking. mostly ok'd by pjanzen
already, but he may have later changes to make still.
Diffstat (limited to 'games/phantasia')
-rw-r--r--games/phantasia/convert.c11
-rw-r--r--games/phantasia/fight.c8
-rw-r--r--games/phantasia/gamesupport.c14
-rw-r--r--games/phantasia/main.c21
-rw-r--r--games/phantasia/misc.c12
-rw-r--r--games/phantasia/phantglobs.h4
-rw-r--r--games/phantasia/setup.c4
7 files changed, 45 insertions, 29 deletions
diff --git a/games/phantasia/convert.c b/games/phantasia/convert.c
index 141d7f808eb..53b247c3a5e 100644
--- a/games/phantasia/convert.c
+++ b/games/phantasia/convert.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: convert.c,v 1.4 2002/12/06 21:48:51 millert Exp $ */
+/* $OpenBSD: convert.c,v 1.5 2003/04/06 18:50:38 deraadt Exp $ */
/* $NetBSD: convert.c,v 1.2 1995/03/24 03:58:34 cgd Exp $ */
/*
@@ -166,9 +166,12 @@ FILE *oldcharac, *newcharac; /* to open old and new files */
Newplayer.p_virgin = Oldplayer.o_virgin;
Newplayer.p_blindness = Oldplayer.o_blindness;
- strcpy(Newplayer.p_name, Oldplayer.o_name);
- strcpy(Newplayer.p_password, Oldplayer.o_password);
- strcpy(Newplayer.p_login, Oldplayer.o_login);
+ strlcpy(Newplayer.p_name, Oldplayer.o_name,
+ sizeof Newplayer.p_name);
+ strlcpy(Newplayer.p_password, Oldplayer.o_password,
+ sizeof Newplayer.p_password);
+ strlcpy(Newplayer.p_login, Oldplayer.o_login,
+ sizeof Newplayer.p_login);
/* write new structure */
fwrite((char *) &Newplayer, sizeof(Newplayer), 1, newcharac);
diff --git a/games/phantasia/fight.c b/games/phantasia/fight.c
index bac020cf490..d8ad552bd25 100644
--- a/games/phantasia/fight.c
+++ b/games/phantasia/fight.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fight.c,v 1.7 2002/01/16 01:28:54 millert Exp $ */
+/* $OpenBSD: fight.c,v 1.8 2003/04/06 18:50:38 deraadt Exp $ */
/* $NetBSD: fight.c,v 1.2 1995/03/24 03:58:39 cgd Exp $ */
/*
@@ -1058,7 +1058,8 @@ callmonster(which)
} else
/* make Modnar into Morgoth */
{
- strcpy(Curmonster.m_name, "Morgoth");
+ strlcpy(Curmonster.m_name, "Morgoth",
+ sizeof Curmonster.m_name);
Curmonster.m_strength = drandom() * (Player.p_maxenergy + Player.p_shield) / 1.4
+ drandom() * (Player.p_maxenergy + Player.p_shield) / 1.5;
Curmonster.m_brains = Player.p_brains;
@@ -1077,7 +1078,8 @@ callmonster(which)
which = (int) ROLL(0.0, 100.0);
fseek(Monstfp, (long) which * (long) SZ_MONSTERSTRUCT, SEEK_SET);
fread(&Othermonster, SZ_MONSTERSTRUCT, 1, Monstfp);
- strcpy(Curmonster.m_name, Othermonster.m_name);
+ strlcpy(Curmonster.m_name, Othermonster.m_name,
+ sizeof Curmonster.m_name);
}
truncstring(Curmonster.m_name);
diff --git a/games/phantasia/gamesupport.c b/games/phantasia/gamesupport.c
index 2c9eaf6d098..0ab75d617ed 100644
--- a/games/phantasia/gamesupport.c
+++ b/games/phantasia/gamesupport.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gamesupport.c,v 1.4 2000/06/29 07:39:43 pjanzen Exp $ */
+/* $OpenBSD: gamesupport.c,v 1.5 2003/04/06 18:50:38 deraadt Exp $ */
/* $NetBSD: gamesupport.c,v 1.3 1995/04/24 12:24:28 cgd Exp $ */
/*
@@ -231,7 +231,8 @@ changestats(ingameflag)
truncstring(Databuf);
if (Databuf[0] != '\0')
if (Wizard || findname(Databuf, &Other) < 0L)
- strcpy(playerp->p_name, Databuf);
+ strlcpy(playerp->p_name, Databuf,
+ sizeof playerp->p_name);
} else
/* get new password */
{
@@ -705,10 +706,13 @@ enterscore()
if ((!found) || Player.p_level > sbuf.sb_level)
/* put new entry in for this login */
{
- strcpy(sbuf.sb_login, Player.p_login);
- strcpy(sbuf.sb_name, Player.p_name);
+ strlcpy(sbuf.sb_login, Player.p_login,
+ sizeof sbuf.sb_login);
+ strlcpy(sbuf.sb_name, Player.p_name,
+ sizeof sbuf.sb_name);
sbuf.sb_level = Player.p_level;
- strcpy(sbuf.sb_type, descrtype(&Player, TRUE));
+ strlcpy(sbuf.sb_type, descrtype(&Player, TRUE),
+ sizeof sbuf.sb_type);
}
/* update entry */
fseek(fp, loc, SEEK_SET);
diff --git a/games/phantasia/main.c b/games/phantasia/main.c
index 3bfed797ffa..03b87df4a10 100644
--- a/games/phantasia/main.c
+++ b/games/phantasia/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.11 2002/12/06 21:48:51 millert Exp $ */
+/* $OpenBSD: main.c,v 1.12 2003/04/06 18:50:38 deraadt Exp $ */
/* $NetBSD: main.c,v 1.3 1995/04/24 12:24:37 cgd Exp $ */
/*
@@ -793,7 +793,8 @@ titlelist()
Other.p_status != S_NOTUSED)
/* found the king */
{
- sprintf(Databuf, "The present ruler is %s Level:%.0f",
+ snprintf(Databuf, sizeof Databuf,
+ "The present ruler is %s Level:%.0f",
Other.p_name, Other.p_level);
mvaddstr(4, 40 - strlen(Databuf) / 2, Databuf);
kingfound = TRUE;
@@ -808,7 +809,9 @@ titlelist()
if (Other.p_specialtype == SC_VALAR && Other.p_status != S_NOTUSED)
/* found the valar */
{
- sprintf(Databuf, "The Valar is %s Login: %s", Other.p_name, Other.p_login);
+ snprintf(Databuf, sizeof Databuf,
+ "The Valar is %s Login: %s", Other.p_name,
+ Other.p_login);
mvaddstr(6, 40 - strlen(Databuf) / 2, Databuf);
break;
}
@@ -824,7 +827,8 @@ titlelist()
councilfound = TRUE;
}
/* This assumes a finite (<=5) number of C.O.W.: */
- sprintf(Databuf, "%s Login: %s", Other.p_name, Other.p_login);
+ snprintf(Databuf, sizeof Databuf,
+ "%s Login: %s", Other.p_name, Other.p_login);
mvaddstr(Lines++, 40 - strlen(Databuf) / 2, Databuf);
}
/* search for the two highest players */
@@ -841,8 +845,8 @@ titlelist()
hiexp = Other.p_experience;
nxtlvl = hilvl;
hilvl = Other.p_level;
- strcpy(nxtname, hiname);
- strcpy(hiname, Other.p_name);
+ strlcpy(nxtname, hiname, sizeof nxtname);
+ strlcpy(hiname, Other.p_name, sizeof hiname);
} else
if (Other.p_experience > nxtexp
&& Other.p_specialtype <= SC_KING
@@ -851,10 +855,11 @@ titlelist()
{
nxtexp = Other.p_experience;
nxtlvl = Other.p_level;
- strcpy(nxtname, Other.p_name);
+ strlcpy(nxtname, Other.p_name, sizeof nxtname);
}
mvaddstr(15, 28, "Highest characters are:");
- sprintf(Databuf, "%s Level:%.0f and %s Level:%.0f",
+ snprintf(Databuf, sizeof Databuf,
+ "%s Level:%.0f and %s Level:%.0f",
hiname, hilvl, nxtname, nxtlvl);
mvaddstr(17, 40 - strlen(Databuf) / 2, Databuf);
diff --git a/games/phantasia/misc.c b/games/phantasia/misc.c
index e756d7c850c..7f895d00db8 100644
--- a/games/phantasia/misc.c
+++ b/games/phantasia/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.10 2003/03/11 04:47:39 david Exp $ */
+/* $OpenBSD: misc.c,v 1.11 2003/04/06 18:50:38 deraadt Exp $ */
/* $NetBSD: misc.c,v 1.2 1995/03/24 03:59:03 cgd Exp $ */
/*
@@ -161,9 +161,10 @@ descrlocation(playerp, shortflag)
}
if (shortflag)
- sprintf(Databuf, "%.29s", label);
+ snprintf(Databuf, sizeof Databuf, "%.29s", label);
else
- sprintf(Databuf, " is in %s (%.0f,%.0f)", label, playerp->p_x, playerp->p_y);
+ snprintf(Databuf, sizeof Databuf,
+ " is in %s (%.0f,%.0f)", label, playerp->p_x, playerp->p_y);
return (Databuf);
}
@@ -638,7 +639,7 @@ descrtype(playerp, shortflag)
++type;
if (playerp->p_crowns > 0) {
- strcpy(Databuf, results[type]);
+ strlcpy(Databuf, results[type], sizeof Databuf);
Databuf[0] = '*';
return (Databuf);
} else
@@ -901,7 +902,8 @@ death(how)
"Your ring has taken control of you and turned you into a monster!\n");
fseek(Monstfp, 13L * SZ_MONSTERSTRUCT, SEEK_SET);
fread((char *) &Curmonster, SZ_MONSTERSTRUCT, 1, Monstfp);
- strcpy(Curmonster.m_name, Player.p_name);
+ strlcpy(Curmonster.m_name, Player.p_name,
+ sizeof Curmonster.m_name);
fseek(Monstfp, 13L * SZ_MONSTERSTRUCT, SEEK_SET);
fwrite((char *) &Curmonster, SZ_MONSTERSTRUCT, 1, Monstfp);
fflush(Monstfp);
diff --git a/games/phantasia/phantglobs.h b/games/phantasia/phantglobs.h
index 81d187d9c1f..41700ea20d5 100644
--- a/games/phantasia/phantglobs.h
+++ b/games/phantasia/phantglobs.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: phantglobs.h,v 1.4 2002/02/16 21:27:11 millert Exp $ */
+/* $OpenBSD: phantglobs.h,v 1.5 2003/04/06 18:50:38 deraadt Exp $ */
/* $NetBSD: phantglobs.h,v 1.3 1995/04/24 12:24:39 cgd Exp $ */
/*
@@ -52,7 +52,7 @@ extern FILE *Monstfp; /* pointer to open monster file */
extern FILE *Messagefp; /* pointer to open message file */
extern FILE *Energyvoidfp; /* pointer to open energy void file */
-extern char Databuf[]; /* a place to read data into */
+extern char Databuf[SZ_DATABUF]; /* a place to read data into */
/* some canned strings for messages */
extern char Illcmd[];
diff --git a/games/phantasia/setup.c b/games/phantasia/setup.c
index dfdad09a1b3..2434e609122 100644
--- a/games/phantasia/setup.c
+++ b/games/phantasia/setup.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: setup.c,v 1.7 2002/12/06 21:48:51 millert Exp $ */
+/* $OpenBSD: setup.c,v 1.8 2003/04/06 18:50:38 deraadt Exp $ */
/* $NetBSD: setup.c,v 1.4 1995/04/24 12:24:41 cgd Exp $ */
/*
@@ -167,7 +167,7 @@ main(argc, argv)
&Curmonster.m_experience, &Curmonster.m_treasuretype,
&Curmonster.m_type, &Curmonster.m_flock);
Databuf[24] = '\0';
- strcpy(Curmonster.m_name, Databuf);
+ strlcpy(Curmonster.m_name, Databuf, sizeof Curmonster.m_name);
fwrite((char *) &Curmonster, SZ_MONSTERSTRUCT, 1, Monstfp);
}
fclose(fp);