From 961f5b3e1abdffe530b197a07b82f42848ee24fe Mon Sep 17 00:00:00 2001 From: charnier Date: Mon, 2 Jun 1997 06:30:06 +0000 Subject: Off by 1 adjustment. Properly NUL terminate after strncpy. Obtained from: {Net|Open}BSD --- bin/pax/cache.c | 10 +++++----- bin/pax/pat_rep.c | 4 +++- bin/pax/tables.c | 4 +++- 3 files changed, 11 insertions(+), 7 deletions(-) (limited to 'bin/pax') diff --git a/bin/pax/cache.c b/bin/pax/cache.c index 9b2615c..68e534a 100644 --- a/bin/pax/cache.c +++ b/bin/pax/cache.c @@ -34,7 +34,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id$ + * $Id: cache.c,v 1.6 1997/02/22 14:04:21 peter Exp $ */ #ifndef lint @@ -255,7 +255,7 @@ name_uid(uid, frc) if (ptr == NULL) return(pw->pw_name); ptr->uid = uid; - (void)strncpy(ptr->name, pw->pw_name, UNMLEN); + (void)strncpy(ptr->name, pw->pw_name, UNMLEN - 1); ptr->name[UNMLEN-1] = '\0'; ptr->valid = VALID; } @@ -332,7 +332,7 @@ name_gid(gid, frc) if (ptr == NULL) return(gr->gr_name); ptr->gid = gid; - (void)strncpy(ptr->name, gr->gr_name, GNMLEN); + (void)strncpy(ptr->name, gr->gr_name, GNMLEN - 1); ptr->name[GNMLEN-1] = '\0'; ptr->valid = VALID; } @@ -398,7 +398,7 @@ uid_name(name, uid) *uid = pw->pw_uid; return(0); } - (void)strncpy(ptr->name, name, UNMLEN); + (void)strncpy(ptr->name, name, UNMLEN - 1); ptr->name[UNMLEN-1] = '\0'; if ((pw = getpwnam(name)) == NULL) { ptr->valid = INVALID; @@ -468,7 +468,7 @@ gid_name(name, gid) return(0); } - (void)strncpy(ptr->name, name, GNMLEN); + (void)strncpy(ptr->name, name, GNMLEN - 1); ptr->name[GNMLEN-1] = '\0'; if ((gr = getgrnam(name)) == NULL) { ptr->valid = INVALID; diff --git a/bin/pax/pat_rep.c b/bin/pax/pat_rep.c index 0c9ed7b..6519eb4 100644 --- a/bin/pax/pat_rep.c +++ b/bin/pax/pat_rep.c @@ -34,7 +34,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id$ + * $Id: pat_rep.c,v 1.8 1997/02/22 14:04:35 peter Exp $ */ #ifndef lint @@ -776,6 +776,7 @@ tty_rename(arcn) tty_prnt("Processing continues, name changed to: %s\n", tmpname); res = add_name(arcn->name, arcn->nlen, tmpname); arcn->nlen = l_strncpy(arcn->name, tmpname, PAXPATHLEN+1); + arcn->name[PAXPATHLEN] = '\0'; if (res < 0) return(-1); return(0); @@ -1056,6 +1057,7 @@ rep_name(name, nlen, prnt) if (*nname == '\0') return(1); *nlen = l_strncpy(name, nname, PAXPATHLEN + 1); + name[PAXPATHLEN] = '\0'; } return(0); } diff --git a/bin/pax/tables.c b/bin/pax/tables.c index a464ad1..b35bb99 100644 --- a/bin/pax/tables.c +++ b/bin/pax/tables.c @@ -34,7 +34,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id$ + * $Id: tables.c,v 1.7 1997/02/22 14:04:43 peter Exp $ */ #ifndef lint @@ -180,6 +180,7 @@ chk_lnk(arcn) */ arcn->ln_nlen = l_strncpy(arcn->ln_name, pt->name, PAXPATHLEN+1); + arcn->ln_name[PAXPATHLEN] = '\0'; if (arcn->type == PAX_REG) arcn->type = PAX_HRG; else @@ -655,6 +656,7 @@ sub_name(oname, onamelen) * and return (we know that oname has enough space) */ *onamelen = l_strncpy(oname, pt->nname, PAXPATHLEN+1); + oname[PAXPATHLEN] = '\0'; return; } pt = pt->fow; -- cgit v1.1