diff options
Diffstat (limited to 'usr.bin/less')
-rw-r--r-- | usr.bin/less/charset.c | 10 | ||||
-rw-r--r-- | usr.bin/less/filename.c | 20 | ||||
-rw-r--r-- | usr.bin/less/option.c | 4 | ||||
-rw-r--r-- | usr.bin/less/os.c | 10 |
4 files changed, 23 insertions, 21 deletions
diff --git a/usr.bin/less/charset.c b/usr.bin/less/charset.c index 04b4f83ed4a..979435e283b 100644 --- a/usr.bin/less/charset.c +++ b/usr.bin/less/charset.c @@ -1,4 +1,4 @@ -/* $OpenBSD: charset.c,v 1.3 2001/11/19 19:02:14 mpech Exp $ */ +/* $OpenBSD: charset.c,v 1.4 2003/03/13 09:09:32 deraadt Exp $ */ /* * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman @@ -278,12 +278,12 @@ prchar(c) c &= 0377; if (!control_char(c)) - sprintf(buf, "%c", c); + snprintf(buf, sizeof buf, "%c", c); else if (c == ESC) - sprintf(buf, "ESC"); + snprintf(buf, sizeof buf, "ESC"); else if (c < 128 && !control_char(c ^ 0100)) - sprintf(buf, "^%c", c ^ 0100); + snprintf(buf, sizeof buf, "^%c", c ^ 0100); else - sprintf(buf, binfmt, c); + snprintf(buf, sizeof buf, binfmt, c); return (buf); } diff --git a/usr.bin/less/filename.c b/usr.bin/less/filename.c index 28bacff3278..71dc429e756 100644 --- a/usr.bin/less/filename.c +++ b/usr.bin/less/filename.c @@ -1,4 +1,4 @@ -/* $OpenBSD: filename.c,v 1.3 2001/11/19 19:02:14 mpech Exp $ */ +/* $OpenBSD: filename.c,v 1.4 2003/03/13 09:09:32 deraadt Exp $ */ /* * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman @@ -51,21 +51,21 @@ dirfile(dirname, filename) char *filename; { char *pathname; - int f; + int f, len; if (dirname == NULL || *dirname == '\0') return (NULL); /* * Construct the full pathname. */ - pathname = (char *) calloc(strlen(dirname) + strlen(filename) + 2, - sizeof(char)); + len = strlen(dirname) + strlen(filename) + 2; + pathname = (char *) calloc(len, sizeof(char)); if (pathname == NULL) return (NULL); #if MSOFTC || OS2 sprintf(pathname, "%s\\%s", dirname, filename); #else - sprintf(pathname, "%s/%s", dirname, filename); + snprintf(pathname, len, "%s/%s", dirname, filename); #endif /* * Make sure the file exists. @@ -239,7 +239,7 @@ fcomplete(s) sprintf(fpat, "%s*", s); #else fpat = (char *) ecalloc(strlen(s)+2, sizeof(char)); - sprintf(fpat, "%s*", s); + snprintf(fpat, strlen(s)+2, "%s*", s); #endif s = glob(fpat); if (strcmp(s,fpat) == 0) @@ -360,7 +360,7 @@ shellcmd(cmd, s1, s2) (s1 == NULL ? 0 : strlen(s1)) + (s2 == NULL ? 0 : strlen(s2)) + 1; scmd = (char *) ecalloc(len, sizeof(char)); - sprintf(scmd, cmd, s1, s2); + snprintf(scmd, len, cmd, s1, s2); #if HAVE_SHELL shell = getenv("SHELL"); if (shell != NULL && *shell != '\0') @@ -368,9 +368,9 @@ shellcmd(cmd, s1, s2) /* * Read the output of <$SHELL -c "cmd">. */ - scmd2 = (char *) ecalloc(strlen(shell) + strlen(scmd) + 7, - sizeof(char)); - sprintf(scmd2, "%s -c \"%s\"", shell, scmd); + len = strlen(shell) + strlen(scmd) + 7; + scmd2 = (char *) ecalloc(len, sizeof(char)); + snprintf(scmd2, len, "%s -c \"%s\"", shell, scmd); free(scmd); scmd = scmd2; } diff --git a/usr.bin/less/option.c b/usr.bin/less/option.c index ad44cb60af6..694c2baac70 100644 --- a/usr.bin/less/option.c +++ b/usr.bin/less/option.c @@ -1,4 +1,4 @@ -/* $OpenBSD: option.c,v 1.3 2001/11/19 19:02:14 mpech Exp $ */ +/* $OpenBSD: option.c,v 1.4 2003/03/13 09:09:32 deraadt Exp $ */ /* * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman @@ -408,7 +408,7 @@ propt(c) { static char buf[8]; - sprintf(buf, "-%s", prchar(c)); + snprintf(buf, sizeof buf, "-%s", prchar(c)); return (buf); } diff --git a/usr.bin/less/os.c b/usr.bin/less/os.c index 27953952806..c4235f81979 100644 --- a/usr.bin/less/os.c +++ b/usr.bin/less/os.c @@ -1,4 +1,4 @@ -/* $OpenBSD: os.c,v 1.4 2001/11/19 19:02:14 mpech Exp $ */ +/* $OpenBSD: os.c,v 1.5 2003/03/13 09:09:32 deraadt Exp $ */ /* * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman @@ -162,7 +162,7 @@ strerror(err) if (err < sys_nerr) return sys_errlist[err]; - sprintf(buf, "Error %d", err); + snprintf(buf, sizeof buf, "Error %d", err); return buf; #else return ("cannot open"); @@ -179,14 +179,16 @@ errno_message(filename) { char *p; char *m; + int len; #if HAVE_ERRNO extern int errno; p = strerror(errno); #else p = "cannot open"; #endif - m = (char *) ecalloc(strlen(filename) + strlen(p) + 3, sizeof(char)); - sprintf(m, "%s: %s", filename, p); + len = strlen(filename) + strlen(p) + 3; + m = (char *) ecalloc(len, sizeof(char)); + snprintf(m, len, "%s: %s", filename, p); return (m); } |