summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>1998-06-23 22:40:56 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>1998-06-23 22:40:56 +0000
commit30cb72a00b8cc59895c391cad0f8e31611611ec4 (patch)
tree3e2f67dd80af3489363cf0596b740c6533994e40 /usr.bin
parent325437057bbda9490b174c8fc6dc8f0e14a8f145 (diff)
Fix snprintf return value usage.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/netstat/atalk.c17
-rw-r--r--usr.bin/netstat/route.c28
-rw-r--r--usr.bin/sed/main.c6
-rw-r--r--usr.bin/vi/cl/cl_term.c2
-rw-r--r--usr.bin/vi/common/api.c6
-rw-r--r--usr.bin/vi/common/exf.c6
-rw-r--r--usr.bin/vi/ex/ex_tag.c3
-rw-r--r--usr.bin/vi/ex/ex_visual.c2
-rw-r--r--usr.bin/vi/vi/v_at.c2
-rw-r--r--usr.bin/vi/vi/v_increment.c4
-rw-r--r--usr.bin/vi/vi/v_search.c4
-rw-r--r--usr.bin/vi/vi/vs_line.c4
12 files changed, 68 insertions, 16 deletions
diff --git a/usr.bin/netstat/atalk.c b/usr.bin/netstat/atalk.c
index f6b33c45fb1..d57aa91b3bf 100644
--- a/usr.bin/netstat/atalk.c
+++ b/usr.bin/netstat/atalk.c
@@ -219,7 +219,7 @@ atalk_print2(sa, mask, what)
const struct sockaddr *mask;
int what;
{
- int n;
+ size_t n, l;
static char buf[100];
struct sockaddr_at *sat1, *sat2;
struct sockaddr_at thesockaddr;
@@ -232,15 +232,24 @@ atalk_print2(sa, mask, what)
thesockaddr.sat_addr.s_net = sat1->sat_addr.s_net &
sat2->sat_addr.s_net;
n = snprintf(buf, sizeof(buf), "%s", atalk_print(sa2, 1 | (what & 8)));
+ if (n >= sizeof(buf))
+ n = sizeof(buf) - 1;
if (sat2->sat_addr.s_net != 0xFFFF) {
thesockaddr.sat_addr.s_net = sat1->sat_addr.s_net |
~sat2->sat_addr.s_net;
- n += snprintf(buf + n, sizeof(buf) - n,
+ l = snprintf(buf + n, sizeof(buf) - n,
"-%s", atalk_print(sa2, 1 | (what & 8)));
+ if (l >= sizeof(buf) - n)
+ l = sizeof(buf) - n - 1;
+ n += l;
}
- if (what & 2)
- n += snprintf(buf + n, sizeof(buf) - n, ".%s",
+ if (what & 2) {
+ l = snprintf(buf + n, sizeof(buf) - n, ".%s",
atalk_print(sa, what & (~1)));
+ if (l >= sizeof(buf) - n)
+ l = sizeof(buf) - n - 1;
+ n += l;
+ }
return (buf);
}
diff --git a/usr.bin/netstat/route.c b/usr.bin/netstat/route.c
index 950e9d4c111..ced59780a73 100644
--- a/usr.bin/netstat/route.c
+++ b/usr.bin/netstat/route.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: route.c,v 1.24 1998/05/18 19:03:29 deraadt Exp $ */
+/* $OpenBSD: route.c,v 1.25 1998/06/23 22:40:40 millert Exp $ */
/* $NetBSD: route.c,v 1.15 1996/05/07 02:55:06 thorpej Exp $ */
/*
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "from: @(#)route.c 8.3 (Berkeley) 3/9/94";
#else
-static char *rcsid = "$OpenBSD: route.c,v 1.24 1998/05/18 19:03:29 deraadt Exp $";
+static char *rcsid = "$OpenBSD: route.c,v 1.25 1998/06/23 22:40:40 millert Exp $";
#endif
#endif /* not lint */
@@ -404,6 +404,7 @@ p_sockaddr(sa, mask, flags, width)
{
char workbuf[128], *cplim;
register char *cp = workbuf;
+ size_t n;
switch(sa->sa_family) {
case AF_INET:
@@ -444,9 +445,12 @@ p_sockaddr(sa, mask, flags, width)
cplim = "";
for (i = 0; i < sdl->sdl_alen; i++, lla++) {
- cp += snprintf(cp,
+ n = snprintf(cp,
workbuf + sizeof (workbuf) - cp,
"%s%x", cplim, *lla);
+ if (n >= workbuf + sizeof (workbuf) - cp)
+ n = workbuf + sizeof (workbuf) - cp - 1;
+ cp += n;
cplim = ":";
}
cp = workbuf;
@@ -471,14 +475,24 @@ p_sockaddr(sa, mask, flags, width)
slim = sa->sa_len + (u_char *) sa;
cplim = cp + sizeof(workbuf) - 6;
- cp += snprintf(cp, cplim - cp, "(%d)", sa->sa_family);
+ n = snprintf(cp, cplim - cp, "(%d)", sa->sa_family);
+ if (n >= cplim - cp)
+ n = cplim - cp - 1;
+ cp += n;
while (s < slim && cp < cplim) {
- cp += snprintf(cp, workbuf + sizeof (workbuf) - cp,
+ n = snprintf(cp, workbuf + sizeof (workbuf) - cp,
" %02x", *s++);
- if (s < slim)
- cp += snprintf(cp,
+ if (n >= workbuf + sizeof (workbuf) - cp)
+ n = workbuf + sizeof (workbuf) - cp - 1;
+ cp += n;
+ if (s < slim) {
+ n = snprintf(cp,
workbuf + sizeof (workbuf) - cp,
"%02x", *s++);
+ if (n >= workbuf + sizeof (workbuf) - cp)
+ n = workbuf + sizeof (workbuf) - cp - 1;
+ cp += n;
+ }
}
cp = workbuf;
}
diff --git a/usr.bin/sed/main.c b/usr.bin/sed/main.c
index f365409959f..757ef476cf8 100644
--- a/usr.bin/sed/main.c
+++ b/usr.bin/sed/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.4 1997/01/15 23:43:12 millert Exp $ */
+/* $OpenBSD: main.c,v 1.5 1998/06/23 22:40:42 millert Exp $ */
/*-
* Copyright (c) 1992 Diomidis Spinellis.
@@ -45,7 +45,7 @@ static char copyright[] =
#ifndef lint
/* from: static char sccsid[] = "@(#)main.c 8.2 (Berkeley) 1/3/94"; */
-static char *rcsid = "$OpenBSD: main.c,v 1.4 1997/01/15 23:43:12 millert Exp $";
+static char *rcsid = "$OpenBSD: main.c,v 1.5 1998/06/23 22:40:42 millert Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -191,7 +191,7 @@ again:
case CU_STRING:
if ((snprintf(string_ident,
sizeof(string_ident), "\"%s\"", script->s)) >=
- sizeof(string_ident) - 1)
+ sizeof(string_ident))
(void)strcpy(string_ident +
sizeof(string_ident) - 6, " ...\"");
fname = string_ident;
diff --git a/usr.bin/vi/cl/cl_term.c b/usr.bin/vi/cl/cl_term.c
index 6edaffb0bf4..a86b9924b00 100644
--- a/usr.bin/vi/cl/cl_term.c
+++ b/usr.bin/vi/cl/cl_term.c
@@ -221,6 +221,8 @@ cl_pfmap(sp, stype, from, flen, to, tlen)
nlen = snprintf(keyname,
sizeof(keyname), "function key %d", atoi(from + 1));
+ if (nlen >= sizeof(keyname))
+ nlen = sizeof(keyname) - 1;
return (seq_set(sp, keyname, nlen,
p, strlen(p), to, tlen, stype, SEQ_NOOVERWRITE | SEQ_SCREEN));
}
diff --git a/usr.bin/vi/common/api.c b/usr.bin/vi/common/api.c
index 35d9f0c8f66..aac0ac627b3 100644
--- a/usr.bin/vi/common/api.c
+++ b/usr.bin/vi/common/api.c
@@ -488,14 +488,20 @@ api_opts_set(sp, name, str_value, num_value, bool_value)
case OPT_1BOOL:
GET_SPACE_RET(sp, bp, blen, 64);
a.len = snprintf(bp, 64, "%s%s", bool_value ? "" : "no", name);
+ if (a.len > 63)
+ a.len = 63;
break;
case OPT_NUM:
GET_SPACE_RET(sp, bp, blen, 64);
a.len = snprintf(bp, 64, "%s=%lu", name, num_value);
+ if (a.len > 63)
+ a.len = 63;
break;
case OPT_STR:
GET_SPACE_RET(sp, bp, blen, 1024);
a.len = snprintf(bp, 1024, "%s=%s", name, str_value);
+ if (a.len > 63)
+ a.len = 63;
break;
}
a.bp = bp;
diff --git a/usr.bin/vi/common/exf.c b/usr.bin/vi/common/exf.c
index 39c781a3f7d..574a16aab3b 100644
--- a/usr.bin/vi/common/exf.c
+++ b/usr.bin/vi/common/exf.c
@@ -482,6 +482,8 @@ file_spath(sp, frp, sbp, existsp)
*p = '\0';
len = snprintf(path,
sizeof(path), "%s/%s", t, name);
+ if (len >= sizeof(path))
+ len = sizeof(path) - 1;
*p = savech;
if (!stat(path, sbp)) {
found = 1;
@@ -941,12 +943,16 @@ file_write(sp, fm, tm, name, flags)
msgstr = msg_cat(sp,
"256|%s: new file: %lu lines, %lu characters", NULL);
len = snprintf(buf, sizeof(buf), msgstr, p, nlno, nch);
+ if (len >= sizeof(buf))
+ len = sizeof(buf) - 1;
break;
case OLDFILE:
msgstr = msg_cat(sp, LF_ISSET(FS_APPEND) ?
"315|%s: appended: %lu lines, %lu characters" :
"257|%s: %lu lines, %lu characters", NULL);
len = snprintf(buf, sizeof(buf), msgstr, p, nlno, nch);
+ if (len >= sizeof(buf))
+ len = sizeof(buf) - 1;
break;
default:
abort();
diff --git a/usr.bin/vi/ex/ex_tag.c b/usr.bin/vi/ex/ex_tag.c
index 63d80626a41..15aa58f4cc8 100644
--- a/usr.bin/vi/ex/ex_tag.c
+++ b/usr.bin/vi/ex/ex_tag.c
@@ -1181,7 +1181,6 @@ ctag_file(sp, tfp, name, dirp, dlenp)
size_t *dlenp;
{
struct stat sb;
- size_t len;
char *p, buf[MAXPATHLEN];
/*
@@ -1196,7 +1195,7 @@ ctag_file(sp, tfp, name, dirp, dlenp)
if (name[0] != '/' &&
stat(name, &sb) && (p = strrchr(tfp->name, '/')) != NULL) {
*p = '\0';
- len = snprintf(buf, sizeof(buf), "%s/%s", tfp->name, name);
+ (void)snprintf(buf, sizeof(buf), "%s/%s", tfp->name, name);
if (stat(buf, &sb) == 0) {
*dirp = tfp->name;
*dlenp = strlen(*dirp);
diff --git a/usr.bin/vi/ex/ex_visual.c b/usr.bin/vi/ex/ex_visual.c
index 82e503d4465..c181f7709f4 100644
--- a/usr.bin/vi/ex/ex_visual.c
+++ b/usr.bin/vi/ex/ex_visual.c
@@ -84,6 +84,8 @@ ex_visual(sp, cmdp)
"%luz%c%lu", sp->lno, pos, cmdp->count);
else
len = snprintf(buf, sizeof(buf), "%luz%c", sp->lno, pos);
+ if (len >= sizeof(buf))
+ len = sizeof(buf) - 1;
(void)v_event_push(sp, NULL, buf, len, CH_NOMAP | CH_QUOTED);
/*
diff --git a/usr.bin/vi/vi/v_at.c b/usr.bin/vi/vi/v_at.c
index d266f275d98..7231bb1b674 100644
--- a/usr.bin/vi/vi/v_at.c
+++ b/usr.bin/vi/vi/v_at.c
@@ -102,6 +102,8 @@ v_at(sp, vp)
*/
if (F_ISSET(vp, VC_C1SET)) {
len = snprintf(nbuf, sizeof(nbuf), "%lu", vp->count);
+ if (len >= sizeof(nbuf))
+ len = sizeof(nbuf) - 1;
if (v_event_push(sp, NULL, nbuf, len, 0))
return (1);
}
diff --git a/usr.bin/vi/vi/v_increment.c b/usr.bin/vi/vi/v_increment.c
index 45e763fa5bd..370143187c6 100644
--- a/usr.bin/vi/vi/v_increment.c
+++ b/usr.bin/vi/vi/v_increment.c
@@ -204,6 +204,8 @@ nonum: msgq(sp, M_ERR, "181|Cursor not in a number");
if (lval == 0 && ntype == fmt[SDEC])
ntype = fmt[DEC];
nlen = snprintf(nbuf, sizeof(nbuf), ntype, lval);
+ if (nlen >= sizeof(nbuf))
+ nlen = sizeof(nbuf) - 1;
} else {
if ((nret = nget_uslong(&ulval, t, NULL, base)) != NUM_OK)
goto err;
@@ -226,6 +228,8 @@ nonum: msgq(sp, M_ERR, "181|Cursor not in a number");
wlen -= 2;
nlen = snprintf(nbuf, sizeof(nbuf), ntype, wlen, ulval);
+ if (nlen >= sizeof(nbuf))
+ nlen = sizeof(nbuf) - 1;
}
/* Build the new line. */
diff --git a/usr.bin/vi/vi/v_search.c b/usr.bin/vi/vi/v_search.c
index 4f7a2671ab8..6851a93fa5b 100644
--- a/usr.bin/vi/vi/v_search.c
+++ b/usr.bin/vi/vi/v_search.c
@@ -255,6 +255,8 @@ v_exaddr(sp, vp, dir)
/* Push line number so get correct z display. */
tlen = snprintf(buf,
sizeof(buf), "%lu", (u_long)vp->m_stop.lno);
+ if (tlen >= sizeof(buf))
+ tlen = sizeof(buf) - 1;
if (v_event_push(sp, NULL, buf, tlen, CH_NOMAP | CH_QUOTED))
return (1);
@@ -336,6 +338,8 @@ v_searchw(sp, vp)
len = VIP(sp)->klen + sizeof(RE_WSTART) + sizeof(RE_WSTOP);
GET_SPACE_RET(sp, bp, blen, len);
len = snprintf(bp, blen, "%s%s%s", RE_WSTART, VIP(sp)->keyw, RE_WSTOP);
+ if (len >= blen)
+ len = blen - 1;
rval = v_search(sp, vp, bp, len, SEARCH_SET, FORWARD);
diff --git a/usr.bin/vi/vi/vs_line.c b/usr.bin/vi/vi/vs_line.c
index b439de925ce..a8a65c0d3ca 100644
--- a/usr.bin/vi/vi/vs_line.c
+++ b/usr.bin/vi/vi/vs_line.c
@@ -140,6 +140,8 @@ vs_line(sp, smp, yp, xp)
if ((!dne || smp->lno == 1) && skip_cols == 0) {
nlen = snprintf(cbuf,
sizeof(cbuf), O_NUMBER_FMT, smp->lno);
+ if (nlen >= sizeof(cbuf))
+ nlen = sizeof(cbuf) - 1;
(void)gp->scr_addstr(sp, cbuf, nlen);
}
}
@@ -507,6 +509,8 @@ vs_number(sp)
(void)gp->scr_move(sp, smp - HMAP, 0);
len = snprintf(nbuf, sizeof(nbuf), O_NUMBER_FMT, smp->lno);
+ if (len >= sizeof(nbuf))
+ len = sizeof(nbuf) - 1;
(void)gp->scr_addstr(sp, nbuf, len);
}
(void)gp->scr_move(sp, oldy, oldx);