Skip to content

Commit

Permalink
Merging libarchive 3.2.2 with Fornux C Leak Detector
Browse files Browse the repository at this point in the history
  • Loading branch information
philippeb8 committed Dec 24, 2017
1 parent 6293581 commit 5858b5c
Show file tree
Hide file tree
Showing 107 changed files with 4,261 additions and 1,604 deletions.
10 changes: 10 additions & 0 deletions README.md
Expand Up @@ -5,6 +5,16 @@ can read and write streaming archives in a variety of formats. It
also includes implementations of the common `tar`, `cpio`, and `zcat`
command-line tools that use the libarchive library.

## Fornux C Leak Detector Diagnosis

[2017-12-24 16:20:04.536311] [0x00007fd0b34f3fc0] [info] <cycle>: 0# archive_read_open_filenames(boost::node_proxy&, boost::root_ptr<std::vector<archive, std::allocator<archive> > >, boost::root_ptr<std::vector<boost::root_ptr<std::vector<char, std::allocator<char> > >, std::allocator<boost::root_ptr<std::vector<char, std::allocator<char> > > > > >, unsigned long) at /home/philippeb8/devel/1/libarchive-3.2.2/libarchive/archive_read_open_filename.c:164

[2017-12-24 16:20:04.614519] [0x00007fd0b34f3fc0] [info] "p": 0# gnu_clear_sparse_list(boost::node_proxy&, boost::root_ptr<std::vector<tar, std::allocator<tar> > >) at /home/philippeb8/devel/1/libarchive-3.2.2/libarchive/archive_read_support_format_tar.c:2119

[2017-12-24 16:20:04.677372] [0x00007fd0b34f3fc0] [info] "tar": 0# archive_read_format_tar_cleanup(boost::node_proxy&, boost::root_ptr<std::vector<archive_read, std::allocator<archive_read> > >) at /home/philippeb8/devel/1/libarchive-3.2.2/libarchive/archive_read_support_format_tar.c:237

[2017-12-24 16:20:04.734981] [0x00007fd0b34f3fc0] [info] "client_buff": 0# ~archive_read_filter at /home/philippeb8/devel/1/libarchive-3.2.2/libarchive/archive_read_private.h:82

## Questions? Issues?

* http://www.libarchive.org is the home for ongoing
Expand Down
2 changes: 2 additions & 0 deletions configure.sh
@@ -0,0 +1,2 @@
#!/bin/bash
CC=/usr/local/bin/fcldc.sh CFLAGS="-isystem libarchive/system/" ./configure -C --disable-bsdtar --disable-bsdcpio --disable-bsdcat
20 changes: 15 additions & 5 deletions examples/untar.c
Expand Up @@ -63,6 +63,11 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define __LIBARCHIVE_BUILD 1
#include "archive_private.h"
#include "archive_read_private.h"
#include "archive_entry_private.h"
#include "archive_write_disk_private.h"

static void errmsg(const char *);
static void extract(const char *filename, int do_extract, int flags);
Expand All @@ -75,7 +80,7 @@ static void warn(const char *, const char *);
static int verbose = 0;

int
main(int argc, const char **argv)
main(int argc, char **argv)
{
const char *filename = NULL;
int compress, flags, mode, opt;
Expand Down Expand Up @@ -136,12 +141,16 @@ static void
extract(const char *filename, int do_extract, int flags)
{
struct archive *a;
struct archive_read *ar;
struct archive_write_disk *aw;
struct archive *ext;
struct archive_entry *entry;
int r;

a = archive_read_new();
ext = archive_write_disk_new();
ar = archive_read_new();
a = & ar->archive;
aw = archive_write_disk_new();
ext = & aw->archive;
archive_write_disk_set_options(ext, flags);
/*
* Note: archive_write_disk_set_standard_lookup() is useful
Expand All @@ -157,10 +166,11 @@ extract(const char *filename, int do_extract, int flags)
*/
if (filename != NULL && strcmp(filename, "-") == 0)
filename = NULL;
if ((r = archive_read_open_filename(a, filename, 10240)))

if ((r = archive_read_open_filename(a, filename, 10240)))
fail("archive_read_open_filename()",
archive_error_string(a), r);
for (;;) {
for (;;) {
r = archive_read_next_header(a, &entry);
if (r == ARCHIVE_EOF)
break;
Expand Down
47 changes: 45 additions & 2 deletions libarchive/archive.h
Expand Up @@ -43,6 +43,9 @@
#include <stdio.h> /* For FILE * */
#include <time.h> /* For time_t */

#define _offsetof(type, member) (&(((type *)NULL)->member))
#define _containerof(ptr, type, member) ((type *)(void *)((char *)(void *)(ptr) - (char *)(void *)_offsetof(type, member)))

/*
* Note: archive.h is for use outside of libarchive; the configuration
* headers (config.h, archive_platform.h, etc.) are purely internal.
Expand Down Expand Up @@ -181,6 +184,7 @@ __LA_DECL const char * archive_liblz4_version(void);
/* Declare our basic types. */
struct archive;
struct archive_entry;
struct archive_write_disk;

/*
* Error codes: Use archive_errno() and archive_error_string()
Expand Down Expand Up @@ -375,7 +379,7 @@ typedef const char *archive_passphrase_callback(struct archive *,
* data for entries of interest.
* 5) Call archive_read_finish to end processing.
*/
__LA_DECL struct archive *archive_read_new(void);
__LA_DECL struct archive_read *archive_read_new(void);

/*
* The archive_read_support_XXX calls enable auto-detect for this
Expand Down Expand Up @@ -894,7 +898,7 @@ __LA_DECL int archive_write_set_passphrase_callback(struct archive *,
* In particular, you can use this in conjunction with archive_read()
* to pull entries out of an archive and create them on disk.
*/
__LA_DECL struct archive *archive_write_disk_new(void);
__LA_DECL struct archive_write_disk *archive_write_disk_new(void);
/* This file will not be overwritten. */
__LA_DECL int archive_write_disk_set_skip_file(struct archive *,
la_int64_t, la_int64_t);
Expand Down Expand Up @@ -1173,6 +1177,45 @@ __LA_DECL int archive_match_include_gname_w(struct archive *,
/* Convenience function to sort a NULL terminated list of strings */
__LA_DECL int archive_utility_string_sort(char **);

/*
* Basic resizable/reusable string support similar to Java's "StringBuffer."
*
* Unlike sbuf(9), the buffers here are fully reusable and track the
* length throughout.
*/

struct archive_string {
char *s; /* Pointer to the storage */
size_t length; /* Length of 's' in characters */
size_t buffer_length; /* Length of malloc-ed storage in bytes. */
};

struct archive_wstring {
wchar_t *s; /* Pointer to the storage */
size_t length; /* Length of 's' in characters */
size_t buffer_length; /* Length of malloc-ed storage in bytes. */
};

/* A "multistring" can hold Unicode, UTF8, or MBS versions of
* the string. If you set and read the same version, no translation
* is done. If you set and read different versions, the library
* will attempt to transparently convert.
*/
struct archive_mstring {
struct archive_string aes_mbs;
struct archive_string aes_utf8;
struct archive_wstring aes_wcs;
struct archive_string aes_mbs_in_locale;
/* Bitmap of which of the above are valid. Because we're lazy
* about malloc-ing and reusing the underlying storage, we
* can't rely on NULL pointers to indicate whether a string
* has been set. */
int aes_set;
#define AES_SET_MBS 1
#define AES_SET_UTF8 2
#define AES_SET_WCS 4
};

#ifdef __cplusplus
}
#endif
Expand Down
24 changes: 15 additions & 9 deletions libarchive/archive_acl.c
Expand Up @@ -821,15 +821,18 @@ append_entry(char **p, const char *prefix, int tag,
* indicate the type that should be used for any entries not
* explicitly marked as "default:".
*/
struct archive_acl_parse_w_range {
const wchar_t *start;
const wchar_t *end;
};

int
archive_acl_parse_w(struct archive_acl *acl,
const wchar_t *text, int default_type)
{
struct {
const wchar_t *start;
const wchar_t *end;
} field[4], name;

struct archive_acl_parse_w_range field[4];
struct archive_acl_parse_w_range name;

int fields, n;
int type, tag, permset, id;
wchar_t sep;
Expand Down Expand Up @@ -1051,14 +1054,17 @@ prefix_w(const wchar_t *start, const wchar_t *end, const wchar_t *test)
* indicate the type that should be used for any entries not
* explicitly marked as "default:".
*/
struct archive_acl_parse_l_range {
const char *start;
const char *end;
};

int
archive_acl_parse_l(struct archive_acl *acl,
const char *text, int default_type, struct archive_string_conv *sc)
{
struct {
const char *start;
const char *end;
} field[4], name;
struct archive_acl_parse_l_range field[4];
struct archive_acl_parse_l_range name;

int fields, n, r, ret = ARCHIVE_OK;
int type, tag, permset, id;
Expand Down
6 changes: 3 additions & 3 deletions libarchive/archive_cryptor.c
Expand Up @@ -76,8 +76,8 @@ pbkdf2_sha1(const char *pw, size_t pw_len, const uint8_t *salt,
return -1;

status = BCryptDeriveKeyPBKDF2(hAlg,
(PUCHAR)(uintptr_t)pw, (ULONG)pw_len,
(PUCHAR)(uintptr_t)salt, (ULONG)salt_len, rounds,
(PUCHAR)pw, (ULONG)pw_len,
(PUCHAR)salt, (ULONG)salt_len, rounds,
(PUCHAR)derived_key, (ULONG)derived_key_len, 0);

BCryptCloseAlgorithmProvider(hAlg, 0);
Expand Down Expand Up @@ -225,7 +225,7 @@ aes_ctr_init(archive_crypto_ctx *ctx, const uint8_t *key, size_t key_len)
}
status = BCryptGenerateSymmetricKey(hAlg, &hKey,
keyObj, keyObj_len,
(PUCHAR)(uintptr_t)key, (ULONG)key_len, 0);
(PUCHAR)key, (ULONG)key_len, 0);
if (!BCRYPT_SUCCESS(status)) {
BCryptCloseAlgorithmProvider(hAlg, 0);
HeapFree(GetProcessHeap(), 0, keyObj);
Expand Down
2 changes: 1 addition & 1 deletion libarchive/archive_digest.c
Expand Up @@ -82,7 +82,7 @@ win_crypto_Update(Digest_CTX *ctx, const unsigned char *buf, size_t len)
return (ARCHIVE_FAILED);

CryptHashData(ctx->hash,
(unsigned char *)(uintptr_t)buf,
(unsigned char *)buf,
(DWORD)len, 0);
return (ARCHIVE_OK);
}
Expand Down
12 changes: 8 additions & 4 deletions libarchive/archive_entry.h
Expand Up @@ -40,8 +40,10 @@
*/

#include <sys/types.h>
#include <sys/stat.h>
#include <stddef.h> /* for wchar_t */
#include <time.h>
#include <unistd.h>

#if defined(_WIN32) && !defined(__CYGWIN__)
#include <windows.h>
Expand Down Expand Up @@ -111,7 +113,7 @@ extern "C" {
/*
* Description of an archive entry.
*
* You can think of this as "struct stat" with some text fields added in.
* You can think of this as "stat_" with some text fields added in.
*
* TODO: Add "comment", "charset", and possibly other entries that are
* supported by "pax interchange" format. However, GNU, ustar, cpio,
Expand All @@ -127,6 +129,8 @@ extern "C" {
struct archive;
struct archive_entry;

typedef struct stat stat_;

/*
* File-type constants. These are returned from archive_entry_filetype()
* and passed to archive_entry_set_filetype().
Expand Down Expand Up @@ -335,7 +339,7 @@ __LA_DECL void archive_entry_set_is_data_encrypted(struct archive_entry *, char
__LA_DECL void archive_entry_set_is_metadata_encrypted(struct archive_entry *, char is_encrypted);
/*
* Routines to bulk copy fields to/from a platform-native "struct
* stat." Libarchive used to just store a struct stat inside of each
* stat." Libarchive used to just store a stat_ inside of each
* archive_entry object, but this created issues when trying to
* manipulate archives on systems different than the ones they were
* created on.
Expand All @@ -345,8 +349,8 @@ __LA_DECL void archive_entry_set_is_metadata_encrypted(struct archive_entry *, c
* that archive_entry_stat is magically defined to
* archive_entry_stat32 or archive_entry_stat64 as appropriate.
*/
__LA_DECL const struct stat *archive_entry_stat(struct archive_entry *);
__LA_DECL void archive_entry_copy_stat(struct archive_entry *, const struct stat *);
__LA_DECL const stat_ *archive_entry_stat(struct archive_entry *);
__LA_DECL void archive_entry_copy_stat(struct archive_entry *, const stat_ *);

/*
* Storage for Mac OS-specific AppleDouble metadata information.
Expand Down
5 changes: 4 additions & 1 deletion libarchive/archive_entry_link_resolver.c
Expand Up @@ -42,6 +42,8 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_entry_link_resolver.c 201100 200

#include "archive.h"
#include "archive_entry.h"
#include "archive_private.h"
#include "archive_entry_private.h"

/*
* This is mostly a pretty straightforward hash table implementation.
Expand Down Expand Up @@ -383,7 +385,8 @@ insert_entry(struct archive_entry_linkresolver *res,
static void
grow_hash(struct archive_entry_linkresolver *res)
{
struct links_entry *le, **new_buckets;
struct links_entry *le;
struct links_entry **new_buckets;
size_t new_size;
size_t i, bucket;

Expand Down
64 changes: 33 additions & 31 deletions libarchive/archive_entry_private.h
Expand Up @@ -70,6 +70,38 @@ struct ae_sparse {
*
* TODO: Design a good API for handling sparse files.
*/
struct aest {
int64_t aest_atime;
uint32_t aest_atime_nsec;
int64_t aest_ctime;
uint32_t aest_ctime_nsec;
int64_t aest_mtime;
uint32_t aest_mtime_nsec;
int64_t aest_birthtime;
uint32_t aest_birthtime_nsec;
int64_t aest_gid;
int64_t aest_ino;
uint32_t aest_nlink;
uint64_t aest_size;
int64_t aest_uid;
/*
* Because converting between device codes and
* major/minor values is platform-specific and
* inherently a bit risky, we only do that conversion
* lazily. That way, we will do a better job of
* preserving information in those cases where no
* conversion is actually required.
*/
int aest_dev_is_broken_down;
dev_t aest_dev;
dev_t aest_devmajor;
dev_t aest_devminor;
int aest_rdev_is_broken_down;
dev_t aest_rdev;
dev_t aest_rdevmajor;
dev_t aest_rdevminor;
};

struct archive_entry {
struct archive *archive;

Expand All @@ -96,37 +128,7 @@ struct archive_entry {
void *stat;
int stat_valid; /* Set to 0 whenever a field in aest changes. */

struct aest {
int64_t aest_atime;
uint32_t aest_atime_nsec;
int64_t aest_ctime;
uint32_t aest_ctime_nsec;
int64_t aest_mtime;
uint32_t aest_mtime_nsec;
int64_t aest_birthtime;
uint32_t aest_birthtime_nsec;
int64_t aest_gid;
int64_t aest_ino;
uint32_t aest_nlink;
uint64_t aest_size;
int64_t aest_uid;
/*
* Because converting between device codes and
* major/minor values is platform-specific and
* inherently a bit risky, we only do that conversion
* lazily. That way, we will do a better job of
* preserving information in those cases where no
* conversion is actually required.
*/
int aest_dev_is_broken_down;
dev_t aest_dev;
dev_t aest_devmajor;
dev_t aest_devminor;
int aest_rdev_is_broken_down;
dev_t aest_rdev;
dev_t aest_rdevmajor;
dev_t aest_rdevminor;
} ae_stat;
struct aest ae_stat;

int ae_set; /* bitmap of fields that are currently set */
#define AE_SET_HARDLINK 1
Expand Down
2 changes: 2 additions & 0 deletions libarchive/archive_entry_stat.c
Expand Up @@ -33,7 +33,9 @@ __FBSDID("$FreeBSD: head/lib/libarchive/archive_entry_stat.c 201100 2009-12-28 0
#include <stdlib.h>
#endif

#include "archive.h"
#include "archive_entry.h"
#include "archive_private.h"
#include "archive_entry_private.h"

const struct stat *
Expand Down
1 change: 1 addition & 0 deletions libarchive/archive_entry_strmode.c
Expand Up @@ -34,6 +34,7 @@ __FBSDID("$FreeBSD: src/lib/libarchive/archive_entry_strmode.c,v 1.4 2008/06/15
#endif

#include "archive_entry.h"
#include "archive_private.h"
#include "archive_entry_private.h"

const char *
Expand Down

0 comments on commit 5858b5c

Please sign in to comment.