From: Thomas Cort Date: Thu, 9 Jun 2011 17:12:53 +0000 (+0000) Subject: A few aesthetic changes to make the minix port more acceptable X-Git-Tag: v3.2.0~536 X-Git-Url: http://zhaoyanbai.com/repos/Bv9ARM.ch10.html?a=commitdiff_plain;h=25d26d76fd0711f851bad77ee67ecf986b39f5ab;p=minix.git A few aesthetic changes to make the minix port more acceptable to upstream. - revert to upstream version of function prototypes for setting the uid and gid fields of the archive_entry. - move uid/gid overflow checks into header_common(). - use archive_set_error() instead of fprintf() for getting error message text back to the main program. --- diff --git a/lib/libarchive/archive_entry.c b/lib/libarchive/archive_entry.c index c7ddaf67f..a2364c05a 100644 --- a/lib/libarchive/archive_entry.c +++ b/lib/libarchive/archive_entry.c @@ -82,9 +82,6 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_entry.c 201096 2009-12-28 02:41: #define makedev(maj,min) ((0xff00 & ((maj)<<8)) | (0xffff00ff & (min))) #endif -#include -#include - /* Play games to come up with a suitable makedev() definition. */ #ifdef __QNXNTO__ /* QNX. */ @@ -807,27 +804,10 @@ archive_entry_copy_fflags_text_w(struct archive_entry *entry, } void -archive_entry_set_gid(struct archive_entry *entry, int g) +archive_entry_set_gid(struct archive_entry *entry, gid_t g) { entry->stat_valid = 0; entry->ae_stat.aest_gid = g; - if(entry->ae_stat.aest_gid != g) { - static int warned = 0; - static struct group *nobodygroup; - gid_t truncgroup; - if(!nobodygroup) - nobodygroup = getgrnam("nobody"); - if(nobodygroup) - truncgroup = nobodygroup->gr_gid; - else - truncgroup = 99; - if(!warned) { - fprintf(stderr, "libarchive: gid %d out of range; will be extracted as %d\n", - g, truncgroup); - warned = 1; - } - entry->ae_stat.aest_gid = truncgroup; - } } void @@ -1179,28 +1159,10 @@ archive_entry_update_symlink_utf8(struct archive_entry *entry, const char *linkn } void -archive_entry_set_uid(struct archive_entry *entry, int u) +archive_entry_set_uid(struct archive_entry *entry, uid_t u) { entry->stat_valid = 0; entry->ae_stat.aest_uid = u; - - if(entry->ae_stat.aest_uid != u) { - static int warned = 0; - static struct passwd *nobodyuser; - uid_t truncuser; - if(!nobodyuser) - nobodyuser = getpwnam("nobody"); - if(nobodyuser) - truncuser = nobodyuser->pw_uid; - else - truncuser = 99; - if(!warned) { - fprintf(stderr, "libarchive: uid %d out of range; will be extracted as %d\n", - u, truncuser); - warned = 1; - } - entry->ae_stat.aest_uid = truncuser; - } } void diff --git a/lib/libarchive/archive_entry.h b/lib/libarchive/archive_entry.h index 16b1189a1..12b224416 100644 --- a/lib/libarchive/archive_entry.h +++ b/lib/libarchive/archive_entry.h @@ -270,7 +270,7 @@ __LA_DECL const char *archive_entry_copy_fflags_text(struct archive_entry *, const char *); __LA_DECL const wchar_t *archive_entry_copy_fflags_text_w(struct archive_entry *, const wchar_t *); -__LA_DECL void archive_entry_set_gid(struct archive_entry *, int); +__LA_DECL void archive_entry_set_gid(struct archive_entry *, __LA_GID_T); __LA_DECL void archive_entry_set_gname(struct archive_entry *, const char *); __LA_DECL void archive_entry_copy_gname(struct archive_entry *, const char *); __LA_DECL void archive_entry_copy_gname_w(struct archive_entry *, const wchar_t *); @@ -315,7 +315,7 @@ __LA_DECL void archive_entry_set_symlink(struct archive_entry *, const char *); __LA_DECL void archive_entry_copy_symlink(struct archive_entry *, const char *); __LA_DECL void archive_entry_copy_symlink_w(struct archive_entry *, const wchar_t *); __LA_DECL int archive_entry_update_symlink_utf8(struct archive_entry *, const char *); -__LA_DECL void archive_entry_set_uid(struct archive_entry *, int); +__LA_DECL void archive_entry_set_uid(struct archive_entry *, __LA_UID_T); __LA_DECL void archive_entry_set_uname(struct archive_entry *, const char *); __LA_DECL void archive_entry_copy_uname(struct archive_entry *, const char *); __LA_DECL void archive_entry_copy_uname_w(struct archive_entry *, const wchar_t *); diff --git a/lib/libarchive/archive_read_support_format_tar.c b/lib/libarchive/archive_read_support_format_tar.c index e34b4e736..0469b75ea 100644 --- a/lib/libarchive/archive_read_support_format_tar.c +++ b/lib/libarchive/archive_read_support_format_tar.c @@ -26,6 +26,9 @@ #include "archive_platform.h" __FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_format_tar.c 201161 2009-12-29 05:44:39Z kientzle $"); +#include +#include + #ifdef HAVE_ERRNO_H #include #endif @@ -948,8 +951,11 @@ static int header_common(struct archive_read *a, struct tar *tar, struct archive_entry *entry, const void *h) { + int err = ARCHIVE_OK; const struct archive_entry_header_ustar *header; char tartype; + uid_t uid; + gid_t gid; (void)a; /* UNUSED */ @@ -962,8 +968,85 @@ header_common(struct archive_read *a, struct tar *tar, /* Parse out the numeric fields (all are octal) */ archive_entry_set_mode(entry, tar_atol(header->mode, sizeof(header->mode))); - archive_entry_set_uid(entry, tar_atol(header->uid, sizeof(header->uid))); - archive_entry_set_gid(entry, tar_atol(header->gid, sizeof(header->gid))); + + uid = (uid_t) tar_atol(header->uid, sizeof(header->uid)); + + /* Sanity check: uid overflow. Some systems have a limited uid_t. + * For example, Minix 3.2.0 has 16-bit uids. + */ + if (uid != tar_atol(header->uid, sizeof(header->uid))) { + + /* This isn't a fatal error, so we try to set the uid to + * the uid of the "nobody" user or 99. + */ + + static int warned = 0; + static struct passwd *nobodyuser = NULL; + + if (nobodyuser == NULL) { + nobodyuser = getpwnam("nobody"); + } + + if (nobodyuser != NULL) { + uid = nobodyuser->pw_uid; + } else { + uid = (uid_t) 99; + } + + if (warned == 0) { + archive_set_error(&a->archive, EINVAL, + "uid %ld out of range; will be extracted as %d.", + tar_atol(header->uid, sizeof(header->uid)), + uid); + + warned = 1; /* only warn once about invalid uid */ + err = ARCHIVE_WARN; + } + } + + archive_entry_set_uid(entry, uid); + + gid = (gid_t) tar_atol(header->gid, sizeof(header->gid)); + + /* Sanity check: gid overflow. Some systems have a limited gid_t. + * For example, Minix 3.2.0 has 8-bit gids. + */ + if (gid != tar_atol(header->gid, sizeof(header->gid))) { + + /* This isn't a fatal error, so we try to set the gid to + * the gid of the "nobody" or "nogroup" group or 99. + */ + + static int warned = 0; + static struct group *nobodygroup = NULL; + + if (nobodygroup == NULL) { + + nobodygroup = getgrnam("nobody"); + if (nobodygroup == NULL) { + nobodygroup = getgrnam("nogroup"); + } + } + + if (nobodygroup != NULL) { + gid = nobodygroup->gr_gid; + } else { + gid = (gid_t) 99; + } + + if (warned == 0) { + archive_set_error(&a->archive, EINVAL, + "gid %ld out of range; will be extracted as %d", + tar_atol(header->gid, sizeof(header->gid)), + gid); + + warned = 1; /* only warn once about invalid gid */ + err = ARCHIVE_WARN; + } + } + + archive_entry_set_gid(entry, gid); + tar->entry_bytes_remaining = tar_atol(header->size, sizeof(header->size)); tar->realsize = tar->entry_bytes_remaining; archive_entry_set_size(entry, tar->entry_bytes_remaining); @@ -1094,7 +1177,8 @@ header_common(struct archive_read *a, struct tar *tar, archive_entry_set_filetype(entry, AE_IFREG); break; } - return (0); + + return err; } /* @@ -1104,6 +1188,7 @@ static int header_old_tar(struct archive_read *a, struct tar *tar, struct archive_entry *entry, const void *h) { + int err; const struct archive_entry_header_ustar *header; /* Copy filename over (to ensure null termination). */ @@ -1112,10 +1197,10 @@ header_old_tar(struct archive_read *a, struct tar *tar, archive_entry_copy_pathname(entry, tar->entry_pathname.s); /* Grab rest of common fields */ - header_common(a, tar, entry, h); + err = header_common(a, tar, entry, h); tar->entry_padding = 0x1ff & (-tar->entry_bytes_remaining); - return (0); + return err; } /* @@ -1174,6 +1259,7 @@ static int header_ustar(struct archive_read *a, struct tar *tar, struct archive_entry *entry, const void *h) { + int err; const struct archive_entry_header_ustar *header; struct archive_string *as; @@ -1192,7 +1278,7 @@ header_ustar(struct archive_read *a, struct tar *tar, archive_entry_copy_pathname(entry, as->s); /* Handle rest of common fields. */ - header_common(a, tar, entry, h); + err = header_common(a, tar, entry, h); /* Handle POSIX ustar fields. */ archive_strncpy(&(tar->entry_uname), header->uname, @@ -1213,7 +1299,7 @@ header_ustar(struct archive_read *a, struct tar *tar, tar->entry_padding = 0x1ff & (-tar->entry_bytes_remaining); - return (0); + return err; } @@ -1745,6 +1831,7 @@ static int header_gnutar(struct archive_read *a, struct tar *tar, struct archive_entry *entry, const void *h) { + int err; const struct archive_entry_header_gnutar *header; (void)a; @@ -1756,7 +1843,7 @@ header_gnutar(struct archive_read *a, struct tar *tar, */ /* Grab fields common to all tar variants. */ - header_common(a, tar, entry, h); + err = header_common(a, tar, entry, h); /* Copy filename over (to ensure null termination). */ header = (const struct archive_entry_header_gnutar *)h; @@ -1806,7 +1893,7 @@ header_gnutar(struct archive_read *a, struct tar *tar, } } - return (0); + return err; } static void