diff options
-rw-r--r-- | games/hack/hack.bones.c | 6 | ||||
-rw-r--r-- | games/hack/hack.do_name.c | 17 | ||||
-rw-r--r-- | games/hack/hack.dog.c | 7 | ||||
-rw-r--r-- | games/hack/hack.end.c | 88 | ||||
-rw-r--r-- | games/hack/hack.engrave.c | 17 | ||||
-rw-r--r-- | games/hack/hack.fight.c | 6 | ||||
-rw-r--r-- | games/hack/hack.h | 4 | ||||
-rw-r--r-- | games/hack/hack.main.c | 16 | ||||
-rw-r--r-- | games/hack/hack.mkshop.c | 6 | ||||
-rw-r--r-- | games/hack/hack.objnam.c | 256 | ||||
-rw-r--r-- | games/hack/hack.pager.c | 6 | ||||
-rw-r--r-- | games/hack/hack.pri.c | 32 | ||||
-rw-r--r-- | games/hack/hack.shknam.c | 17 | ||||
-rw-r--r-- | games/hack/hack.topl.c | 14 | ||||
-rw-r--r-- | games/hack/hack.unix.c | 39 | ||||
-rw-r--r-- | games/hack/hack.zap.c | 6 |
16 files changed, 307 insertions, 230 deletions
diff --git a/games/hack/hack.bones.c b/games/hack/hack.bones.c index fd21e85ca85..4e96a2ae5c0 100644 --- a/games/hack/hack.bones.c +++ b/games/hack/hack.bones.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hack.bones.c,v 1.5 2003/03/16 21:22:35 camield Exp $ */ +/* $OpenBSD: hack.bones.c,v 1.6 2003/05/07 09:48:56 tdeval Exp $ */ /* * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica, @@ -62,7 +62,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: hack.bones.c,v 1.5 2003/03/16 21:22:35 camield Exp $"; +static char rcsid[] = "$OpenBSD: hack.bones.c,v 1.6 2003/05/07 09:48:56 tdeval Exp $"; #endif /* not lint */ #include "hack.h" @@ -107,7 +107,7 @@ register struct monst *mtmp; mtmp->mx = u.ux; mtmp->my = u.uy; mtmp->msleep = 1; - (void) strcpy((char *) mtmp->mextra, plname); + (void) strlcpy((char *) mtmp->mextra, plname, mtmp->mxlth); mkgold(somegold() + d(dlevel,30), u.ux, u.uy); for(mtmp = fmon; mtmp; mtmp = mtmp->nmon){ mtmp->m_id = 0; diff --git a/games/hack/hack.do_name.c b/games/hack/hack.do_name.c index 584be169e05..1531c973d26 100644 --- a/games/hack/hack.do_name.c +++ b/games/hack/hack.do_name.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hack.do_name.c,v 1.6 2003/04/06 18:50:37 deraadt Exp $ */ +/* $OpenBSD: hack.do_name.c,v 1.7 2003/05/07 09:48:57 tdeval Exp $ */ /* * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica, @@ -62,7 +62,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: hack.do_name.c,v 1.6 2003/04/06 18:50:37 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: hack.do_name.c,v 1.7 2003/05/07 09:48:57 tdeval Exp $"; #endif /* not lint */ #include "hack.h" @@ -150,7 +150,7 @@ extern char *lmonnam(); for(i=0; i<mtmp->mxlth; i++) ((char *) mtmp2->mextra)[i] = ((char *) mtmp->mextra)[i]; mtmp2->mnamelth = lth; - (void) strcpy(NAME(mtmp2), buf); + (void) strlcpy(NAME(mtmp2), buf, lth); replmon(mtmp,mtmp2); return(1); } @@ -177,7 +177,7 @@ char buf[BUFSZ]; otmp2 = newobj(lth); *otmp2 = *obj; otmp2->onamelth = lth; - (void) strcpy(ONAME(otmp2), buf); + (void) strlcpy(ONAME(otmp2), buf, lth); setworn((struct obj *) 0, obj->owornmask); setworn(otmp2, otmp2->owornmask); @@ -224,6 +224,7 @@ register struct obj *obj; register char **str1; extern char *xname(); register char *str; + size_t len; otemp = *obj; otemp.quan = 1; @@ -234,8 +235,9 @@ register struct obj *obj; clrlin(); if(!*buf || *buf == '\033') return; - str = newstring(strlen(buf)+1); - (void) strcpy(str,buf); + len = strlen(buf) + 1; + str = newstring(len); + (void) strlcpy(str, buf, len); str1 = &(objects[obj->otyp].oc_uname); if(*str1) free(*str1); *str1 = str; @@ -262,7 +264,8 @@ extern char *shkname(); if(!*gn) { /* might also look in scorefile */ gn = ghostnames[rn2(SIZE(ghostnames))]; if(!rn2(2)) (void) - strcpy((char *) mtmp->mextra, !rn2(5) ? plname : gn); + strlcpy((char *) mtmp->mextra, !rn2(5) ? plname : gn, + mtmp->mxlth); } (void) snprintf(buf, sizeof buf, "%s's ghost", gn); } diff --git a/games/hack/hack.dog.c b/games/hack/hack.dog.c index c5ae1c82803..95be6b7a204 100644 --- a/games/hack/hack.dog.c +++ b/games/hack/hack.dog.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hack.dog.c,v 1.5 2003/03/16 21:22:35 camield Exp $ */ +/* $OpenBSD: hack.dog.c,v 1.6 2003/05/07 09:48:57 tdeval Exp $ */ /* * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica, @@ -62,7 +62,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: hack.dog.c,v 1.5 2003/03/16 21:22:35 camield Exp $"; +static char rcsid[] = "$OpenBSD: hack.dog.c,v 1.6 2003/05/07 09:48:57 tdeval Exp $"; #endif /* not lint */ #include "hack.h" @@ -470,7 +470,8 @@ register struct obj *obj; mtmp2 = newmonst(sizeof(struct edog) + mtmp->mnamelth); *mtmp2 = *mtmp; mtmp2->mxlth = sizeof(struct edog); - if(mtmp->mnamelth) (void) strcpy(NAME(mtmp2), NAME(mtmp)); + if(mtmp->mnamelth) + (void) strlcpy(NAME(mtmp2), NAME(mtmp), mtmp2->mnamelth); initedog(mtmp2); replmon(mtmp,mtmp2); return(1); diff --git a/games/hack/hack.end.c b/games/hack/hack.end.c index 9a86617afe0..9091a59ab00 100644 --- a/games/hack/hack.end.c +++ b/games/hack/hack.end.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hack.end.c,v 1.6 2003/04/06 18:50:37 deraadt Exp $ */ +/* $OpenBSD: hack.end.c,v 1.7 2003/05/07 09:48:57 tdeval Exp $ */ /* * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica, @@ -62,7 +62,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: hack.end.c,v 1.6 2003/04/06 18:50:37 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: hack.end.c,v 1.7 2003/05/07 09:48:57 tdeval Exp $"; #endif /* not lint */ #include "hack.h" @@ -321,7 +321,7 @@ topten(){ (t0->name)[NAMSZ] = 0; (void) strncpy(t0->death, killer, DTHSZ); (t0->death)[DTHSZ] = 0; - (void) strcpy(t0->date, getdate()); + (void) strlcpy(t0->date, getdate(), sizeof t0->date); /* assure minimum number of points */ if(t0->points < POINTSMIN) @@ -437,10 +437,10 @@ unlock: outheader() { char linebuf[BUFSZ]; register char *bp; - (void) strcpy(linebuf, "Number Points Name"); + (void) strlcpy(linebuf, "Number Points Name", sizeof linebuf); bp = eos(linebuf); while(bp < linebuf + COLNO - 9) *bp++ = ' '; - (void) strcpy(bp, "Hp [max]"); + (void) strlcpy(bp, "Hp [max]", linebuf + sizeof linebuf - bp); puts(linebuf); } @@ -449,59 +449,83 @@ int outentry(rank,t1,so) register struct toptenentry *t1; { boolean quit = FALSE, killed = FALSE, starv = FALSE; char linebuf[BUFSZ]; +char *bp; linebuf[0] = 0; - if(rank) sprintf(eos(linebuf), "%3d", rank); - else sprintf(eos(linebuf), " "); - sprintf(eos(linebuf), " %6ld %8s", t1->points, t1->name); - if(t1->plchar == 'X') sprintf(eos(linebuf), " "); - else sprintf(eos(linebuf), "-%c ", t1->plchar); + if(rank) + snprintf(linebuf, sizeof linebuf, "%3d", rank); + else + snprintf(linebuf, sizeof linebuf, " "); + bp = eos(linebuf); + snprintf(bp, linebuf + sizeof linebuf - bp, " %6ld %8s", + t1->points, t1->name); + if(t1->plchar == 'X') + strlcat(linebuf, " ", sizeof linebuf); + else { + bp = eos(linebuf); + snprintf(bp, linebuf + sizeof linebuf - bp, + "-%c ", t1->plchar); + } + bp = eos(linebuf); if(!strncmp("escaped", t1->death, 7)) { if(!strcmp(" (with amulet)", t1->death+7)) - sprintf(eos(linebuf), "escaped the dungeon with amulet"); + snprintf(bp, linebuf + sizeof linebuf - bp, + "escaped the dungeon with amulet"); else - sprintf(eos(linebuf), "escaped the dungeon [max level %d]", - t1->maxlvl); + snprintf(bp, linebuf + sizeof linebuf - bp, + "escaped the dungeon [max level %d]", t1->maxlvl); } else { if(!strncmp(t1->death,"quit",4)) { quit = TRUE; if(t1->maxhp < 3*t1->hp && t1->maxlvl < 4) - sprintf(eos(linebuf), "cravenly gave up"); + strlcat(linebuf, "cravenly gave up", sizeof linebuf); else - sprintf(eos(linebuf), "quit"); + strlcat(linebuf, "quit", sizeof linebuf); } else if(!strcmp(t1->death,"choked")) - sprintf(eos(linebuf), "choked on %s food", + snprintf(bp, linebuf + sizeof linebuf - bp, "choked on %s food", (t1->sex == 'F') ? "her" : "his"); - else if(!strncmp(t1->death,"starv",5)) - sprintf(eos(linebuf), "starved to death"), starv = TRUE; - else sprintf(eos(linebuf), "was killed"), killed = TRUE; - sprintf(eos(linebuf), " on%s level %d", + else if(!strncmp(t1->death,"starv",5)) { + strlcat(linebuf, "starved to death", sizeof linebuf); + starv = TRUE; + } else { + strlcat(linebuf, "was killed", sizeof linebuf); + killed = TRUE; + } + bp = eos(linebuf); + snprintf(bp, linebuf + sizeof linebuf - bp, " on%s level %d", (killed || starv) ? "" : " dungeon", t1->level); - if(t1->maxlvl != t1->level) - sprintf(eos(linebuf), " [max %d]", t1->maxlvl); - if(quit && t1->death[4]) sprintf(eos(linebuf), t1->death + 4); + if(t1->maxlvl != t1->level) { + bp = eos(linebuf); + snprintf(bp, linebuf + sizeof linebuf - bp, + " [max %d]", t1->maxlvl); + } + if(quit && t1->death[4]) + strlcat(linebuf, t1->death + 4, sizeof linebuf); } - if(killed) sprintf(eos(linebuf), " by %s%s", - (!strncmp(t1->death, "trick", 5) || !strncmp(t1->death, "the ", 4)) + if(killed) { + bp = eos(linebuf); + snprintf(bp, linebuf + sizeof linebuf - bp, " by %s%s", + (!strncmp(t1->death, "trick", 5) || !strncmp(t1->death, "the ", 4)) ? "" : - strchr(vowels,*t1->death) ? "an " : "a ", - t1->death); - sprintf(eos(linebuf), "."); + strchr(vowels,*t1->death) ? "an " : "a ", t1->death); + } + strlcat(linebuf, ".", sizeof linebuf); if(t1->maxhp) { - register char *bp = eos(linebuf); char hpbuf[10]; int hppos; + bp = eos(linebuf); snprintf(hpbuf, sizeof hpbuf, (t1->hp > 0) ? itoa(t1->hp) : "-"); hppos = COLNO - 7 - strlen(hpbuf); if(bp <= linebuf + hppos) { while(bp < linebuf + hppos) *bp++ = ' '; - (void) strcpy(bp, hpbuf); - sprintf(eos(bp), " [%d]", t1->maxhp); + (void) strlcpy(bp, hpbuf, linebuf + sizeof linebuf - bp); + bp = eos(linebuf); + snprintf(bp, linebuf + sizeof linebuf - bp, " [%d]", t1->maxhp); } } if(so == 0) puts(linebuf); else if(so > 0) { - register char *bp = eos(linebuf); + bp = eos(linebuf); if(so >= COLNO) so = COLNO-1; while(bp < linebuf + so) *bp++ = ' '; *bp = 0; diff --git a/games/hack/hack.engrave.c b/games/hack/hack.engrave.c index 784e69848d6..df712cbbaa3 100644 --- a/games/hack/hack.engrave.c +++ b/games/hack/hack.engrave.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hack.engrave.c,v 1.3 2003/03/16 21:22:35 camield Exp $ */ +/* $OpenBSD: hack.engrave.c,v 1.4 2003/05/07 09:48:57 tdeval Exp $ */ /* * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica, @@ -62,7 +62,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: hack.engrave.c,v 1.3 2003/03/16 21:22:35 camield Exp $"; +static char rcsid[] = "$OpenBSD: hack.engrave.c,v 1.4 2003/05/07 09:48:57 tdeval Exp $"; #endif /* not lint */ #include "hack.h" @@ -168,20 +168,21 @@ register int x,y; register char *s; { register struct engr *ep; + register size_t len = strlen(s) + 1; if(ep = engr_at(x,y)) del_engr(ep); ep = (struct engr *) - alloc((unsigned)(sizeof(struct engr) + strlen(s) + 1)); + alloc((unsigned)(sizeof(struct engr) + len)); ep->nxt_engr = head_engr; head_engr = ep; ep->engr_x = x; ep->engr_y = y; ep->engr_txt = (char *)(ep + 1); - (void) strcpy(ep->engr_txt, s); + (void) strlcpy(ep->engr_txt, s, len); ep->engr_time = 0; ep->engr_type = DUST; - ep->engr_lth = strlen(s) + 1; + ep->engr_lth = len; } doengrave(){ @@ -306,11 +307,11 @@ register struct obj *otmp; sp = (char *)(ep + 1); /* (char *)ep + sizeof(struct engr) */ ep->engr_txt = sp; if(oep) { - (void) strcpy(sp, oep->engr_txt); - (void) strcat(sp, buf); + (void) strlcpy(sp, oep->engr_txt, len + 1); + (void) strlcat(sp, buf, len + 1); del_engr(oep); } else - (void) strcpy(sp, buf); + (void) strlcpy(sp, buf, len + 1); ep->engr_lth = len+1; ep->engr_type = type; ep->engr_time = moves-multi; diff --git a/games/hack/hack.fight.c b/games/hack/hack.fight.c index 757d0b12545..f0658e73874 100644 --- a/games/hack/hack.fight.c +++ b/games/hack/hack.fight.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hack.fight.c,v 1.6 2003/04/06 18:50:37 deraadt Exp $ */ +/* $OpenBSD: hack.fight.c,v 1.7 2003/05/07 09:48:57 tdeval Exp $ */ /* * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica, @@ -62,7 +62,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: hack.fight.c,v 1.6 2003/04/06 18:50:37 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: hack.fight.c,v 1.7 2003/05/07 09:48:57 tdeval Exp $"; #endif /* not lint */ #include "hack.h" @@ -175,7 +175,7 @@ register tlev,dam; register char *name; { char buf[BUFSZ]; - setan(name,buf); + setan(name,buf,sizeof buf); if(u.uac + tlev <= rnd(20)) { if(Blind) pline("It misses."); else pline("You are almost hit by %s!", buf); diff --git a/games/hack/hack.h b/games/hack/hack.h index c52c0626567..910f602c34d 100644 --- a/games/hack/hack.h +++ b/games/hack/hack.h @@ -1,4 +1,4 @@ -/* $OpenBSD: hack.h,v 1.6 2003/03/16 21:22:35 camield Exp $*/ +/* $OpenBSD: hack.h,v 1.7 2003/05/07 09:48:57 tdeval Exp $*/ /* $NetBSD: hack.h,v 1.3 1995/03/23 08:30:21 cgd Exp $*/ /* @@ -206,7 +206,7 @@ extern long moves; extern int multi; -extern char lock[]; +extern char lock[PL_NSIZ+4]; #define DIST(x1,y1,x2,y2) (((x1)-(x2))*((x1)-(x2)) + ((y1)-(y2))*((y1)-(y2))) diff --git a/games/hack/hack.main.c b/games/hack/hack.main.c index 5a0acc8a4d7..d5e07c92d08 100644 --- a/games/hack/hack.main.c +++ b/games/hack/hack.main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hack.main.c,v 1.10 2003/04/06 18:50:37 deraadt Exp $ */ +/* $OpenBSD: hack.main.c,v 1.11 2003/05/07 09:48:57 tdeval Exp $ */ /* * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica, @@ -62,7 +62,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: hack.main.c,v 1.10 2003/04/06 18:50:37 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: hack.main.c,v 1.11 2003/05/07 09:48:57 tdeval Exp $"; #endif /* not lint */ #include <stdio.h> @@ -78,7 +78,7 @@ static char rcsid[] = "$OpenBSD: hack.main.c,v 1.10 2003/04/06 18:50:37 deraadt extern char *getlogin(), *getenv(); extern char plname[PL_NSIZ], pl_character[PL_CSIZ]; extern struct permonst mons[CMNUM+2]; -extern char genocided[], fut_geno[]; +extern char genocided[60], fut_geno[60]; int (*afternmv)(); int (*occupation)(); @@ -277,12 +277,12 @@ char *argv[]; (void) signal(SIGQUIT,SIG_IGN); (void) signal(SIGINT,SIG_IGN); if(!locknum) - (void) strcpy(lock,plname); + (void) strlcpy(lock,plname,sizeof lock); getlock(); /* sets lock if locknum != 0 */ #ifdef WIZARD } else { register char *sfoo; - (void) strcpy(lock,plname); + (void) strlcpy(lock,plname,sizeof lock); if(sfoo = getenv("MAGIC")) while(*sfoo) { switch(*sfoo++) { @@ -302,8 +302,8 @@ char *argv[]; } *gp = 0; } else - (void) strcpy(genocided, sfoo); - (void) strcpy(fut_geno, genocided); + strlcpy(genocided, sfoo, sizeof genocided); + strlcpy(fut_geno, genocided, sizeof fut_geno); } } #endif @@ -479,7 +479,7 @@ register foo; tf = lock; while(*tf && *tf != '.') tf++; - (void) sprintf(tf, ".%d", foo); + (void) snprintf(tf, lock + sizeof lock - tf, ".%d", foo); } /* diff --git a/games/hack/hack.mkshop.c b/games/hack/hack.mkshop.c index 48011fcf502..7e68ce539c4 100644 --- a/games/hack/hack.mkshop.c +++ b/games/hack/hack.mkshop.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hack.mkshop.c,v 1.4 2003/03/16 21:22:36 camield Exp $ */ +/* $OpenBSD: hack.mkshop.c,v 1.5 2003/05/07 09:48:57 tdeval Exp $ */ /* * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica, @@ -62,7 +62,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: hack.mkshop.c,v 1.4 2003/03/16 21:22:36 camield Exp $"; +static char rcsid[] = "$OpenBSD: hack.mkshop.c,v 1.5 2003/05/07 09:48:57 tdeval Exp $"; #endif /* not lint */ #include <stdlib.h> @@ -178,7 +178,7 @@ gottype: ESHK->following = 0; shk->mgold = 1000 + 30*rnd(100); /* initial capital */ ESHK->billct = 0; - findname(ESHK->shknam, let); + findname(ESHK->shknam, sizeof ESHK->shknam, let); for(sx = sroom->lx; sx <= sroom->hx; sx++) for(sy = sroom->ly; sy <= sroom->hy; sy++){ register struct monst *mtmp; diff --git a/games/hack/hack.objnam.c b/games/hack/hack.objnam.c index d671260acba..902e56a06ff 100644 --- a/games/hack/hack.objnam.c +++ b/games/hack/hack.objnam.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hack.objnam.c,v 1.6 2003/04/06 18:50:37 deraadt Exp $ */ +/* $OpenBSD: hack.objnam.c,v 1.7 2003/05/07 09:48:57 tdeval Exp $ */ /* * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica, @@ -62,7 +62,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: hack.objnam.c,v 1.6 2003/04/06 18:50:37 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: hack.objnam.c,v 1.7 2003/05/07 09:48:57 tdeval Exp $"; #endif /* not lint */ #include "hack.h" @@ -70,6 +70,8 @@ static char rcsid[] = "$OpenBSD: hack.objnam.c,v 1.6 2003/04/06 18:50:37 deraadt extern char *eos(); extern int bases[]; +static char bufr[BUFSZ]; + char * strprepend(s,pref) register char *s, *pref; { register int i = strlen(pref); @@ -98,6 +100,7 @@ register struct objclass *ocl = &objects[otyp]; register char *an = ocl->oc_name; register char *dn = ocl->oc_descr; register char *un = ocl->oc_uname; +register char *bp; register int nn = ocl->oc_name_known; switch(ocl->oc_olet) { case POTION_SYM: @@ -117,26 +120,41 @@ register int nn = ocl->oc_name_known; strlcpy(buf, an, sizeof buf); if(otyp >= TURQUOISE && otyp <= JADE) strlcat(buf, " stone", sizeof buf); - if(un) - sprintf(eos(buf), " called %s", un); - if(dn) - sprintf(eos(buf), " (%s)", dn); + if(un) { + bp = eos(buf); + snprintf(bp, buf + sizeof buf - bp, + " called %s", un); + } + if(dn) { + bp = eos(buf); + snprintf(bp, buf + sizeof buf - bp, + " (%s)", dn); + } } else { strlcpy(buf, dn ? dn : an, sizeof buf); if(ocl->oc_olet == GEM_SYM) strlcat(buf, " gem", sizeof buf); - if(un) - sprintf(eos(buf), " called %s", un); + if(un) { + bp = eos(buf); + snprintf(bp, buf + sizeof buf - bp, + " called %s", un); + } } return(buf); } /* here for ring/scroll/potion/wand */ - if(nn) - sprintf(eos(buf), " of %s", an); - if(un) - sprintf(eos(buf), " called %s", un); - if(dn) - sprintf(eos(buf), " (%s)", dn); + if(nn) { + bp = eos(buf); + snprintf(bp, buf + sizeof buf - bp, " of %s", an); + } + if(un) { + bp = eos(buf); + snprintf(bp, buf + sizeof buf - bp, " called %s", un); + } + if(dn) { + bp = eos(buf); + snprintf(bp, buf + sizeof buf - bp, " (%s)", dn); + } return(buf); } @@ -144,31 +162,31 @@ char * xname(obj) register struct obj *obj; { -static char bufr[BUFSZ]; register char *buf = &(bufr[PREFIX]); /* leave room for "17 -3 " */ register int nn = objects[obj->otyp].oc_name_known; register char *an = objects[obj->otyp].oc_name; register char *dn = objects[obj->otyp].oc_descr; register char *un = objects[obj->otyp].oc_uname; register int pl = (obj->quan != 1); +size_t len = bufr + sizeof bufr - buf; if(!obj->dknown && !Blind) obj->dknown = 1; /* %% doesn't belong here */ switch(obj->olet) { case AMULET_SYM: - strcpy(buf, (obj->spe < 0 && obj->known) - ? "cheap plastic imitation of the " : ""); - strcat(buf,"Amulet of Yendor"); + strlcpy(buf, (obj->spe < 0 && obj->known) + ? "cheap plastic imitation of the " : "", len); + strlcat(buf,"Amulet of Yendor", len); break; case TOOL_SYM: if(!nn) { - strcpy(buf, dn); + strlcpy(buf, dn, len); break; } - strcpy(buf,an); + strlcpy(buf,an,len); break; case FOOD_SYM: if(obj->otyp == DEAD_HOMUNCULUS && pl) { pl = 0; - strcpy(buf, "dead homunculi"); + strlcpy(buf, "dead homunculi", len); break; } /* fungis ? */ @@ -176,97 +194,97 @@ register int pl = (obj->quan != 1); case WEAPON_SYM: if(obj->otyp == WORM_TOOTH && pl) { pl = 0; - strcpy(buf, "worm teeth"); + strlcpy(buf, "worm teeth", len); break; } if(obj->otyp == CRYSKNIFE && pl) { pl = 0; - strcpy(buf, "crysknives"); + strlcpy(buf, "crysknives", len); break; } /* fall into next case */ case ARMOR_SYM: case CHAIN_SYM: case ROCK_SYM: - strcpy(buf,an); + strlcpy(buf,an,len); break; case BALL_SYM: - sprintf(buf, "%sheavy iron ball", + snprintf(buf, len, "%sheavy iron ball", (obj->owt > objects[obj->otyp].oc_weight) ? "very " : ""); break; case POTION_SYM: if(nn || un || !obj->dknown) { - strcpy(buf, "potion"); + strlcpy(buf, "potion", len); if(pl) { pl = 0; - strcat(buf, "s"); + strlcat(buf, "s", len); } if(!obj->dknown) break; if(un) { - strcat(buf, " called "); - strcat(buf, un); + strlcat(buf, " called ", len); + strlcat(buf, un, len); } else { - strcat(buf, " of "); - strcat(buf, an); + strlcat(buf, " of ", len); + strlcat(buf, an, len); } } else { - strcpy(buf, dn); - strcat(buf, " potion"); + strlcpy(buf, dn, len); + strlcat(buf, " potion", len); } break; case SCROLL_SYM: - strcpy(buf, "scroll"); + strlcpy(buf, "scroll", len); if(pl) { pl = 0; - strcat(buf, "s"); + strlcat(buf, "s", len); } if(!obj->dknown) break; if(nn) { - strcat(buf, " of "); - strcat(buf, an); + strlcat(buf, " of ", len); + strlcat(buf, an, len); } else if(un) { - strcat(buf, " called "); - strcat(buf, un); + strlcat(buf, " called ", len); + strlcat(buf, un, len); } else { - strcat(buf, " labeled "); - strcat(buf, dn); + strlcat(buf, " labeled ", len); + strlcat(buf, dn, len); } break; case WAND_SYM: if(!obj->dknown) - sprintf(buf, "wand"); + snprintf(buf, len, "wand"); else if(nn) - sprintf(buf, "wand of %s", an); + snprintf(buf, len, "wand of %s", an); else if(un) - sprintf(buf, "wand called %s", un); + snprintf(buf, len, "wand called %s", un); else - sprintf(buf, "%s wand", dn); + snprintf(buf, len, "%s wand", dn); break; case RING_SYM: if(!obj->dknown) - sprintf(buf, "ring"); + snprintf(buf, len, "ring"); else if(nn) - sprintf(buf, "ring of %s", an); + snprintf(buf, len, "ring of %s", an); else if(un) - sprintf(buf, "ring called %s", un); + snprintf(buf, len, "ring called %s", un); else - sprintf(buf, "%s ring", dn); + snprintf(buf, len, "%s ring", dn); break; case GEM_SYM: if(!obj->dknown) { - strcpy(buf, "gem"); + strlcpy(buf, "gem", len); break; } if(!nn) { - sprintf(buf, "%s gem", dn); + snprintf(buf, len, "%s gem", dn); break; } - strcpy(buf, an); + strlcpy(buf, an, len); if(obj->otyp >= TURQUOISE && obj->otyp <= JADE) - strcat(buf, " stone"); + strlcat(buf, " stone", len); break; default: - sprintf(buf,"glorkum %c (0%o) %u %d", + snprintf(buf,len,"glorkum %c (0%o) %u %d", obj->olet,obj->olet,obj->otyp,obj->spe); } if(pl) { @@ -286,16 +304,17 @@ register int pl = (obj->quan != 1); p = eos(buf)-1; if(*p == 's' || *p == 'z' || *p == 'x' || (*p == 'h' && p[-1] == 's')) - strcat(buf, "es"); /* boxes */ + strlcat(buf, "es", len); /* boxes */ else if(*p == 'y' && !strchr(vowels, p[-1])) - strcpy(p, "ies"); /* rubies, zruties */ + /* rubies, zruties */ + strlcpy(p, "ies", bufr + sizeof bufr - p); else - strcat(buf, "s"); + strlcat(buf, "s", len); } nopl: if(obj->onamelth) { - strcat(buf, " named "); - strcat(buf, ONAME(obj)); + strlcat(buf, " named ", len); + strlcat(buf, ONAME(obj), len); } return(buf); } @@ -306,6 +325,7 @@ register struct obj *obj; { char prefix[PREFIX]; register char *bp = xname(obj); +register char *p; if(obj->quan != 1) snprintf(prefix, sizeof prefix, "%u ", obj->quan); else @@ -317,7 +337,7 @@ register char *bp = xname(obj); break; case ARMOR_SYM: if(obj->owornmask & W_ARMOR) - strcat(bp, " (being worn)"); + strlcat(bp, " (being worn)", bufr + sizeof bufr - bp); /* fall into next case */ case WEAPON_SYM: if(obj->known) { @@ -326,12 +346,16 @@ register char *bp = xname(obj); } break; case WAND_SYM: - if(obj->known) - sprintf(eos(bp), " (%d)", obj->spe); + if(obj->known) { + p = eos(bp); + snprintf(p, bufr + sizeof bufr - p, " (%d)", obj->spe); + } break; case RING_SYM: - if(obj->owornmask & W_RINGR) strcat(bp, " (on right hand)"); - if(obj->owornmask & W_RINGL) strcat(bp, " (on left hand)"); + if(obj->owornmask & W_RINGR) + strlcat(bp, " (on right hand)", bufr + sizeof bufr - bp); + if(obj->owornmask & W_RINGL) + strlcat(bp, " (on left hand)", bufr + sizeof bufr - bp); if(obj->known && (objects[obj->otyp].bits & SPEC)) { strlcat(prefix, sitoa(obj->spe), sizeof prefix); strlcat(prefix, " ", sizeof prefix); @@ -339,9 +363,9 @@ register char *bp = xname(obj); break; } if(obj->owornmask & W_WEP) - strcat(bp, " (weapon in hand)"); + strlcat(bp, " (weapon in hand)", bufr + sizeof bufr - bp); if(obj->unpaid) - strcat(bp, " (unpaid)"); + strlcat(bp, " (unpaid)", bufr + sizeof bufr - bp); if(!strcmp(prefix, "a ") && strchr(vowels, *bp)) strlcpy(prefix, "an ", sizeof prefix); bp = strprepend(bp, prefix); @@ -349,13 +373,14 @@ register char *bp = xname(obj); } /* used only in hack.fight.c (thitu) */ -setan(str,buf) +setan(str,buf,len) register char *str,*buf; +register size_t len; { if(strchr(vowels,*str)) - sprintf(buf, "an %s", str); + snprintf(buf, len, "an %s", str); else - sprintf(buf, "a %s", str); + snprintf(buf, len, "a %s", str); } char * @@ -369,14 +394,14 @@ char prefix[PREFIX]; if(verb) { /* verb is given in plural (i.e., without trailing s) */ - strcat(bp, " "); + strlcat(bp, " ", bufr + sizeof bufr - bp); if(otmp->quan != 1) - strcat(bp, verb); + strlcat(bp, verb, bufr + sizeof bufr - bp); else if(!strcmp(verb, "are")) - strcat(bp, "is"); + strlcat(bp, "is", bufr + sizeof bufr - bp); else { - strcat(bp, verb); - strcat(bp, "s"); + strlcat(bp, verb, bufr + sizeof bufr - bp); + strlcat(bp, "s", bufr + sizeof bufr - bp); } } return(bp); @@ -396,8 +421,11 @@ char *wrp[] = { "wand", "ring", "potion", "scroll", "gem" }; char wrpsym[] = { WAND_SYM, RING_SYM, POTION_SYM, SCROLL_SYM, GEM_SYM }; struct obj * -readobjnam(bp) register char *bp; { -register char *p; +readobjnam(bp, len) +register char *bp; +register size_t len; +{ +register char *p, *cp = bp; register int i; int cnt, spe, spesgn, typ, heavy; char let; @@ -406,34 +434,34 @@ char *un, *dn, *an; cnt = spe = spesgn = typ = heavy = 0; let = 0; an = dn = un = 0; - for(p = bp; *p; p++) + for(p = cp; *p; p++) if('A' <= *p && *p <= 'Z') *p += 'a'-'A'; - if(!strncmp(bp, "the ", 4)){ + if(!strncmp(cp, "the ", 4)){ /* the = 1; */ - bp += 4; - } else if(!strncmp(bp, "an ", 3)){ + cp += 4; + } else if(!strncmp(cp, "an ", 3)){ cnt = 1; - bp += 3; - } else if(!strncmp(bp, "a ", 2)){ + cp += 3; + } else if(!strncmp(cp, "a ", 2)){ cnt = 1; - bp += 2; + cp += 2; } - if(!cnt && digit(*bp)){ - cnt = atoi(bp); - while(digit(*bp)) bp++; - while(*bp == ' ') bp++; + if(!cnt && digit(*cp)){ + cnt = atoi(cp); + while(digit(*cp)) cp++; + while(*cp == ' ') cp++; } if(!cnt) cnt = 1; /* %% what with "gems" etc. ? */ - if(*bp == '+' || *bp == '-'){ - spesgn = (*bp++ == '+') ? 1 : -1; - spe = atoi(bp); - while(digit(*bp)) bp++; - while(*bp == ' ') bp++; + if(*cp == '+' || *cp == '-'){ + spesgn = (*cp++ == '+') ? 1 : -1; + spe = atoi(cp); + while(digit(*cp)) cp++; + while(*cp == ' ') cp++; } else { - p = strrchr(bp, '('); + p = strrchr(cp, '('); if(p) { - if(p > bp && p[-1] == ' ') p[-1] = 0; + if(p > cp && p[-1] == ' ') p[-1] = 0; else *p = 0; p++; spe = atoi(p); @@ -452,15 +480,15 @@ char *un, *dn, *an; wand of wishing elven cloak */ - for(p = bp; *p; p++) if(!strncmp(p, " named ", 7)) { + for(p = cp; *p; p++) if(!strncmp(p, " named ", 7)) { *p = 0; /* oname = p+7; */ } - for(p = bp; *p; p++) if(!strncmp(p, " called ", 8)) { + for(p = cp; *p; p++) if(!strncmp(p, " called ", 8)) { *p = 0; un = p+8; } - for(p = bp; *p; p++) if(!strncmp(p, " labeled ", 9)) { + for(p = cp; *p; p++) if(!strncmp(p, " labeled ", 9)) { *p = 0; dn = p+9; } @@ -468,24 +496,24 @@ char *un, *dn, *an; /* first change to singular if necessary */ if(cnt != 1) { /* find "cloves of garlic", "worthless pieces of blue glass" */ - for(p = bp; *p; p++) if(!strncmp(p, "s of ", 5)){ + for(p = cp; *p; p++) if(!strncmp(p, "s of ", 5)){ while(*p = p[1]) p++; goto sing; } /* remove -s or -es (boxes) or -ies (rubies, zruties) */ - p = eos(bp); + p = eos(cp); if(p[-1] == 's') { if(p[-2] == 'e') { if(p[-3] == 'i') { if(!strcmp(p-7, "cookies")) goto mins; - strcpy(p-3, "y"); + strlcpy(p-3, "y", bp + len - (p-3)); goto sing; } /* note: cloves / knives from clove / knife */ if(!strcmp(p-6, "knives")) { - strcpy(p-3, "fe"); + strlcpy(p-3, "fe", bp + len - (p-3)); goto sing; } @@ -499,34 +527,34 @@ char *un, *dn, *an; p[-1] = 0; } else { if(!strcmp(p-9, "homunculi")) { - strcpy(p-1, "us"); /* !! makes string longer */ + strlcpy(p-1, "us", bp + len - (p-1)); goto sing; } if(!strcmp(p-5, "teeth")) { - strcpy(p-5, "tooth"); + strlcpy(p-5, "tooth", bp + len - (p-5)); goto sing; } /* here we cannot find the plural suffix */ } } sing: - if(!strcmp(bp, "amulet of yendor")) { + if(!strcmp(cp, "amulet of yendor")) { typ = AMULET_OF_YENDOR; goto typfnd; } - p = eos(bp); + p = eos(cp); if(!strcmp(p-5, " mail")){ /* Note: ring mail is not a ring ! */ let = ARMOR_SYM; - an = bp; + an = cp; goto srch; } for(i = 0; i < sizeof(wrpsym); i++) { register int j = strlen(wrp[i]); - if(!strncmp(bp, wrp[i], j)){ + if(!strncmp(cp, wrp[i], j)){ let = wrpsym[i]; - bp += j; - if(!strncmp(bp, " of ", 4)) an = bp+4; - /* else if(*bp) ?? */ + cp += j; + if(!strncmp(cp, " of ", 4)) an = cp+4; + /* else if(*cp) ?? */ goto srch; } if(!strcmp(p-j, wrp[i])){ @@ -534,22 +562,22 @@ sing: p -= j; *p = 0; if(p[-1] == ' ') p[-1] = 0; - dn = bp; + dn = cp; goto srch; } } if(!strcmp(p-6, " stone")){ p[-6] = 0; let = GEM_SYM; - an = bp; + an = cp; goto srch; } - if(!strcmp(bp, "very heavy iron ball")){ + if(!strcmp(cp, "very heavy iron ball")){ heavy = 1; typ = HEAVY_IRON_BALL; goto typfnd; } - an = bp; + an = cp; srch: if(!an && !dn && !un) goto any; diff --git a/games/hack/hack.pager.c b/games/hack/hack.pager.c index 2b8062ce46b..c91dbb993fb 100644 --- a/games/hack/hack.pager.c +++ b/games/hack/hack.pager.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hack.pager.c,v 1.8 2003/03/16 21:22:36 camield Exp $ */ +/* $OpenBSD: hack.pager.c,v 1.9 2003/05/07 09:48:57 tdeval Exp $ */ /* * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica, @@ -62,7 +62,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: hack.pager.c,v 1.8 2003/03/16 21:22:36 camield Exp $"; +static char rcsid[] = "$OpenBSD: hack.pager.c,v 1.9 2003/05/07 09:48:57 tdeval Exp $"; #endif /* not lint */ /* This file contains the command routine dowhatis() and a pager. */ @@ -278,7 +278,7 @@ char *text; alloc((unsigned)(len + sizeof(struct line) + 1)); tl->next_line = 0; tl->line_text = (char *)(tl + 1); - (void) strcpy(tl->line_text, text); + (void) strlcpy(tl->line_text, text, len + 1); if(!texthead) texthead = tl; else diff --git a/games/hack/hack.pri.c b/games/hack/hack.pri.c index b2a432e8941..998bd3279a8 100644 --- a/games/hack/hack.pri.c +++ b/games/hack/hack.pri.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hack.pri.c,v 1.6 2003/04/06 18:50:37 deraadt Exp $ */ +/* $OpenBSD: hack.pri.c,v 1.7 2003/05/07 09:48:57 tdeval Exp $ */ /* * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica, @@ -62,7 +62,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: hack.pri.c,v 1.6 2003/04/06 18:50:37 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: hack.pri.c,v 1.7 2003/05/07 09:48:57 tdeval Exp $"; #endif /* not lint */ #include "hack.h" @@ -655,7 +655,7 @@ register int lth; bot() { -register char *ob = oldbot, *nb = newbot; +register char *ob = oldbot, *nb = newbot, *bp; register int i; extern char *eos(); if(flags.botlx) *ob = 0; @@ -672,18 +672,28 @@ extern char *eos(); if(u.ustr>18) { if(u.ustr>117) (void) strlcat(newbot,"18/**",sizeof newbot); - else - (void) sprintf(eos(newbot), "18/%02d",u.ustr-18); - } else - (void) sprintf(eos(newbot), "%-2d ",u.ustr); + else { + bp = eos(newbot); + (void) snprintf(bp, newbot + sizeof newbot - bp, + "18/%02d",u.ustr-18); + } + } else { + bp = eos(newbot); + (void) snprintf(bp, newbot + sizeof newbot - bp, "%-2d ",u.ustr); + } + bp = eos(newbot); #ifdef EXP_ON_BOTL - (void) sprintf(eos(newbot), " Exp %2d/%-5lu ", u.ulevel,u.uexp); + (void) snprintf(bp, newbot + sizeof newbot - bp, + " Exp %2d/%-5lu ", u.ulevel,u.uexp); #else - (void) sprintf(eos(newbot), " Exp %2u ", u.ulevel); + (void) snprintf(bp, newbot + sizeof newbot - bp, + " Exp %2u ", u.ulevel); #endif /* EXP_ON_BOTL */ (void) strlcat(newbot, hu_stat[u.uhs], sizeof newbot); - if(flags.time) - (void) sprintf(eos(newbot), " %ld", moves); + if(flags.time) { + bp = eos(newbot); + (void) snprintf(bp, newbot + sizeof newbot - bp, " %ld", moves); + } if(strlen(newbot) >= COLNO) { register char *bp0, *bp1; bp0 = bp1 = newbot; diff --git a/games/hack/hack.shknam.c b/games/hack/hack.shknam.c index 6887446d7c7..e0dacb3b2cd 100644 --- a/games/hack/hack.shknam.c +++ b/games/hack/hack.shknam.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hack.shknam.c,v 1.4 2003/03/16 21:22:36 camield Exp $ */ +/* $OpenBSD: hack.shknam.c,v 1.5 2003/05/07 09:48:57 tdeval Exp $ */ /* * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica, @@ -62,7 +62,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: hack.shknam.c,v 1.4 2003/03/16 21:22:36 camield Exp $"; +static char rcsid[] = "$OpenBSD: hack.shknam.c,v 1.5 2003/05/07 09:48:57 tdeval Exp $"; #endif /* not lint */ #include "hack.h" @@ -187,7 +187,7 @@ struct shk_nx { { 0, shkgeneral } }; -findname(nampt, let) char *nampt; char let; { +findname(nampt, len, let) char *nampt; size_t len; char let; { register struct shk_nx *p = shk_nx; register char **q; register int i; @@ -195,10 +195,13 @@ register int i; q = p->xn; for(i=0; i<dlevel; i++) if(!q[i]){ /* Not enough names, try general name */ - if(let) findname(nampt, 0); - else (void) strcpy(nampt, "Dirk"); + if(let) findname(nampt, len, 0); + else { + (void) strncpy(nampt, "Dirk", len-1); + nampt[len-1] = '\0'; + } return; } - (void) strncpy(nampt, q[i], PL_NSIZ-1); - nampt[PL_NSIZ-1] = 0; + (void) strncpy(nampt, q[i], len-1); + nampt[len-1] = '\0'; } diff --git a/games/hack/hack.topl.c b/games/hack/hack.topl.c index fa703d16bec..8ece23f2690 100644 --- a/games/hack/hack.topl.c +++ b/games/hack/hack.topl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hack.topl.c,v 1.6 2003/04/06 18:50:37 deraadt Exp $ */ +/* $OpenBSD: hack.topl.c,v 1.7 2003/05/07 09:48:57 tdeval Exp $ */ /* * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica, @@ -62,7 +62,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: hack.topl.c,v 1.6 2003/04/06 18:50:37 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: hack.topl.c,v 1.7 2003/05/07 09:48:57 tdeval Exp $"; #endif /* not lint */ #include "hack.h" @@ -106,16 +106,18 @@ redotoplin() { remember_topl() { register struct topl *tl; register int cnt = OTLMAX; +register size_t slen; if(last_redone_topl && !strcmp(toplines, last_redone_topl->topl_text)) return; if(old_toplines && !strcmp(toplines, old_toplines->topl_text)) return; last_redone_topl = 0; + slen = strlen(toplines) + 1; tl = (struct topl *) - alloc((unsigned)(strlen(toplines) + sizeof(struct topl) + 1)); + alloc(sizeof(struct topl) + slen); tl->next_topl = old_toplines; tl->topl_text = (char *)(tl + 1); - (void) strcpy(tl->topl_text, toplines); + (void) strlcpy(tl->topl_text, toplines, slen); old_toplines = tl; while(cnt && tl){ cnt--; @@ -227,7 +229,9 @@ register char *line,*arg1,*arg2,*arg3,*arg4,*arg5,*arg6; tl[--n0] = 0; n0 = strlen(bp); - if(n0 && tl[0]) (void) strcat(tl, "\n"); + if(n0 && tl[0]) + (void) strlcat(tl, "\n", + toplines + sizeof toplines - tl); } redotoplin(); } diff --git a/games/hack/hack.unix.c b/games/hack/hack.unix.c index 1c0f890f38e..a15b8f27bf7 100644 --- a/games/hack/hack.unix.c +++ b/games/hack/hack.unix.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hack.unix.c,v 1.11 2003/04/06 18:50:37 deraadt Exp $ */ +/* $OpenBSD: hack.unix.c,v 1.12 2003/05/07 09:48:57 tdeval Exp $ */ /* * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica, @@ -62,7 +62,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: hack.unix.c,v 1.11 2003/04/06 18:50:37 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: hack.unix.c,v 1.12 2003/05/07 09:48:57 tdeval Exp $"; #endif /* not lint */ /* This file collects some Unix dependencies; hack.pager.c contains some more */ @@ -169,29 +169,32 @@ gethdate(name) char *name; { */ #define MAXPATHLEN 1024 -register char *np, *path; + +char *p, *np, *path; char filename[MAXPATHLEN+1]; - if (strchr(name, '/') != NULL || (path = getenv("PATH")) == NULL) - path = ""; + if (strchr(name, '/') != NULL || (p = getenv("PATH")) == NULL) + p = ""; + np = path = strdup(p); /* Make a copy for strsep. */ + if (path == NULL) + err(1, NULL); for (;;) { - if ((np = strchr(path, ':')) == NULL) - np = path + strlen(path); /* point to end str */ - if (np - path <= 1) /* %% */ + if ((p = strsep(&np, ":")) == NULL) + break; + if (*p == '\0') /* :: */ (void) strlcpy(filename, name, sizeof filename); - else { - (void) strncpy(filename, path, np - path); - filename[np - path] = '/'; - (void) strcpy(filename + (np - path) + 1, name); - } - if (stat(filename, &hbuf) == 0) + else + (void) snprintf(filename, sizeof filename, + "%s/%s", p, name); + + if (stat(filename, &hbuf) == 0) { + free(path); return; - if (*np == '\0') - break; - path = np + 1; + } } error("Cannot get status of %s.", - (np = strrchr(name, '/')) ? np+1 : name); + (p = strrchr(name, '/')) ? p+1 : name); + free(path); } uptodate(fd) { diff --git a/games/hack/hack.zap.c b/games/hack/hack.zap.c index 62d76a342c8..d75892ff387 100644 --- a/games/hack/hack.zap.c +++ b/games/hack/hack.zap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hack.zap.c,v 1.5 2003/03/16 21:22:36 camield Exp $ */ +/* $OpenBSD: hack.zap.c,v 1.6 2003/05/07 09:48:57 tdeval Exp $ */ /* * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica, @@ -62,7 +62,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: hack.zap.c,v 1.5 2003/03/16 21:22:36 camield Exp $"; +static char rcsid[] = "$OpenBSD: hack.zap.c,v 1.6 2003/05/07 09:48:57 tdeval Exp $"; #endif /* not lint */ #include "hack.h" @@ -235,7 +235,7 @@ dozap() pline("You may wish for an object. What do you want? "); getlin(buf); if(buf[0] == '\033') buf[0] = 0; - otmp = readobjnam(buf); + otmp = readobjnam(buf, sizeof buf); otmp = addinv(otmp); prinv(otmp); break; |