diff options
author | Emil Velikov <emil.l.velikov@gmail.com> | 2021-10-23 18:22:05 +0100 |
---|---|---|
committer | Emil Velikov <emil.l.velikov@gmail.com> | 2021-10-23 19:26:23 +0100 |
commit | 5b5f6b591bced6037959945f69ab46466abd1698 (patch) | |
tree | 0ca11fbd330c1fd1aa1a19daea93a50948fb2992 /libarchive/archive_read_support_filter_program.c | |
parent | 64b82ac5c8cb5d822962af988dd075331d997b79 (diff) | |
download | libarchive-5b5f6b591bced6037959945f69ab46466abd1698.tar.gz |
reader: transform get_bidder into register_bidder
There's a notable duplication across all the read bidder code.
Check the archive magic/state, set the bidder private data (to NULL in
all but one case), name and vtable.
Change the helper to do the actual registration, keeping things simpler
in the dozen+ filters. This also allows us to enforce the bidder ::bid
and ::init dispatch are non NULL. The final one ::free is optional.
NOTE: some of the bidders do _not_ set a name, which I suspect is a
pre-existing bug. I've left them as-is, but we might want to fix and
enforce that somehow.
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Diffstat (limited to 'libarchive/archive_read_support_filter_program.c')
-rw-r--r-- | libarchive/archive_read_support_filter_program.c | 40 |
1 files changed, 13 insertions, 27 deletions
diff --git a/libarchive/archive_read_support_filter_program.c b/libarchive/archive_read_support_filter_program.c index 85540387..5d9d0719 100644 --- a/libarchive/archive_read_support_filter_program.c +++ b/libarchive/archive_read_support_filter_program.c @@ -130,40 +130,14 @@ program_bidder_vtable = { .free = program_bidder_free, }; -static int -set_bidder_signature(struct archive_read_filter_bidder *bidder, - struct program_bidder *state, const void *signature, size_t signature_len) -{ - - if (signature != NULL && signature_len > 0) { - state->signature_len = signature_len; - state->signature = malloc(signature_len); - memcpy(state->signature, signature, signature_len); - } - - /* - * Fill in the bidder object. - */ - bidder->data = state; - bidder->vtable = &program_bidder_vtable; - return (ARCHIVE_OK); -} - int archive_read_support_filter_program_signature(struct archive *_a, const char *cmd, const void *signature, size_t signature_len) { struct archive_read *a = (struct archive_read *)_a; - struct archive_read_filter_bidder *bidder; struct program_bidder *state; /* - * Get a bidder object from the read core. - */ - if (__archive_read_get_bidder(a, &bidder) != ARCHIVE_OK) - return (ARCHIVE_FATAL); - - /* * Allocate our private state. */ state = (struct program_bidder *)calloc(1, sizeof (*state)); @@ -173,7 +147,19 @@ archive_read_support_filter_program_signature(struct archive *_a, if (state->cmd == NULL) goto memerr; - return set_bidder_signature(bidder, state, signature, signature_len); + if (signature != NULL && signature_len > 0) { + state->signature_len = signature_len; + state->signature = malloc(signature_len); + memcpy(state->signature, signature, signature_len); + } + + if (__archive_read_register_bidder(a, state, NULL, + &program_bidder_vtable) != ARCHIVE_OK) { + free_state(state); + return (ARCHIVE_FATAL); + } + return (ARCHIVE_OK); + memerr: free_state(state); archive_set_error(_a, ENOMEM, "Can't allocate memory"); |