Date: Wed, 24 Jul 2024 20:07:10 GMT From: Dag-Erling =?utf-8?Q?Sm=C3=B8rgrav?= <des@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: f890020d43bf - main - pax: Clear arcn in each read function. Message-ID: <202407242007.46OK7A4b046068@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=f890020d43bf2070f12ffec37bcd9579f6fb1347 commit f890020d43bf2070f12ffec37bcd9579f6fb1347 Author: Dag-Erling Smørgrav <des@FreeBSD.org> AuthorDate: 2024-07-24 20:06:44 +0000 Commit: Dag-Erling Smørgrav <des@FreeBSD.org> CommitDate: 2024-07-24 20:07:06 +0000 pax: Clear arcn in each read function. Instead of initializing individual fields to zero, clear the entire struct prior to populating it. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: 0mp, markj Differential Revision: https://reviews.freebsd.org/D46097 --- bin/pax/cpio.c | 12 +++--------- bin/pax/tar.c | 20 ++------------------ 2 files changed, 5 insertions(+), 27 deletions(-) diff --git a/bin/pax/cpio.c b/bin/pax/cpio.c index 8ae40f461343..8108dd11731f 100644 --- a/bin/pax/cpio.c +++ b/bin/pax/cpio.c @@ -274,13 +274,13 @@ cpio_rd(ARCHD *arcn, char *buf) */ if (cpio_id(buf, sizeof(HD_CPIO)) < 0) return(-1); + memset(arcn, 0, sizeof *arcn); hd = (HD_CPIO *)buf; /* * byte oriented cpio (posix) does not have padding! extract the octal * ascii fields from the header */ - arcn->pad = 0L; arcn->sb.st_dev = (dev_t)asc_ul(hd->c_dev, sizeof(hd->c_dev), OCT); arcn->sb.st_ino = (ino_t)asc_ul(hd->c_ino, sizeof(hd->c_ino), OCT); arcn->sb.st_mode = (mode_t)asc_ul(hd->c_mode, sizeof(hd->c_mode), OCT); @@ -309,8 +309,6 @@ cpio_rd(ARCHD *arcn, char *buf) /* * no link name to read for this file */ - arcn->ln_nlen = 0; - arcn->ln_name[0] = '\0'; return(com_rd(arcn)); } @@ -555,8 +553,8 @@ vcpio_rd(ARCHD *arcn, char *buf) return(-1); } + memset(arcn, 0, sizeof *arcn); hd = (HD_VCPIO *)buf; - arcn->pad = 0L; /* * extract the hex ascii fields from the header @@ -603,8 +601,6 @@ vcpio_rd(ARCHD *arcn, char *buf) /* * we have a valid header (not a link) */ - arcn->ln_nlen = 0; - arcn->ln_name[0] = '\0'; arcn->pad = VCPIO_PAD(arcn->sb.st_size); return(com_rd(arcn)); } @@ -851,7 +847,7 @@ bcpio_rd(ARCHD *arcn, char *buf) if (bcpio_id(buf, sizeof(HD_BCPIO)) < 0) return(-1); - arcn->pad = 0L; + memset(arcn, 0, sizeof *arcn); hd = (HD_BCPIO *)buf; if (swp_head) { /* @@ -913,8 +909,6 @@ bcpio_rd(ARCHD *arcn, char *buf) /* * we have a valid header (not a link) */ - arcn->ln_nlen = 0; - arcn->ln_name[0] = '\0'; arcn->pad = BCPIO_PAD(arcn->sb.st_size); return(com_rd(arcn)); } diff --git a/bin/pax/tar.c b/bin/pax/tar.c index 50a9a41623ca..8b551d84ccc3 100644 --- a/bin/pax/tar.c +++ b/bin/pax/tar.c @@ -367,9 +367,9 @@ tar_rd(ARCHD *arcn, char *buf) */ if (tar_id(buf, BLKMULT) < 0) return(-1); + memset(arcn, 0, sizeof *arcn); arcn->org_name = arcn->name; arcn->sb.st_nlink = 1; - arcn->pat = NULL; /* * copy out the name and values in the stat buffer @@ -396,8 +396,6 @@ tar_rd(ARCHD *arcn, char *buf) * to encode this as a directory */ pt = &(arcn->name[arcn->nlen - 1]); - arcn->pad = 0; - arcn->skip = 0; switch(hd->linkflag) { case SYMTYPE: /* @@ -434,8 +432,6 @@ tar_rd(ARCHD *arcn, char *buf) arcn->type = PAX_DIR; arcn->sb.st_mode |= S_IFDIR; arcn->sb.st_nlink = 2; - arcn->ln_name[0] = '\0'; - arcn->ln_nlen = 0; break; case AREGTYPE: case REGTYPE: @@ -443,8 +439,6 @@ tar_rd(ARCHD *arcn, char *buf) /* * If we have a trailing / this is a directory and NOT a file. */ - arcn->ln_name[0] = '\0'; - arcn->ln_nlen = 0; if (*pt == '/') { /* * it is a directory, set the mode for -v printing @@ -721,10 +715,9 @@ ustar_rd(ARCHD *arcn, char *buf) */ if (ustar_id(buf, BLKMULT) < 0) return(-1); + memset(arcn, 0, sizeof *arcn); arcn->org_name = arcn->name; arcn->sb.st_nlink = 1; - arcn->pat = NULL; - arcn->nlen = 0; hd = (HD_USTAR *)buf; /* @@ -771,15 +764,6 @@ ustar_rd(ARCHD *arcn, char *buf) if (uid_name(hd->uname, &(arcn->sb.st_uid)) < 0) arcn->sb.st_uid = (uid_t)asc_ul(hd->uid, sizeof(hd->uid), OCT); - /* - * set the defaults, these may be changed depending on the file type - */ - arcn->ln_name[0] = '\0'; - arcn->ln_nlen = 0; - arcn->pad = 0; - arcn->skip = 0; - arcn->sb.st_rdev = (dev_t)0; - /* * set the mode and PAX type according to the typeflag in the header */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202407242007.46OK7A4b046068>