| 1 |
/** $MirOS: src/bin/pax/cpio.c,v 1.10 2006/06/19 19:22:08 tg Exp $ */ |
/** $MirOS: src/bin/pax/cpio.c,v 1.12 2007/02/17 05:07:12 tg Exp $ */ |
| 2 |
/* $OpenBSD: cpio.c,v 1.17 2004/04/16 22:50:23 deraadt Exp $ */ |
/* $OpenBSD: cpio.c,v 1.17 2004/04/16 22:50:23 deraadt Exp $ */ |
| 3 |
/* $NetBSD: cpio.c,v 1.5 1995/03/21 09:07:13 cgd Exp $ */ |
/* $NetBSD: cpio.c,v 1.5 1995/03/21 09:07:13 cgd Exp $ */ |
| 4 |
|
|
| 49 |
#include "options.h" |
#include "options.h" |
| 50 |
|
|
| 51 |
__SCCSID("@(#)cpio.c 8.1 (Berkeley) 5/31/93"); |
__SCCSID("@(#)cpio.c 8.1 (Berkeley) 5/31/93"); |
| 52 |
__RCSID("$MirOS: src/bin/pax/cpio.c,v 1.10 2006/06/19 19:22:08 tg Exp $"); |
__RCSID("$MirOS: src/bin/pax/cpio.c,v 1.12 2007/02/17 05:07:12 tg Exp $"); |
| 53 |
|
|
| 54 |
static int rd_nm(ARCHD *, int); |
static int rd_nm(ARCHD *, int); |
| 55 |
static int rd_ln_nm(ARCHD *); |
static int rd_ln_nm(ARCHD *); |
| 89 |
*/ |
*/ |
| 90 |
|
|
| 91 |
int |
int |
| 92 |
cpio_trail(ARCHD *arcn, char *notused, int notused2, int *notused3) |
cpio_trail(ARCHD *arcn, char *notused __attribute__((unused)), |
| 93 |
|
int notused2 __attribute__((unused)), |
| 94 |
|
int *notused3 __attribute__((unused))) |
| 95 |
{ |
{ |
| 96 |
/* |
/* |
| 97 |
* look for trailer id in file we are about to process |
* look for trailer id in file we are about to process |
| 186 |
/* |
/* |
| 187 |
* do not even try bogus values |
* do not even try bogus values |
| 188 |
*/ |
*/ |
| 189 |
if ((nsz == 0) || (nsz > sizeof(arcn->name))) { |
if ((nsz == 0) || ((size_t)nsz > sizeof(arcn->name))) { |
| 190 |
paxwarn(1, "Cpio file name length %d is out of range", nsz); |
paxwarn(1, "Cpio file name length %d is out of range", nsz); |
| 191 |
return(-1); |
return(-1); |
| 192 |
} |
} |
| 217 |
* check the length specified for bogus values |
* check the length specified for bogus values |
| 218 |
*/ |
*/ |
| 219 |
if ((arcn->sb.st_size == 0) || |
if ((arcn->sb.st_size == 0) || |
| 220 |
(arcn->sb.st_size >= sizeof(arcn->ln_name))) { |
((size_t)arcn->sb.st_size >= sizeof(arcn->ln_name))) { |
| 221 |
# ifdef LONG_OFF_T |
# ifdef LONG_OFF_T |
| 222 |
paxwarn(1, "Cpio link name length is invalid: %lu", |
paxwarn(1, "Cpio link name length is invalid: %lu", |
| 223 |
arcn->sb.st_size); |
arcn->sb.st_size); |
| 224 |
# else |
# else |
| 225 |
paxwarn(1, "Cpio link name length is invalid: %qu", |
paxwarn(1, "Cpio link name length is invalid: %llu", |
| 226 |
arcn->sb.st_size); |
arcn->sb.st_size); |
| 227 |
# endif |
# endif |
| 228 |
return(-1); |
return(-1); |
| 264 |
int |
int |
| 265 |
cpio_id(char *blk, int size) |
cpio_id(char *blk, int size) |
| 266 |
{ |
{ |
| 267 |
if ((size < sizeof(HD_CPIO)) || |
if (((size_t)size < sizeof(HD_CPIO)) || |
| 268 |
(strncmp(blk, AMAGIC, sizeof(AMAGIC) - 1) != 0)) |
(strncmp(blk, AMAGIC, sizeof(AMAGIC) - 1) != 0)) |
| 269 |
return(-1); |
return(-1); |
| 270 |
return(0); |
return(0); |
| 419 |
t_uid = (anonarch & ANON_UIDGID) ? 0UL : (u_long)arcn->sb.st_uid; |
t_uid = (anonarch & ANON_UIDGID) ? 0UL : (u_long)arcn->sb.st_uid; |
| 420 |
t_gid = (anonarch & ANON_UIDGID) ? 0UL : (u_long)arcn->sb.st_gid; |
t_gid = (anonarch & ANON_UIDGID) ? 0UL : (u_long)arcn->sb.st_gid; |
| 421 |
t_mtime = (anonarch & ANON_MTIME) ? 0UL : (u_long)arcn->sb.st_mtime; |
t_mtime = (anonarch & ANON_MTIME) ? 0UL : (u_long)arcn->sb.st_mtime; |
| 422 |
t_ino = (anonarch & ANON_INODES) ? chk_flnk(arcn) : arcn->sb.st_ino; |
t_ino = (anonarch & ANON_INODES) ? (ino_t)chk_flnk(arcn) : |
| 423 |
|
arcn->sb.st_ino; |
| 424 |
t_dev = (anonarch & ANON_INODES) ? 0UL : (u_long)arcn->sb.st_dev; |
t_dev = (anonarch & ANON_INODES) ? 0UL : (u_long)arcn->sb.st_dev; |
| 425 |
if (!cpio_trail(arcn, NULL, 0, NULL)) |
if (!cpio_trail(arcn, NULL, 0, NULL)) |
| 426 |
t_ino = 0UL; |
t_ino = 0UL; |
| 427 |
if (t_ino == -1) { |
if (t_ino == (ino_t)-1) { |
| 428 |
paxwarn(1, "Invalid inode number for file %s", arcn->org_name); |
paxwarn(1, "Invalid inode number for file %s", arcn->org_name); |
| 429 |
return (1); |
return (1); |
| 430 |
} |
} |
| 555 |
int |
int |
| 556 |
vcpio_id(char *blk, int size) |
vcpio_id(char *blk, int size) |
| 557 |
{ |
{ |
| 558 |
if ((size < sizeof(HD_VCPIO)) || |
if (((size_t)size < sizeof(HD_VCPIO)) || |
| 559 |
(strncmp(blk, AVMAGIC, sizeof(AVMAGIC) - 1) != 0)) |
(strncmp(blk, AVMAGIC, sizeof(AVMAGIC) - 1) != 0)) |
| 560 |
return(-1); |
return(-1); |
| 561 |
return(0); |
return(0); |
| 572 |
int |
int |
| 573 |
crc_id(char *blk, int size) |
crc_id(char *blk, int size) |
| 574 |
{ |
{ |
| 575 |
if ((size < sizeof(HD_VCPIO)) || |
if (((size_t)size < sizeof(HD_VCPIO)) || |
| 576 |
(strncmp(blk, AVCMAGIC, sizeof(AVCMAGIC) - 1) != 0)) |
(strncmp(blk, AVCMAGIC, sizeof(AVCMAGIC) - 1) != 0)) |
| 577 |
return(-1); |
return(-1); |
| 578 |
return(0); |
return(0); |
| 790 |
t_uid = (anonarch & ANON_UIDGID) ? 0UL : (u_long)arcn->sb.st_uid; |
t_uid = (anonarch & ANON_UIDGID) ? 0UL : (u_long)arcn->sb.st_uid; |
| 791 |
t_gid = (anonarch & ANON_UIDGID) ? 0UL : (u_long)arcn->sb.st_gid; |
t_gid = (anonarch & ANON_UIDGID) ? 0UL : (u_long)arcn->sb.st_gid; |
| 792 |
t_mtime = (anonarch & ANON_MTIME) ? 0UL : (u_long)arcn->sb.st_mtime; |
t_mtime = (anonarch & ANON_MTIME) ? 0UL : (u_long)arcn->sb.st_mtime; |
| 793 |
t_ino = (anonarch & ANON_INODES) ? chk_flnk(arcn) : arcn->sb.st_ino; |
t_ino = (anonarch & ANON_INODES) ? (ino_t)chk_flnk(arcn) : |
| 794 |
|
arcn->sb.st_ino; |
| 795 |
t_major = (anonarch & ANON_INODES) ? 0UL : (u_long)MAJOR(arcn->sb.st_dev); |
t_major = (anonarch & ANON_INODES) ? 0UL : (u_long)MAJOR(arcn->sb.st_dev); |
| 796 |
t_minor = (anonarch & ANON_INODES) ? 0UL : (u_long)MINOR(arcn->sb.st_dev); |
t_minor = (anonarch & ANON_INODES) ? 0UL : (u_long)MINOR(arcn->sb.st_dev); |
| 797 |
if (!cpio_trail(arcn, NULL, 0, NULL)) |
if (!cpio_trail(arcn, NULL, 0, NULL)) |
| 798 |
t_ino = 0UL; |
t_ino = 0UL; |
| 799 |
if (t_ino == -1) { |
if (t_ino == (ino_t)-1) { |
| 800 |
paxwarn(1, "Invalid inode number for file %s", arcn->org_name); |
paxwarn(1, "Invalid inode number for file %s", arcn->org_name); |
| 801 |
return (1); |
return (1); |
| 802 |
} |
} |
| 942 |
int |
int |
| 943 |
bcpio_id(char *blk, int size) |
bcpio_id(char *blk, int size) |
| 944 |
{ |
{ |
| 945 |
if (size < sizeof(HD_BCPIO)) |
if ((size_t)size < sizeof(HD_BCPIO)) |
| 946 |
return(-1); |
return(-1); |
| 947 |
|
|
| 948 |
/* |
/* |