diff options
-rw-r--r-- | usr.bin/vi/cl/cl_bsd.c | 4 | ||||
-rw-r--r-- | usr.bin/vi/common/main.c | 17 | ||||
-rw-r--r-- | usr.bin/vi/common/msg.c | 14 | ||||
-rw-r--r-- | usr.bin/vi/ex/ex_script.c | 29 |
4 files changed, 35 insertions, 29 deletions
diff --git a/usr.bin/vi/cl/cl_bsd.c b/usr.bin/vi/cl/cl_bsd.c index 73d9e2dd486..cdf22ce1eb0 100644 --- a/usr.bin/vi/cl/cl_bsd.c +++ b/usr.bin/vi/cl/cl_bsd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cl_bsd.c,v 1.7 2002/02/16 21:27:56 millert Exp $ */ +/* $OpenBSD: cl_bsd.c,v 1.8 2003/04/17 02:22:56 itojun Exp $ */ /*- * Copyright (c) 1995, 1996 @@ -317,7 +317,7 @@ tigetstr(name) p = sbuf; #ifdef _AIX - return ((p = tgetstr(name, &p)) == NULL ? (char *)-1 : strcpy(sbuf, p)); + return ((p = tgetstr(name, &p)) == NULL ? (char *)-1 : (strlcpy(sbuf, p, sizeof(sbuf)), sbuf)); #else return (tgetstr(name, &p) == NULL ? (char *)-1 : sbuf); #endif diff --git a/usr.bin/vi/common/main.c b/usr.bin/vi/common/main.c index a54d97c2a61..aa81444c60f 100644 --- a/usr.bin/vi/common/main.c +++ b/usr.bin/vi/common/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.9 2002/06/12 06:07:16 mpech Exp $ */ +/* $OpenBSD: main.c,v 1.10 2003/04/17 02:22:56 itojun Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 @@ -343,14 +343,15 @@ editor(gp, argc, argv) */ if (*argv != NULL) { if (sp->frp != NULL) { + size_t l; /* Cheat -- we know we have an extra argv slot. */ - MALLOC_NOMSG(sp, - *--argv, char *, strlen(sp->frp->name) + 1); + l = strlen(sp->frp->name) + 1; + MALLOC_NOMSG(sp, *--argv, char *, l); if (*argv == NULL) { v_estr(gp->progname, errno, NULL); goto err; } - (void)strcpy(*argv, sp->frp->name); + (void)strlcpy(*argv, sp->frp->name, l); } sp->argv = sp->cargv = argv; F_SET(sp, SC_ARGNOFREE); @@ -548,10 +549,9 @@ v_obsolete(name, argv) while (*++argv && strcmp(argv[0], "--")) if (argv[0][0] == '+') { if (argv[0][1] == '\0') { - MALLOC_NOMSG(NULL, argv[0], char *, 4); + argv[0] = strdup("-c$"); if (argv[0] == NULL) goto nomem; - (void)strcpy(argv[0], "-c$"); } else { p = argv[0]; len = strlen(argv[0]); @@ -560,16 +560,15 @@ v_obsolete(name, argv) goto nomem; argv[0][0] = '-'; argv[0][1] = 'c'; - (void)strcpy(argv[0] + 2, p + 1); + (void)strlcpy(argv[0] + 2, p + 1, len); } } else if (argv[0][0] == '-') if (argv[0][1] == '\0') { - MALLOC_NOMSG(NULL, argv[0], char *, 3); + argv[0] = strdup("-s"); if (argv[0] == NULL) { nomem: v_estr(name, errno, NULL); return (1); } - (void)strcpy(argv[0], "-s"); } else if ((argv[0][1] == 'c' || argv[0][1] == 'T' || argv[0][1] == 't' || argv[0][1] == 'w') && diff --git a/usr.bin/vi/common/msg.c b/usr.bin/vi/common/msg.c index bae7bdbc85b..14e54df71fe 100644 --- a/usr.bin/vi/common/msg.c +++ b/usr.bin/vi/common/msg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: msg.c,v 1.11 2002/06/12 06:07:16 mpech Exp $ */ +/* $OpenBSD: msg.c,v 1.12 2003/04/17 02:22:56 itojun Exp $ */ /*- * Copyright (c) 1991, 1993, 1994 @@ -506,12 +506,13 @@ msgq_status(sp, lno, flags) size_t blen, len; int cnt, needsep; const char *t; - char **ap, *bp, *np, *p, *s; + char **ap, *bp, *np, *p, *s, *ep; /* Get sufficient memory. */ len = strlen(sp->frp->name); GET_SPACE_GOTO(sp, bp, blen, len * MAX_CHARACTER_COLUMNS + 128); p = bp; + ep = bp + blen; /* Copy in the filename. */ for (p = bp, t = sp->frp->name; *t != '\0'; ++t) { @@ -527,7 +528,7 @@ msgq_status(sp, lno, flags) if (F_ISSET(sp, SC_STATUS_CNT) && sp->argv != NULL) { for (cnt = 0, ap = sp->argv; *ap != NULL; ++ap, ++cnt); if (cnt > 1) { - (void)sprintf(p, + (void)snprintf(p, ep - p, msg_cat(sp, "317|%d files to edit", NULL), cnt); p += strlen(p); *p++ = ':'; @@ -602,16 +603,17 @@ msgq_status(sp, lno, flags) p += len; } else { t = msg_cat(sp, "027|line %lu of %lu [%ld%%]", &len); - (void)sprintf(p, t, lno, last, (lno * 100) / last); + (void)snprintf(p, ep - p, t, lno, last, + (lno * 100) / last); p += strlen(p); } } else { t = msg_cat(sp, "029|line %lu", &len); - (void)sprintf(p, t, lno); + (void)snprintf(p, ep - p, t, lno); p += strlen(p); } #ifdef DEBUG - (void)sprintf(p, " (pid %ld)", (long)getpid()); + (void)snprintf(p, ep - p, " (pid %ld)", (long)getpid()); p += strlen(p); #endif *p++ = '\n'; diff --git a/usr.bin/vi/ex/ex_script.c b/usr.bin/vi/ex/ex_script.c index 6d8a11813f7..d1068448177 100644 --- a/usr.bin/vi/ex/ex_script.c +++ b/usr.bin/vi/ex/ex_script.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ex_script.c,v 1.9 2002/06/12 06:07:17 mpech Exp $ */ +/* $OpenBSD: ex_script.c,v 1.10 2003/04/17 02:22:56 itojun Exp $ */ /*- * Copyright (c) 1992, 1993, 1994 @@ -52,7 +52,7 @@ static int sscr_getprompt(SCR *); static int sscr_init(SCR *); static int sscr_insert(SCR *); static int sscr_matchprompt(SCR *, char *, size_t, size_t *); -static int sscr_pty(int *, int *, char *, struct termios *, void *); +static int sscr_pty(int *, int *, char *, size_t, struct termios *, void *); static int sscr_setprompt(SCR *, char *, size_t); /* @@ -128,13 +128,15 @@ sscr_init(sp) } if (sscr_pty(&sc->sh_master, - &sc->sh_slave, sc->sh_name, &sc->sh_term, &sc->sh_win) == -1) { + &sc->sh_slave, sc->sh_name, sizeof(sc->sh_name), + &sc->sh_term, &sc->sh_win) == -1) { msgq(sp, M_SYSERR, "pty"); goto err; } #else if (sscr_pty(&sc->sh_master, - &sc->sh_slave, sc->sh_name, &sc->sh_term, NULL) == -1) { + &sc->sh_slave, sc->sh_name, sizeof(sc->sh_name), + &sc->sh_term, NULL) == -1) { msgq(sp, M_SYSERR, "pty"); goto err; } @@ -630,19 +632,20 @@ sscr_check(sp) #ifdef HAVE_SYS5_PTY static int ptys_open(int, char *); -static int ptym_open(char *); +static int ptym_open(char *, size_t); static int -sscr_pty(amaster, aslave, name, termp, winp) +sscr_pty(amaster, aslave, name, namelen, termp, winp) int *amaster, *aslave; char *name; + size_t namelen; struct termios *termp; void *winp; { int master, slave, ttygid; /* open master terminal */ - if ((master = ptym_open(name)) < 0) { + if ((master = ptym_open(name, namelen)) < 0) { errno = ENOENT; /* out of ptys */ return (-1); } @@ -671,13 +674,14 @@ sscr_pty(amaster, aslave, name, termp, winp) * to it. pts_name is also returned which is the name of the slave. */ static int -ptym_open(pts_name) +ptym_open(pts_name, pts_namelen) char *pts_name; + size_t pts_namelen; { int fdm; char *ptr, *ptsname(); - strcpy(pts_name, _PATH_SYSV_PTY); + strlcpy(pts_name, _PATH_SYSV_PTY, pts_namelen); if ((fdm = open(pts_name, O_RDWR)) < 0 ) return (-1); @@ -701,7 +705,7 @@ ptym_open(pts_name) close(fdm); return (-3); } - strcpy(pts_name, ptr); + strlcpy(pts_name, ptr, pts_namelen); return (fdm); } @@ -745,9 +749,10 @@ ptys_open(fdm, pts_name) #else /* !HAVE_SYS5_PTY */ static int -sscr_pty(amaster, aslave, name, termp, winp) +sscr_pty(amaster, aslave, name, namelen, termp, winp) int *amaster, *aslave; char *name; + size_t namelen; struct termios *termp; void *winp; { @@ -780,7 +785,7 @@ sscr_pty(amaster, aslave, name, termp, winp) *amaster = master; *aslave = slave; if (name) - strcpy(name, line); + strlcpy(name, line, namelen); if (termp) (void) tcsetattr(slave, TCSAFLUSH, termp); |