diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1997-06-04 00:15:19 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1997-06-04 00:15:19 +0000 |
commit | c35a45090a123fc8a5e09fbf7a3a10a0a25f693b (patch) | |
tree | a691363c61984f4fd5521d70f6de7e8739d93c54 /bin | |
parent | a28529a0b7fce8365f04c43f00a02b08a4d9a0a1 (diff) |
Fix usage of l_strncpy() (noticed by Theo) and make l_strncpy()
pad with NULL's like strncpy(3). This eliminates the need for
zf_strncpy(); ocurrences of zf_strncpy() have been changed to l_strncpy().
Diffstat (limited to 'bin')
-rw-r--r-- | bin/pax/ar_subs.c | 6 | ||||
-rw-r--r-- | bin/pax/extern.h | 5 | ||||
-rw-r--r-- | bin/pax/ftree.c | 6 | ||||
-rw-r--r-- | bin/pax/gen_subs.c | 45 | ||||
-rw-r--r-- | bin/pax/pat_rep.c | 10 | ||||
-rw-r--r-- | bin/pax/tables.c | 19 | ||||
-rw-r--r-- | bin/pax/tar.c | 37 |
7 files changed, 50 insertions, 78 deletions
diff --git a/bin/pax/ar_subs.c b/bin/pax/ar_subs.c index 9ebc7dc1586..6d1c68c8881 100644 --- a/bin/pax/ar_subs.c +++ b/bin/pax/ar_subs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ar_subs.c,v 1.6 1997/02/27 23:32:57 michaels Exp $ */ +/* $OpenBSD: ar_subs.c,v 1.7 1997/06/04 00:15:14 millert Exp $ */ /* $NetBSD: ar_subs.c,v 1.5 1995/03/21 09:07:06 cgd Exp $ */ /*- @@ -42,7 +42,7 @@ #if 0 static char sccsid[] = "@(#)ar_subs.c 8.2 (Berkeley) 4/18/94"; #else -static char rcsid[] = "$OpenBSD: ar_subs.c,v 1.6 1997/02/27 23:32:57 michaels Exp $"; +static char rcsid[] = "$OpenBSD: ar_subs.c,v 1.7 1997/06/04 00:15:14 millert Exp $"; #endif #endif /* not lint */ @@ -777,7 +777,7 @@ copy() * set up the destination dir path and make sure it is a directory. We * make sure we have a trailing / on the destination */ - dlen = l_strncpy(dirbuf, dirptr, PAXPATHLEN); + dlen = l_strncpy(dirbuf, dirptr, sizeof(dirbuf) - 1); dest_pt = dirbuf + dlen; if (*(dest_pt-1) != '/') { *dest_pt++ = '/'; diff --git a/bin/pax/extern.h b/bin/pax/extern.h index a7204242206..64b7c8a903f 100644 --- a/bin/pax/extern.h +++ b/bin/pax/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.12 1997/04/05 22:36:12 millert Exp $ */ +/* $OpenBSD: extern.h,v 1.13 1997/06/04 00:15:15 millert Exp $ */ /* $NetBSD: extern.h,v 1.5 1996/03/26 23:54:16 mrg Exp $ */ /*- @@ -169,7 +169,6 @@ int next_file __P((register ARCHD *)); */ void ls_list __P((register ARCHD *, time_t, FILE *)); void ls_tty __P((register ARCHD *)); -void zf_strncpy __P((register char *, register char *, int)); int l_strncpy __P((register char *, register char *, int)); u_long asc_ul __P((register char *, int, register int)); int ul_asc __P((u_long, register char *, register int, register int)); @@ -261,7 +260,7 @@ int ftime_start __P((void)); int chk_ftime __P((register ARCHD *)); int name_start __P((void)); int add_name __P((register char *, int, char *)); -void sub_name __P((register char *, int *)); +void sub_name __P((register char *, int *, size_t)); int dev_start __P((void)); int add_dev __P((register ARCHD *)); int map_dev __P((register ARCHD *, u_long, u_long)); diff --git a/bin/pax/ftree.c b/bin/pax/ftree.c index a17ebf7a625..ed846c5ddf7 100644 --- a/bin/pax/ftree.c +++ b/bin/pax/ftree.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ftree.c,v 1.4 1996/10/27 06:45:11 downsj Exp $ */ +/* $OpenBSD: ftree.c,v 1.5 1997/06/04 00:15:16 millert Exp $ */ /* $NetBSD: ftree.c,v 1.4 1995/03/21 09:07:21 cgd Exp $ */ /*- @@ -42,7 +42,7 @@ #if 0 static char sccsid[] = "@(#)ftree.c 8.2 (Berkeley) 4/18/94"; #else -static char rcsid[] = "$OpenBSD: ftree.c,v 1.4 1996/10/27 06:45:11 downsj Exp $"; +static char rcsid[] = "$OpenBSD: ftree.c,v 1.5 1997/06/04 00:15:16 millert Exp $"; #endif #endif /* not lint */ @@ -558,7 +558,7 @@ next_file(arcn) /* * copy file name, set file name length */ - arcn->nlen = l_strncpy(arcn->name, ftent->fts_path, PAXPATHLEN+1); + arcn->nlen = l_strncpy(arcn->name, ftent->fts_path, sizeof(arcn->name) - 1); arcn->name[arcn->nlen] = '\0'; arcn->org_name = ftent->fts_path; return(0); diff --git a/bin/pax/gen_subs.c b/bin/pax/gen_subs.c index 554faf88faa..3cd1f0f08c0 100644 --- a/bin/pax/gen_subs.c +++ b/bin/pax/gen_subs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gen_subs.c,v 1.4 1997/01/24 19:41:21 millert Exp $ */ +/* $OpenBSD: gen_subs.c,v 1.5 1997/06/04 00:15:16 millert Exp $ */ /* $NetBSD: gen_subs.c,v 1.5 1995/03/21 09:07:26 cgd Exp $ */ /*- @@ -42,7 +42,7 @@ #if 0 static char sccsid[] = "@(#)gen_subs.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$OpenBSD: gen_subs.c,v 1.4 1997/01/24 19:41:21 millert Exp $"; +static char rcsid[] = "$OpenBSD: gen_subs.c,v 1.5 1997/06/04 00:15:16 millert Exp $"; #endif #endif /* not lint */ @@ -206,40 +206,12 @@ ls_tty(arcn) } /* - * zf_strncpy() - * copy src to dest up to len chars (stopping at first '\0'), when src is - * shorter than len, pads to len with '\0'. big performance win (and - * a lot easier to code) over strncpy(), then a strlen() then a - * memset(). (or doing the memset() first). - */ - -#if __STDC__ -void -zf_strncpy(register char *dest, register char *src, int len) -#else -void -zf_strncpy(dest, src, len) - register char *dest; - register char *src; - int len; -#endif -{ - register char *stop; - - stop = dest + len; - while ((dest < stop) && (*src != '\0')) - *dest++ = *src++; - while (dest < stop) - *dest++ = '\0'; - return; -} - -/* * l_strncpy() - * copy src to dest up to len chars (stopping at first '\0') + * copy src to dest up to len chars (stopping at first '\0'). + * when src is shorter than len, pads to len with '\0'. * Return: * number of chars copied. (Note this is a real performance win over - * doing a strncpy() then a strlen() + * doing a strncpy(), a strlen(), and then a possible memset()) */ #if __STDC__ @@ -260,9 +232,10 @@ l_strncpy(dest, src, len) start = dest; while ((dest < stop) && (*src != '\0')) *dest++ = *src++; - if (dest < stop) - *dest = '\0'; - return(dest - start); + len = dest - start; + while (dest < stop) + *dest++ = '\0'; + return(len); } /* diff --git a/bin/pax/pat_rep.c b/bin/pax/pat_rep.c index 7bd5e6c5587..87e43ed93ff 100644 --- a/bin/pax/pat_rep.c +++ b/bin/pax/pat_rep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pat_rep.c,v 1.8 1997/04/05 22:36:15 millert Exp $ */ +/* $OpenBSD: pat_rep.c,v 1.9 1997/06/04 00:15:17 millert Exp $ */ /* $NetBSD: pat_rep.c,v 1.4 1995/03/21 09:07:33 cgd Exp $ */ /*- @@ -42,7 +42,7 @@ #if 0 static char sccsid[] = "@(#)pat_rep.c 8.2 (Berkeley) 4/18/94"; #else -static char rcsid[] = "$OpenBSD: pat_rep.c,v 1.8 1997/04/05 22:36:15 millert Exp $"; +static char rcsid[] = "$OpenBSD: pat_rep.c,v 1.9 1997/06/04 00:15:17 millert Exp $"; #endif #endif /* not lint */ @@ -744,7 +744,7 @@ mod_name(arcn) return(res); if ((arcn->type == PAX_SLK) || (arcn->type == PAX_HLK) || (arcn->type == PAX_HRG)) - sub_name(arcn->ln_name, &(arcn->ln_nlen)); + sub_name(arcn->ln_name, &(arcn->ln_nlen), sizeof(arcn->ln_name)); } return(res); } @@ -816,8 +816,8 @@ 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'; + arcn->nlen = l_strncpy(arcn->name, tmpname, sizeof(arcn->name) - 1); + arcn->name[arcn->nlen] = '\0'; if (res < 0) return(-1); return(0); diff --git a/bin/pax/tables.c b/bin/pax/tables.c index ec9b8ae08bf..7e241e0ce67 100644 --- a/bin/pax/tables.c +++ b/bin/pax/tables.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tables.c,v 1.5 1996/12/24 03:44:13 tholo Exp $ */ +/* $OpenBSD: tables.c,v 1.6 1997/06/04 00:15:17 millert Exp $ */ /* $NetBSD: tables.c,v 1.4 1995/03/21 09:07:45 cgd Exp $ */ /*- @@ -42,7 +42,7 @@ #if 0 static char sccsid[] = "@(#)tables.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$OpenBSD: tables.c,v 1.5 1996/12/24 03:44:13 tholo Exp $"; +static char rcsid[] = "$OpenBSD: tables.c,v 1.6 1997/06/04 00:15:17 millert Exp $"; #endif #endif /* not lint */ @@ -184,8 +184,8 @@ chk_lnk(arcn) * other links. */ arcn->ln_nlen = l_strncpy(arcn->ln_name, pt->name, - PAXPATHLEN+1); - arcn->ln_name[PAXPATHLEN] = '\0'; + sizeof(arcn->ln_name) - 1); + arcn->ln_name[arcn->ln_nlen] = '\0'; if (arcn->type == PAX_REG) arcn->type = PAX_HRG; else @@ -630,12 +630,13 @@ add_name(oname, onamelen, nname) #if __STDC__ void -sub_name(register char *oname, int *onamelen) +sub_name(register char *oname, int *onamelen, size_t onamesize) #else void -sub_name(oname, onamelen) +sub_name(oname, onamelen, onamesize) register char *oname; int *onamelen; + size_t onamesize; #endif { register NAMT *pt; @@ -652,15 +653,15 @@ sub_name(oname, onamelen) while (pt != NULL) { /* - * walk down the hash cahin looking for a match + * walk down the hash chain looking for a match */ if (strcmp(oname, pt->oname) == 0) { /* * found it, replace it with the new name * and return (we know that oname has enough space) */ - *onamelen = l_strncpy(oname, pt->nname, PAXPATHLEN+1); - oname[PAXPATHLEN] = '\0'; + *onamelen = l_strncpy(oname, pt->nname, onamesize - 1); + oname[*onamelen] = '\0'; return; } pt = pt->fow; diff --git a/bin/pax/tar.c b/bin/pax/tar.c index c51d0cfae9e..bb4ecca415b 100644 --- a/bin/pax/tar.c +++ b/bin/pax/tar.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tar.c,v 1.9 1997/04/05 22:36:19 millert Exp $ */ +/* $OpenBSD: tar.c,v 1.10 1997/06/04 00:15:18 millert Exp $ */ /* $NetBSD: tar.c,v 1.5 1995/03/21 09:07:49 cgd Exp $ */ /*- @@ -42,7 +42,7 @@ #if 0 static char sccsid[] = "@(#)tar.c 8.2 (Berkeley) 4/18/94"; #else -static char rcsid[] = "$OpenBSD: tar.c,v 1.9 1997/04/05 22:36:19 millert Exp $"; +static char rcsid[] = "$OpenBSD: tar.c,v 1.10 1997/06/04 00:15:18 millert Exp $"; #endif #endif /* not lint */ @@ -457,7 +457,7 @@ tar_rd(arcn, buf) * copy out the name and values in the stat buffer */ hd = (HD_TAR *)buf; - arcn->nlen = l_strncpy(arcn->name, hd->name, sizeof(hd->name) - 1); + arcn->nlen = l_strncpy(arcn->name, hd->name, sizeof(arcn->name) - 1); arcn->name[arcn->nlen] = '\0'; arcn->sb.st_mode = (mode_t)(asc_ul(hd->mode,sizeof(hd->mode),OCT) & 0xfff); @@ -482,7 +482,7 @@ tar_rd(arcn, buf) */ arcn->type = PAX_SLK; arcn->ln_nlen = l_strncpy(arcn->ln_name, hd->linkname, - sizeof(hd->linkname) - 1); + sizeof(arcn->ln_name) - 1); arcn->ln_name[arcn->ln_nlen] = '\0'; arcn->sb.st_mode |= S_IFLNK; break; @@ -494,7 +494,7 @@ tar_rd(arcn, buf) arcn->type = PAX_HLK; arcn->sb.st_nlink = 2; arcn->ln_nlen = l_strncpy(arcn->ln_name, hd->linkname, - sizeof(hd->linkname) - 1); + sizeof(arcn->ln_name) - 1); arcn->ln_name[arcn->ln_nlen] = '\0'; /* @@ -635,7 +635,7 @@ tar_wr(arcn) * a header) */ hd = (HD_TAR *)hdblk; - zf_strncpy(hd->name, arcn->name, sizeof(hd->name) - 1); + l_strncpy(hd->name, arcn->name, sizeof(hd->name) - 1); hd->name[sizeof(hd->name) - 1] = '\0'; arcn->pad = 0; @@ -655,7 +655,7 @@ tar_wr(arcn) * no data follows this file, so no pad */ hd->linkflag = SYMTYPE; - zf_strncpy(hd->linkname,arcn->ln_name, sizeof(hd->linkname) - 1); + l_strncpy(hd->linkname,arcn->ln_name, sizeof(hd->linkname) - 1); hd->linkname[sizeof(hd->linkname) - 1] = '\0'; if (ul_oct((u_long)0L, hd->size, sizeof(hd->size), 1)) goto out; @@ -664,7 +664,7 @@ tar_wr(arcn) * no data follows this file, so no pad */ hd->linkflag = LNKTYPE; - zf_strncpy(hd->linkname,arcn->ln_name, sizeof(hd->linkname) - 1); + l_strncpy(hd->linkname,arcn->ln_name, sizeof(hd->linkname) - 1); hd->linkname[sizeof(hd->linkname) - 1] = '\0'; if (ul_oct((u_long)0L, hd->size, sizeof(hd->size), 1)) goto out; @@ -844,13 +844,12 @@ ustar_rd(arcn, buf) */ dest = arcn->name; if (*(hd->prefix) != '\0') { - cnt = l_strncpy(dest, hd->prefix, sizeof(hd->prefix) - 1); - hd->prefix[sizeof(hd->prefix) - 1] = '\0'; + cnt = l_strncpy(dest, hd->prefix, sizeof(arcn->name) - 2); dest += cnt; *dest++ = '/'; cnt++; } - arcn->nlen = cnt + l_strncpy(dest, hd->name, sizeof(hd->name) - 1); + arcn->nlen = cnt + l_strncpy(dest, hd->name, sizeof(arcn->name) - cnt); arcn->name[arcn->nlen] = '\0'; /* @@ -939,7 +938,7 @@ ustar_rd(arcn, buf) * copy the link name */ arcn->ln_nlen = l_strncpy(arcn->ln_name, hd->linkname, - sizeof(hd->linkname) - 1); + sizeof(arcn->ln_name) - 1); arcn->ln_name[arcn->ln_nlen] = '\0'; break; case CONTTYPE: @@ -1021,7 +1020,7 @@ ustar_wr(arcn) * occur, we remove the / and copy the first part to the prefix */ *pt = '\0'; - zf_strncpy(hd->prefix, arcn->name, sizeof(hd->prefix) - 1); + l_strncpy(hd->prefix, arcn->name, sizeof(hd->prefix) - 1); *pt++ = '/'; } else memset(hd->prefix, 0, sizeof(hd->prefix)); @@ -1030,7 +1029,7 @@ ustar_wr(arcn) * copy the name part. this may be the whole path or the part after * the prefix */ - zf_strncpy(hd->name, pt, sizeof(hd->name) - 1); + l_strncpy(hd->name, pt, sizeof(hd->name) - 1); hd->name[sizeof(hd->name) - 1] = '\0'; /* @@ -1074,7 +1073,7 @@ ustar_wr(arcn) hd->typeflag = SYMTYPE; else hd->typeflag = LNKTYPE; - zf_strncpy(hd->linkname,arcn->ln_name, sizeof(hd->linkname) - 1); + l_strncpy(hd->linkname,arcn->ln_name, sizeof(hd->linkname) - 1); hd->linkname[sizeof(hd->linkname) - 1] = '\0'; memset(hd->devmajor, 0, sizeof(hd->devmajor)); memset(hd->devminor, 0, sizeof(hd->devminor)); @@ -1108,8 +1107,8 @@ ustar_wr(arcn) break; } - zf_strncpy(hd->magic, TMAGIC, TMAGLEN); - zf_strncpy(hd->version, TVERSION, TVERSLEN); + l_strncpy(hd->magic, TMAGIC, TMAGLEN); + l_strncpy(hd->version, TVERSION, TVERSLEN); /* * set the remaining fields. Some versions want all 16 bits of mode @@ -1120,8 +1119,8 @@ ustar_wr(arcn) ul_oct((u_long)arcn->sb.st_gid, hd->gid, sizeof(hd->gid), 3) || ul_oct((u_long)arcn->sb.st_mtime,hd->mtime,sizeof(hd->mtime),3)) goto out; - zf_strncpy(hd->uname,name_uid(arcn->sb.st_uid, 0),sizeof(hd->uname)); - zf_strncpy(hd->gname,name_gid(arcn->sb.st_gid, 0),sizeof(hd->gname)); + l_strncpy(hd->uname,name_uid(arcn->sb.st_uid, 0),sizeof(hd->uname)); + l_strncpy(hd->gname,name_gid(arcn->sb.st_gid, 0),sizeof(hd->gname)); /* * calculate and store the checksum write the header to the archive |