Browse Source

use strlcpy vs strncpy+a[len-1]='\0'. millert@ ok.

OPENBSD_3_0
lebel 23 years ago
parent
commit
60ef74bf70
4 changed files with 13 additions and 19 deletions
  1. +3
    -4
      src/lib/libc/crypt/crypt.c
  2. +2
    -3
      src/lib/libc/stdlib/realpath.c
  3. +4
    -6
      src/lib/libc/string/__strerror.c
  4. +4
    -6
      src/lib/libc/string/__strsignal.c

+ 3
- 4
src/lib/libc/crypt/crypt.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: crypt.c,v 1.13 1998/03/22 19:01:18 niklas Exp $ */
/* $OpenBSD: crypt.c,v 1.14 2001/06/27 00:58:53 lebel Exp $ */
/*
* FreeSec: libcrypt
@ -52,7 +52,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char rcsid[] = "$OpenBSD: crypt.c,v 1.13 1998/03/22 19:01:18 niklas Exp $";
static char rcsid[] = "$OpenBSD: crypt.c,v 1.14 2001/06/27 00:58:53 lebel Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@ -650,7 +650,7 @@ crypt(key, setting)
if (des_setkey((u_char *) keybuf))
return(NULL);
}
strncpy((char *)output, setting, 9);
strlcpy((char *)output, setting, 10);
/*
* Double check that we weren't given a short setting.
@ -659,7 +659,6 @@ crypt(key, setting)
* Just make sure the output string doesn't have an extra
* NUL in it.
*/
output[9] = '\0';
p = output + strlen((const char *)output);
} else {
/*


+ 2
- 3
src/lib/libc/stdlib/realpath.c View File

@ -35,7 +35,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char *rcsid = "$OpenBSD: realpath.c,v 1.4 1998/05/18 09:55:19 deraadt Exp $";
static char *rcsid = "$OpenBSD: realpath.c,v 1.5 2001/06/27 00:58:56 lebel Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
@ -78,8 +78,7 @@ realpath(path, resolved)
* if it is a directory, then change to that directory.
* get the current directory name and append the basename.
*/
(void)strncpy(resolved, path, MAXPATHLEN - 1);
resolved[MAXPATHLEN - 1] = '\0';
strlcpy(resolved, path, MAXPATHLEN);
loop:
q = strrchr(resolved, '/');
if (q != NULL) {


+ 4
- 6
src/lib/libc/string/__strerror.c View File

@ -32,7 +32,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char *rcsid = "$OpenBSD: __strerror.c,v 1.6 1996/09/25 08:17:30 deraadt Exp $";
static char *rcsid = "$OpenBSD: __strerror.c,v 1.7 2001/06/27 00:58:56 lebel Exp $";
#endif /* LIBC_SCCS and not lint */
#ifdef NLS
@ -87,16 +87,14 @@ __strerror(num, buf)
errnum = num; /* convert to unsigned */
if (errnum < sys_nerr) {
#ifdef NLS
strncpy(buf, catgets(catd, 1, errnum,
(char *)sys_errlist[errnum]), NL_TEXTMAX-1);
buf[NL_TEXTMAX - 1] = '\0';
strlcpy(buf, catgets(catd, 1, errnum,
(char *)sys_errlist[errnum]), NL_TEXTMAX);
#else
return(sys_errlist[errnum]);
#endif
} else {
#ifdef NLS
strncpy(buf, catgets(catd, 1, 0xffff, UPREFIX), NL_TEXTMAX-1);
buf[NL_TEXTMAX - 1] = '\0';
strlcpy(buf, catgets(catd, 1, 0xffff, UPREFIX), NL_TEXTMAX);
#else
strcpy(buf, UPREFIX);
#endif


+ 4
- 6
src/lib/libc/string/__strsignal.c View File

@ -32,7 +32,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char *rcsid = "$OpenBSD: __strsignal.c,v 1.5 1996/09/25 13:19:01 deraadt Exp $";
static char *rcsid = "$OpenBSD: __strsignal.c,v 1.6 2001/06/27 00:58:56 lebel Exp $";
#endif /* LIBC_SCCS and not lint */
#ifdef NLS
@ -80,16 +80,14 @@ __strsignal(num, buf)
signum = num; /* convert to unsigned */
if (signum < NSIG) {
#ifdef NLS
strncpy(buf, catgets(catd, 2, signum,
(char *)sys_siglist[signum]), NL_TEXTMAX-1);
buf[NL_TEXTMAX-1] = '\0';
strlcpy(buf, catgets(catd, 2, signum,
(char *)sys_siglist[signum]), NL_TEXTMAX);
#else
return((char *)sys_siglist[signum]);
#endif
} else {
#ifdef NLS
strncpy(buf, catgets(catd, 1, 0xffff, UPREFIX), NL_TEXTMAX-1);
buf[NL_TEXTMAX-1] = '\0';
strlcpy(buf, catgets(catd, 1, 0xffff, UPREFIX), NL_TEXTMAX);
#else
strcpy(buf, UPREFIX);
#endif


Loading…
Cancel
Save