From 9772d15e5ee69a0a4bf68acaad32014e45e318c2 Mon Sep 17 00:00:00 2001 From: didg Date: Sat, 14 Feb 2004 15:47:19 +0000 Subject: [PATCH] more strncpy --> strlcpy fixes --- etc/afpd/auth.c | 4 ++-- etc/afpd/mangle.c | 8 +++----- etc/afpd/ofork.c | 8 ++++---- etc/afpd/volume.c | 6 +++--- libatalk/adouble/ad_open.c | 20 ++++++++++++-------- 5 files changed, 24 insertions(+), 22 deletions(-) diff --git a/etc/afpd/auth.c b/etc/afpd/auth.c index b90f7534..c7623413 100644 --- a/etc/afpd/auth.c +++ b/etc/afpd/auth.c @@ -1,5 +1,5 @@ /* - * $Id: auth.c,v 1.44.2.3.2.9 2004-02-14 00:30:50 didg Exp $ + * $Id: auth.c,v 1.44.2.3.2.10 2004-02-14 15:47:19 didg Exp $ * * Copyright (c) 1990,1993 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -943,7 +943,7 @@ int auth_load(const char *path, const char *list) } while (p) { - strncpy(name + len, p, sizeof(name) - len); + strlcpy(name + len, p, sizeof(name) - len); LOG(log_debug, logtype_afpd, "uam: loading (%s)", name); /* if ((stat(name, &st) == 0) && (mod = uam_load(name, p))) { diff --git a/etc/afpd/mangle.c b/etc/afpd/mangle.c index 38855a63..4a6d9eb9 100644 --- a/etc/afpd/mangle.c +++ b/etc/afpd/mangle.c @@ -1,5 +1,5 @@ /* - * $Id: mangle.c,v 1.16.2.1.2.7 2003-11-03 03:10:01 bfernhomberg Exp $ + * $Id: mangle.c,v 1.16.2.1.2.8 2004-02-14 15:47:20 didg Exp $ * * Copyright (c) 2002. Joe Marcus Clarke (marcus@marcuscom.com) * All Rights Reserved. See COPYRIGHT. @@ -17,12 +17,11 @@ #include #include "mangle.h" #include "desktop.h" +#include #define hextoint( c ) ( isdigit( c ) ? c - '0' : c + 10 - 'A' ) #define isuxdigit(x) (isdigit(x) || (isupper(x) && isxdigit(x))) - - static char *demangle_checks ( const struct vol *vol, char* uname, char * mfilename, size_t prefix, char * ext) { u_int16_t flags; @@ -229,10 +228,9 @@ mangle(const struct vol *vol, char *filename, char *uname, cnid_t id, int flags) } } m = mfilename; - memset(m, 0, MAX_LENGTH + 1); k = sprintf(mangle_suffix, "%c%X", MANGLE_CHAR, ntohl(id)); - strncpy(m, filename, MAX_LENGTH - k - ext_len); + strlcpy(m, filename, MAX_LENGTH - k - ext_len +1); if (*m == 0) { strcat(m, "???"); } diff --git a/etc/afpd/ofork.c b/etc/afpd/ofork.c index 378d7c1b..8d47061c 100644 --- a/etc/afpd/ofork.c +++ b/etc/afpd/ofork.c @@ -1,5 +1,5 @@ /* - * $Id: ofork.c,v 1.20.6.3 2003-11-01 02:38:09 bfernhomberg Exp $ + * $Id: ofork.c,v 1.20.6.4 2004-02-14 15:47:20 didg Exp $ * * Copyright (c) 1996 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -20,7 +20,7 @@ #include #include -#include +#include #include "globals.h" #include "volume.h" @@ -120,7 +120,7 @@ const char *oldpath, *newpath; if (vol == of->of_vol && olddir == of->of_dir && s_of->key.dev == of->key.dev && s_of->key.inode == of->key.inode ) { - strncpy( of->of_name, newpath, of->of_namelen); + strlcpy( of->of_name, newpath, of->of_namelen); if (newdir != olddir) { of->of_d_prev->of_d_next = of->of_d_next; of->of_d_next->of_d_prev = of->of_d_prev; @@ -253,7 +253,7 @@ struct stat *st; oforks[ of_refnum ] = NULL; return NULL; } - strncpy( of->of_name, path, of->of_namelen = 255 + 1); + strlcpy( of->of_name, path, of->of_namelen = 255 + 1); *ofrefnum = refnum; of->of_refnum = refnum; of->key.dev = st->st_dev; diff --git a/etc/afpd/volume.c b/etc/afpd/volume.c index 0dcf6321..f8e3f78a 100644 --- a/etc/afpd/volume.c +++ b/etc/afpd/volume.c @@ -1,5 +1,5 @@ /* - * $Id: volume.c,v 1.51.2.7.2.19 2004-02-05 16:55:19 bfernhomberg Exp $ + * $Id: volume.c,v 1.51.2.7.2.20 2004-02-14 15:47:20 didg Exp $ * * Copyright (c) 1990,1993 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -210,7 +210,7 @@ static char *volxlate(AFPObj *obj, char *dest, size_t destlen, if (!ret) { return NULL; } - strncpy(dest, src, destlen); + strlcpy(dest, src, destlen +1); if ((p = strchr(src, '$')) == NULL) /* nothing to do */ return ret; @@ -692,7 +692,7 @@ const char *name; if (!args) return -1; - strncpy(buf, args, sizeof(buf)); + strlcpy(buf, args, sizeof(buf)); if ((p = strtok(buf, ",")) == NULL) /* nothing, return okay */ return -1; diff --git a/libatalk/adouble/ad_open.c b/libatalk/adouble/ad_open.c index 5fd833d1..08cc7fb9 100644 --- a/libatalk/adouble/ad_open.c +++ b/libatalk/adouble/ad_open.c @@ -1,5 +1,5 @@ /* - * $Id: ad_open.c,v 1.30.6.6 2004-02-06 13:39:52 bfernhomberg Exp $ + * $Id: ad_open.c,v 1.30.6.7 2004-02-14 15:47:22 didg Exp $ * * Copyright (c) 1999 Adrian Sun (asun@u.washington.edu) * Copyright (c) 1990,1991 Regents of The University of Michigan. @@ -640,6 +640,8 @@ static int ad_header_read(struct adouble *ad, struct stat *hst) * / a/.AppleDouble/b * a/b * \ b/.AppleDouble/.Parent + * + * FIXME: should do something for pathname > MAXPATHLEN */ char * ad_path( path, adflags ) @@ -648,27 +650,29 @@ ad_path( path, adflags ) { static char pathbuf[ MAXPATHLEN + 1]; char c, *slash, buf[MAXPATHLEN + 1]; + size_t l; - strncpy(buf, path, MAXPATHLEN); + l = strlcpy(buf, path, MAXPATHLEN +1); if ( adflags & ADFLAGS_DIR ) { - strncpy( pathbuf, buf, MAXPATHLEN ); - if ( *buf != '\0' ) { - strcat( pathbuf, "/" ); + strcpy( pathbuf, buf); + if ( *buf != '\0' && l < MAXPATHLEN) { + pathbuf[l++] = '/'; + pathbuf[l] = 0; } slash = ".Parent"; } else { if (NULL != ( slash = strrchr( buf, '/' )) ) { c = *++slash; *slash = '\0'; - strncpy( pathbuf, buf, MAXPATHLEN); + strcpy( pathbuf, buf); *slash = c; } else { pathbuf[ 0 ] = '\0'; slash = buf; } } - strncat( pathbuf, ".AppleDouble/", MAXPATHLEN - strlen(pathbuf)); - strncat( pathbuf, slash, MAXPATHLEN - strlen(pathbuf)); + strlcat( pathbuf, ".AppleDouble/", MAXPATHLEN +1); + strlcat( pathbuf, slash, MAXPATHLEN +1); return( pathbuf ); } -- 2.39.2