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 * FreeSec: libcrypt
@ -52,7 +52,7 @@
*/ */
#if defined(LIBC_SCCS) && !defined(lint) #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 */ #endif /* LIBC_SCCS and not lint */
#include <sys/types.h> #include <sys/types.h>
@ -650,7 +650,7 @@ crypt(key, setting)
if (des_setkey((u_char *) keybuf)) if (des_setkey((u_char *) keybuf))
return(NULL); return(NULL);
} }
strncpy((char *)output, setting, 9);
strlcpy((char *)output, setting, 10);
/* /*
* Double check that we weren't given a short setting. * 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 * Just make sure the output string doesn't have an extra
* NUL in it. * NUL in it.
*/ */
output[9] = '\0';
p = output + strlen((const char *)output); p = output + strlen((const char *)output);
} else { } else {
/* /*


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

@ -35,7 +35,7 @@
*/ */
#if defined(LIBC_SCCS) && !defined(lint) #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 */ #endif /* LIBC_SCCS and not lint */
#include <sys/param.h> #include <sys/param.h>
@ -78,8 +78,7 @@ realpath(path, resolved)
* if it is a directory, then change to that directory. * if it is a directory, then change to that directory.
* get the current directory name and append the basename. * get the current directory name and append the basename.
*/ */
(void)strncpy(resolved, path, MAXPATHLEN - 1);
resolved[MAXPATHLEN - 1] = '\0';
strlcpy(resolved, path, MAXPATHLEN);
loop: loop:
q = strrchr(resolved, '/'); q = strrchr(resolved, '/');
if (q != NULL) { if (q != NULL) {


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

@ -32,7 +32,7 @@
*/ */
#if defined(LIBC_SCCS) && !defined(lint) #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 */ #endif /* LIBC_SCCS and not lint */
#ifdef NLS #ifdef NLS
@ -87,16 +87,14 @@ __strerror(num, buf)
errnum = num; /* convert to unsigned */ errnum = num; /* convert to unsigned */
if (errnum < sys_nerr) { if (errnum < sys_nerr) {
#ifdef NLS #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 #else
return(sys_errlist[errnum]); return(sys_errlist[errnum]);
#endif #endif
} else { } else {
#ifdef NLS #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 #else
strcpy(buf, UPREFIX); strcpy(buf, UPREFIX);
#endif #endif


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

@ -32,7 +32,7 @@
*/ */
#if defined(LIBC_SCCS) && !defined(lint) #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 */ #endif /* LIBC_SCCS and not lint */
#ifdef NLS #ifdef NLS
@ -80,16 +80,14 @@ __strsignal(num, buf)
signum = num; /* convert to unsigned */ signum = num; /* convert to unsigned */
if (signum < NSIG) { if (signum < NSIG) {
#ifdef NLS #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 #else
return((char *)sys_siglist[signum]); return((char *)sys_siglist[signum]);
#endif #endif
} else { } else {
#ifdef NLS #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 #else
strcpy(buf, UPREFIX); strcpy(buf, UPREFIX);
#endif #endif


Loading…
Cancel
Save