From d51292cc7b7c1d89307bcb044b51b3afa33535b8 Mon Sep 17 00:00:00 2001 From: didg Date: Fri, 13 Feb 2004 22:32:17 +0000 Subject: [PATCH] replace : l = strlen(x); strncpy(z,x,l) with memcpy(z,x,l), ie make it clearer that last 0 is not copied. --- etc/afpd/appl.c | 18 +++++++++++++++--- etc/afpd/directory.c | 6 +++--- etc/afpd/filedir.c | 8 ++++---- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/etc/afpd/appl.c b/etc/afpd/appl.c index c3a00189..ababedf3 100644 --- a/etc/afpd/appl.c +++ b/etc/afpd/appl.c @@ -1,5 +1,5 @@ /* - * $Id: appl.c,v 1.12.2.1 2003-05-10 10:33:16 didg Exp $ + * $Id: appl.c,v 1.12.2.1.2.1 2004-02-13 22:32:17 didg Exp $ * * Copyright (c) 1990,1993 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -134,7 +134,8 @@ u_short mplen; * but uses upaths instead of mac format paths. * * The new way: dir and path refer to an app, path is a mac format - * pathname. makemacpath() builds a cname. + * pathname. makemacpath() builds a cname. (zero is a path separator + * and it's not \0 terminated). * * See afp_getappl() for the backward compatiblity code. */ @@ -149,10 +150,14 @@ char *path; p = mpath + mpathlen; p -= strlen( path ); - strncpy( p, path, strlen( path )); + memcpy( p, path, strlen( path )); while ( dir->d_parent != NULL ) { p -= strlen( dir->d_m_name ) + 1; + if (p < mpath) { + /* FIXME: pathname too long */ + return NULL; + } strcpy( p, dir->d_m_name ); dir = dir->d_parent; } @@ -218,6 +223,9 @@ int ibuflen, *rbuflen; } mpath = obj->newtmp; mp = makemacpath( mpath, AFPOBJ_TMPSIZ, curdir, path->m_name ); + if (!mp) { + return AFPERR_PARAM; + } mplen = mpath + AFPOBJ_TMPSIZ - mp; /* write the new appl entry at start of temporary file */ @@ -301,6 +309,10 @@ int ibuflen, *rbuflen; } mpath = obj->newtmp; mp = makemacpath( mpath, AFPOBJ_TMPSIZ, curdir, path->m_name ); + if (!mp) { + return AFPERR_PARAM ; + } + mplen = mpath + AFPOBJ_TMPSIZ - mp; cc = copyapplfile( sa.sdt_fd, tfd, mp, mplen ); close( tfd ); diff --git a/etc/afpd/directory.c b/etc/afpd/directory.c index 536a2bda..ffa896ff 100644 --- a/etc/afpd/directory.c +++ b/etc/afpd/directory.c @@ -1,5 +1,5 @@ /* - * $Id: directory.c,v 1.71.2.4.2.8 2004-02-09 23:49:31 bfernhomberg Exp $ + * $Id: directory.c,v 1.71.2.4.2.9 2004-02-13 22:32:18 didg Exp $ * * Copyright (c) 1990,1993 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -1203,7 +1203,7 @@ struct dir *dir; } *--p = '/'; p -= n; - strncpy( p, u, n ); + memcpy( p, u, n ); } if ( d != curdir ) { n = strlen( vol->v_path ); @@ -1213,7 +1213,7 @@ struct dir *dir; } *--p = '/'; p -= n; - strncpy( p, vol->v_path, n ); + memcpy( p, vol->v_path, n ); } if ( chdir( p ) < 0 ) { switch (errno) { diff --git a/etc/afpd/filedir.c b/etc/afpd/filedir.c index e9da430b..4838bee2 100644 --- a/etc/afpd/filedir.c +++ b/etc/afpd/filedir.c @@ -1,5 +1,5 @@ /* - * $Id: filedir.c,v 1.45.2.2.2.5 2004-01-08 03:50:56 bfernhomberg Exp $ + * $Id: filedir.c,v 1.45.2.2.2.6 2004-02-13 22:32:18 didg Exp $ * * Copyright (c) 1990,1993 Regents of The University of Michigan. * All Rights Reserved. See COPYRIGHT. @@ -625,7 +625,7 @@ char *u; *p = '\0'; len = strlen( u ); p -= len; - strncpy( p, u, len ); + memcpy( p, u, len ); if (dir) for ( d = dir; d->d_parent; d = d->d_parent ) { u = d->d_u_name; len = strlen( u ); @@ -637,7 +637,7 @@ char *u; } *--p = '/'; p -= len; - strncpy( p, u, len ); + memcpy( p, u, len ); } len = strlen( vol->v_path ); if (p -len -1 < path) { @@ -645,7 +645,7 @@ char *u; } *--p = '/'; p -= len; - strncpy( p, vol->v_path, len ); + memcpy( p, vol->v_path, len ); return( p ); } -- 2.39.2