attempt to regularize atoi mess.
This commit is contained in:
@@ -35,7 +35,7 @@ int cpio_main(int argc, char **argv)
|
||||
/* Initialise */
|
||||
archive_handle = init_handle();
|
||||
archive_handle->src_fd = STDIN_FILENO;
|
||||
archive_handle->seek = seek_by_char;
|
||||
archive_handle->seek = seek_by_read;
|
||||
archive_handle->flags = ARCHIVE_EXTRACT_NEWER | ARCHIVE_PRESERVE_DATE;
|
||||
|
||||
opt = getopt32(argc, argv, "ituvF:dm", &cpio_filename);
|
||||
|
@@ -21,7 +21,7 @@ lib-y:= \
|
||||
\
|
||||
archive_xread_all_eof.o \
|
||||
\
|
||||
seek_by_char.o \
|
||||
seek_by_read.o \
|
||||
seek_by_jump.o \
|
||||
\
|
||||
data_align.o \
|
||||
|
@@ -46,14 +46,14 @@ char get_header_ar(archive_handle_t *archive_handle)
|
||||
|
||||
/* align the headers based on the header magic */
|
||||
if ((ar.formatted.magic[0] != '`') || (ar.formatted.magic[1] != '\n')) {
|
||||
bb_error_msg_and_die("Invalid ar header");
|
||||
bb_error_msg_and_die("invalid ar header");
|
||||
}
|
||||
|
||||
typed->mode = strtol(ar.formatted.mode, NULL, 8);
|
||||
typed->mtime = atoi(ar.formatted.date);
|
||||
typed->uid = atoi(ar.formatted.uid);
|
||||
typed->gid = atoi(ar.formatted.gid);
|
||||
typed->size = atoi(ar.formatted.size);
|
||||
typed->mode = xstrtoul(ar.formatted.mode, 8);
|
||||
typed->mtime = xatou(ar.formatted.date);
|
||||
typed->uid = xatou(ar.formatted.uid);
|
||||
typed->gid = xatou(ar.formatted.gid);
|
||||
typed->size = xatoul(ar.formatted.size);
|
||||
|
||||
/* long filenames have '/' as the first character */
|
||||
if (ar.formatted.name[0] == '/') {
|
||||
|
@@ -62,10 +62,10 @@ char get_header_tar(archive_handle_t *archive_handle)
|
||||
* Read until the end to empty the pipe from gz or bz2
|
||||
*/
|
||||
while (full_read(archive_handle->src_fd, tar.raw, 512) == 512);
|
||||
return(EXIT_FAILURE);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
end = 1;
|
||||
return(EXIT_SUCCESS);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
end = 0;
|
||||
|
||||
@@ -76,19 +76,18 @@ char get_header_tar(archive_handle_t *archive_handle)
|
||||
#ifdef CONFIG_FEATURE_TAR_OLDGNU_COMPATIBILITY
|
||||
if (strncmp(tar.formatted.magic, "\0\0\0\0\0", 5) != 0)
|
||||
#endif
|
||||
bb_error_msg_and_die("Invalid tar magic");
|
||||
bb_error_msg_and_die("invalid tar magic");
|
||||
}
|
||||
/* Do checksum on headers */
|
||||
for (i = 0; i < 148 ; i++) {
|
||||
sum += tar.raw[i];
|
||||
}
|
||||
sum += ' ' * 8;
|
||||
for (i = 156; i < 512 ; i++) {
|
||||
for (i = 156; i < 512 ; i++) {
|
||||
sum += tar.raw[i];
|
||||
}
|
||||
if (sum != strtol(tar.formatted.chksum, NULL, 8)) {
|
||||
bb_error_msg("Invalid tar header checksum");
|
||||
return(EXIT_FAILURE);
|
||||
if (sum != xstrtoul(tar.formatted.chksum, 8)) {
|
||||
bb_error_msg_and_die("invalid tar header checksum");
|
||||
}
|
||||
|
||||
#ifdef CONFIG_FEATURE_TAR_GNU_EXTENSIONS
|
||||
@@ -102,8 +101,7 @@ char get_header_tar(archive_handle_t *archive_handle)
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
file_header->name = xstrndup(tar.formatted.name,100);
|
||||
|
||||
file_header->name = xstrndup(tar.formatted.name, 100);
|
||||
if (tar.formatted.prefix[0]) {
|
||||
char *temp = file_header->name;
|
||||
file_header->name = concat_path_file(tar.formatted.prefix, temp);
|
||||
@@ -111,17 +109,18 @@ char get_header_tar(archive_handle_t *archive_handle)
|
||||
}
|
||||
}
|
||||
|
||||
file_header->uid = strtol(tar.formatted.uid, NULL, 8);
|
||||
file_header->gid = strtol(tar.formatted.gid, NULL, 8);
|
||||
file_header->size = strtol(tar.formatted.size, NULL, 8);
|
||||
file_header->mtime = strtol(tar.formatted.mtime, NULL, 8);
|
||||
file_header->link_name = (tar.formatted.linkname[0] != '\0') ?
|
||||
xstrdup(tar.formatted.linkname) : NULL;
|
||||
file_header->device = makedev(strtol(tar.formatted.devmajor, NULL, 8),
|
||||
strtol(tar.formatted.devminor, NULL, 8));
|
||||
file_header->uid = xstrtoul(tar.formatted.uid, 8);
|
||||
file_header->gid = xstrtoul(tar.formatted.gid, 8);
|
||||
// TODO: LFS support
|
||||
file_header->size = xstrtoul(tar.formatted.size, 8);
|
||||
file_header->mtime = xstrtoul(tar.formatted.mtime, 8);
|
||||
file_header->link_name = tar.formatted.linkname[0] ?
|
||||
xstrdup(tar.formatted.linkname) : NULL;
|
||||
file_header->device = makedev(xstrtoul(tar.formatted.devmajor, 8),
|
||||
xstrtoul(tar.formatted.devminor, 8));
|
||||
|
||||
/* Set bits 0-11 of the files mode */
|
||||
file_header->mode = 07777 & strtol(tar.formatted.mode, NULL, 8);
|
||||
file_header->mode = 07777 & xstrtoul(tar.formatted.mode, 8);
|
||||
|
||||
/* Set bits 12-15 of the files mode */
|
||||
switch (tar.formatted.typeflag) {
|
||||
@@ -161,7 +160,7 @@ char get_header_tar(archive_handle_t *archive_handle)
|
||||
xread(archive_handle->src_fd, longname, file_header->size);
|
||||
archive_handle->offset += file_header->size;
|
||||
|
||||
return(get_header_tar(archive_handle));
|
||||
return get_header_tar(archive_handle);
|
||||
}
|
||||
case 'K': {
|
||||
linkname = xzalloc(file_header->size + 1);
|
||||
@@ -169,7 +168,7 @@ char get_header_tar(archive_handle_t *archive_handle)
|
||||
archive_handle->offset += file_header->size;
|
||||
|
||||
file_header->name = linkname;
|
||||
return(get_header_tar(archive_handle));
|
||||
return get_header_tar(archive_handle);
|
||||
}
|
||||
case 'D': /* GNU dump dir */
|
||||
case 'M': /* Continuation of multi volume archive*/
|
||||
@@ -179,10 +178,10 @@ char get_header_tar(archive_handle_t *archive_handle)
|
||||
#endif
|
||||
case 'g': /* pax global header */
|
||||
case 'x': /* pax extended header */
|
||||
bb_error_msg("Ignoring extension type %c", tar.formatted.typeflag);
|
||||
bb_error_msg("ignoring extension type %c", tar.formatted.typeflag);
|
||||
break;
|
||||
default:
|
||||
bb_error_msg("Unknown typeflag: 0x%x", tar.formatted.typeflag);
|
||||
bb_error_msg("unknown typeflag: 0x%x", tar.formatted.typeflag);
|
||||
}
|
||||
{ /* Strip trailing '/' in directories */
|
||||
/* Must be done after mode is set as '/' is used to check if its a directory */
|
||||
@@ -204,5 +203,5 @@ char get_header_tar(archive_handle_t *archive_handle)
|
||||
|
||||
free(file_header->link_name);
|
||||
|
||||
return(EXIT_SUCCESS);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
@@ -16,12 +16,12 @@
|
||||
char get_header_tar_bz2(archive_handle_t *archive_handle)
|
||||
{
|
||||
/* Cant lseek over pipe's */
|
||||
archive_handle->seek = seek_by_char;
|
||||
archive_handle->seek = seek_by_read;
|
||||
|
||||
archive_handle->src_fd = open_transformer(archive_handle->src_fd, uncompressStream);
|
||||
archive_handle->offset = 0;
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS);
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS) /**/;
|
||||
|
||||
/* Can only do one file at a time */
|
||||
return(EXIT_FAILURE);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
@@ -13,7 +13,7 @@ char get_header_tar_gz(archive_handle_t *archive_handle)
|
||||
unsigned char magic[2];
|
||||
|
||||
/* Cant lseek over pipe's */
|
||||
archive_handle->seek = seek_by_char;
|
||||
archive_handle->seek = seek_by_read;
|
||||
|
||||
xread(archive_handle->src_fd, &magic, 2);
|
||||
if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
|
||||
@@ -24,8 +24,8 @@ char get_header_tar_gz(archive_handle_t *archive_handle)
|
||||
|
||||
archive_handle->src_fd = open_transformer(archive_handle->src_fd, inflate_gunzip);
|
||||
archive_handle->offset = 0;
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS);
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS) /**/;
|
||||
|
||||
/* Can only do one file at a time */
|
||||
return(EXIT_FAILURE);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
@@ -11,13 +11,12 @@
|
||||
char get_header_tar_lzma(archive_handle_t * archive_handle)
|
||||
{
|
||||
/* Can't lseek over pipes */
|
||||
archive_handle->seek = seek_by_char;
|
||||
archive_handle->seek = seek_by_read;
|
||||
|
||||
archive_handle->src_fd = open_transformer(archive_handle->src_fd, unlzma);
|
||||
archive_handle->offset = 0;
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS);
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS) /**/;
|
||||
|
||||
/* Can only do one file at a time */
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
@@ -16,7 +16,7 @@ void seek_by_jump(const archive_handle_t *archive_handle, const unsigned int amo
|
||||
if (lseek(archive_handle->src_fd, (off_t) amount, SEEK_CUR) == (off_t) -1) {
|
||||
#ifdef CONFIG_FEATURE_UNARCHIVE_TAPE
|
||||
if (errno == ESPIPE) {
|
||||
seek_by_char(archive_handle, amount);
|
||||
seek_by_read(archive_handle, amount);
|
||||
} else
|
||||
#endif
|
||||
bb_perror_msg_and_die("Seek failure");
|
||||
|
@@ -8,14 +8,10 @@
|
||||
#include "unarchive.h"
|
||||
#include "libbb.h"
|
||||
|
||||
|
||||
|
||||
/* If we are reading through a pipe(), or from stdin then we cant lseek,
|
||||
/* If we are reading through a pipe(), or from stdin then we cant lseek,
|
||||
* we must read and discard the data to skip over it.
|
||||
*
|
||||
* TODO: rename to seek_by_read
|
||||
*/
|
||||
void seek_by_char(const archive_handle_t *archive_handle, const unsigned int jump_size)
|
||||
void seek_by_read(const archive_handle_t *archive_handle, const unsigned int jump_size)
|
||||
{
|
||||
if (jump_size) {
|
||||
bb_copyfd_size(archive_handle->src_fd, -1, jump_size);
|
@@ -173,7 +173,7 @@ static void extract_cpio_gz(int fd) {
|
||||
|
||||
/* Initialise */
|
||||
archive_handle = init_handle();
|
||||
archive_handle->seek = seek_by_char;
|
||||
archive_handle->seek = seek_by_read;
|
||||
//archive_handle->action_header = header_list;
|
||||
archive_handle->action_data = data_extract_all;
|
||||
archive_handle->flags |= ARCHIVE_PRESERVE_DATE;
|
||||
|
@@ -541,7 +541,7 @@ static llist_t *append_file_list_to_list(llist_t *list)
|
||||
static char get_header_tar_Z(archive_handle_t *archive_handle)
|
||||
{
|
||||
/* Cant lseek over pipe's */
|
||||
archive_handle->seek = seek_by_char;
|
||||
archive_handle->seek = seek_by_read;
|
||||
|
||||
/* do the decompression, and cleanup */
|
||||
if (xread_char(archive_handle->src_fd) != 0x1f ||
|
||||
@@ -805,7 +805,7 @@ int tar_main(int argc, char **argv)
|
||||
|
||||
if ((tar_filename[0] == '-') && (tar_filename[1] == '\0')) {
|
||||
tar_handle->src_fd = fileno(tar_stream);
|
||||
tar_handle->seek = seek_by_char;
|
||||
tar_handle->seek = seek_by_read;
|
||||
} else {
|
||||
tar_handle->src_fd = xopen3(tar_filename, flags, 0666);
|
||||
}
|
||||
|
@@ -51,11 +51,12 @@ typedef union {
|
||||
} formatted ATTRIBUTE_PACKED;
|
||||
} zip_header_t;
|
||||
|
||||
/* This one never works with LARGEFILE-sized skips */
|
||||
static void unzip_skip(int fd, off_t skip)
|
||||
{
|
||||
if (lseek(fd, skip, SEEK_CUR) == (off_t)-1) {
|
||||
if ((errno != ESPIPE) || (bb_copyfd_size(fd, -1, skip) != skip)) {
|
||||
bb_error_msg_and_die("Seek failure");
|
||||
bb_error_msg_and_die("seek failure");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -65,7 +66,7 @@ static void unzip_create_leading_dirs(char *fn)
|
||||
/* Create all leading directories */
|
||||
char *name = xstrdup(fn);
|
||||
if (bb_make_directory(dirname(name), 0777, FILEUTILS_RECUR)) {
|
||||
bb_error_msg_and_die("Exiting"); /* bb_make_directory is noisy */
|
||||
bb_error_msg_and_die("exiting"); /* bb_make_directory is noisy */
|
||||
}
|
||||
free(name);
|
||||
}
|
||||
@@ -76,7 +77,7 @@ static int unzip_extract(zip_header_t *zip_header, int src_fd, int dst_fd)
|
||||
/* Method 0 - stored (not compressed) */
|
||||
int size = zip_header->formatted.ucmpsize;
|
||||
if (size && (bb_copyfd_size(src_fd, dst_fd, size) != size)) {
|
||||
bb_error_msg_and_die("Cannot complete extraction");
|
||||
bb_error_msg_and_die("cannot complete extraction");
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -86,12 +87,12 @@ static int unzip_extract(zip_header_t *zip_header, int src_fd, int dst_fd)
|
||||
inflate_cleanup();
|
||||
/* Validate decompression - crc */
|
||||
if (zip_header->formatted.crc32 != (gunzip_crc ^ 0xffffffffL)) {
|
||||
bb_error_msg("Invalid compressed data--crc error");
|
||||
bb_error_msg("invalid compressed data--%s error", "crc");
|
||||
return 1;
|
||||
}
|
||||
/* Validate decompression - size */
|
||||
if (zip_header->formatted.ucmpsize != gunzip_bytes_out) {
|
||||
bb_error_msg("Invalid compressed data--length error");
|
||||
bb_error_msg("invalid compressed data--%s error", "length");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user