1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-08-03 08:22:37 +03:00

basic: move compress.[ch] → src/basic/

The compression helpers are used both in journal code and in coredump
code, and there's a good chance we'll use them later for other stuff.

Let's hence move them into src/basic/, to make them a proper internal
API we can use from everywhere where that's desirable. (pstore might be
a candidate, for example)

No real code changes, just some moving around, build system
rearrangements, and stripping of journal-def.h inclusion.
This commit is contained in:
Lennart Poettering
2022-04-20 15:35:28 +02:00
parent 6ed7b6977f
commit acc50c92eb
16 changed files with 166 additions and 125 deletions

View File

@ -6,21 +6,10 @@
#include "compress.h"
#include "fuzz.h"
static int compress(int alg,
const void *src, uint64_t src_size,
void *dst, size_t dst_alloc_size, size_t *dst_size) {
if (alg == OBJECT_COMPRESSED_LZ4)
return compress_blob_lz4(src, src_size, dst, dst_alloc_size, dst_size);
if (alg == OBJECT_COMPRESSED_XZ)
return compress_blob_xz(src, src_size, dst, dst_alloc_size, dst_size);
return -EOPNOTSUPP;
}
typedef struct header {
uint32_t alg:2; /* We have only two compression algorithms so far, but we might add
* more in the future. Let's make this a bit wider so our fuzzer
* cases remain stable in the future. */
uint32_t alg:2; /* We have only three compression algorithms so far, but we might add more in the
* future. Let's make this a bit wider so our fuzzer cases remain stable in the
* future. */
uint32_t sw_len;
uint32_t sw_alloc;
uint32_t reserved[3]; /* Extra space to keep fuzz cases stable in case we need to
@ -46,7 +35,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
log_set_max_level(LOG_CRIT);
log_info("Using compression %s, data size=%zu",
object_compressed_to_string(alg) ?: "(none)",
compression_to_string(alg) ?: "(none)",
data_len);
buf = malloc(MAX(size, 128u)); /* Make the buffer a bit larger for very small data */
@ -56,7 +45,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
}
size_t csize;
r = compress(alg, h->data, data_len, buf, size, &csize);
r = compress_blob_explicit(alg, h->data, data_len, buf, size, &csize);
if (r < 0) {
log_error_errno(r, "Compression failed: %m");
return 0;