summaryrefslogtreecommitdiffstats
path: root/src/fuzz (follow)
Commit message (Collapse)AuthorAgeFilesLines
* sd-varlink: make our internal Varlink API public as sd-varlink.[ch]Lennart Poettering2024-07-162-18/+21
| | | | | | | | | | It's time. sd-json was already done earlier in this cycle, let's now make sd-varlink public too. This is mostly just a search/replace job of epical proportions. I left some functions internal (mostly IDL handling), and I turned some static inline calls into regular calls.
* libsystemd: turn json.[ch] into a public APILennart Poettering2024-06-124-63/+69
| | | | | | | | | | | | | | | This is preparation for making our Varlink API a public API. Since our Varlink API is built on top of our JSON API we need to make that public first (it's a nice API, but JSON APIs there are already enough, this is purely about the Varlink angle). I made most of the json.h APIs public, and just placed them in sd-json.h. Sometimes I wasn't so sure however, since the underlying data structures would have to be made public too. If in doubt I didn#t risk it, and moved the relevant API to src/libsystemd/sd-json/json-util.h instead (without any sd_* symbol prefixes). This is mostly a giant search/replace patch.
* tree-wide: Use log_setup() everywhereDaan De Meyer2024-04-251-2/+1
| | | | | Otherwise the default log target is the console and we won't use the journal socket even if it is available.
* test: make assert_return() critical by default on fuzzer and unit testsYu Watanabe2023-12-231-0/+1
| | | | | | Several test cases intentionally trigger assert_return(). So, to avoid the entire test fails, this introduces several macros that tentatively make assert_return() not critical.
* fuzz: limit the interface definition input size to 64KFrantisek Sumsal2023-11-031-0/+3
| | | | | | To avoid timeouts with larger inputs. Resolves: #29856
* varlink,json: introduce new varlink_dispatch() helperLennart Poettering2023-11-021-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | varlink_dispatch() is a simple wrapper around json_dispatch() that returns clean, standards-compliant InvalidParameter error back to clients, if the specified JSON cannot be parsed properly. For this json_dispatch() is extended to return the offending field's name. Because it already has quite a few parameters, I then renamed json_dispatch() to json_dispatch_full() and made json_dispatch() a wrapper around it that passes the new argument as NULL. While doing so I figured we should also get rid of the bad= argument in the short wrapper, since it's only used in the OCI code. To simplify the OCI code this adds a second wrapper oci_dispatch() around json_dispatch_full(), that fills in bad= the way we want. Net result: instead of one json_dispatch() call there are now: 1. json_dispatch_full() for the fully feature mother of all dispathers. 2. json_dispatch() for the simpler version that you want to use most of the time. 3. varlink_dispatch() that generates nice Varlink errors 4. oci_dispatch() that does the OCI specific error handling And that's all there is.
* fd-uitl: rename PIPE_EBADF → EBADF_PAIR, and add EBADF_TRIPLETLennart Poettering2023-10-261-1/+1
| | | | | | | | We use it for more than just pipe() arrays. For example also for socketpair(). Hence let's give it a generic name. Also add EBADF_TRIPLET to mirror this for things like stdin/stdout/stderr arrays, which we use a bunch of times.
* iovec-util: make IOVEC_INCREMENT a regular function tooLennart Poettering2023-10-201-1/+1
| | | | | | Even more than with the previous commit, this is not a trivial function and there's no reason to believe this will actually be inlined nor that it would be beneficial.
* io-util: split out "struct iovec" related calls into their own .c/.h filesLennart Poettering2023-10-201-1/+1
| | | | | | | | | This is preparation for #28891, which adds a bunch more helpers around "struct iovec", at which point this really deserves its own .c/.h file. The idea is that we sooner or later can consider "struct iovec" as an entirely generic mechanism to reference some binary blob, and is the go-to type for this purpose whenever we need one.
* fuzz: unify logging setupFrantisek Sumsal2023-10-1913-31/+21
| | | | | | | | | | Make sure we don't log anything when running in "fuzzing" mode. Also, when at it, unify the setup logic into a helper, pretty similar to the test_setup_logging() one. Addresses: - https://github.com/systemd/systemd/pull/29558#pullrequestreview-1676060607 - https://github.com/systemd/systemd/pull/29558#discussion_r1358940663
* test: add a fuzzer for the varlink IDL stuffFrantisek Sumsal2023-10-142-0/+34
|
* json: rename json_append() → json_variant_merge_objectb()Lennart Poettering2023-08-241-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | json_append() is a useful wrapper around json_variant_merge(). However, I think the naming sould be cleaned up a bit of both functions. I thinker "merge" is the better word than "append", since it does decidedly more than just append: it replaces existing fields of the same name, hence "merge" sounds more appropriate. This is as opposed to the similar operations for arrays, where no such override logic is applied and we really just append, hence those functions are called "append" already. To make clearer that "merge" is about objects, and "append" about arrays, also include "object" in the name. Also, include "json_variant" in the name, like we do for almost all other functions in the JSON API that take a JSON object as primary input, and hence are kinda object methods. Finally, let's follow the logic that helpers that combine json_build() with some other operation get suffixed with "b" like we already have in some cases. Hence: json_variant_merge() → json_variant_merge_object() json_append() → json_variant_merge_objectb() This mirrors nicely the existing: json_variant_append_array() json_vairant_append_arrayb() This also drops the variant of json_append() that takes a va_arg parameter (i.e. json_appendv()). We have no user of that so far, and given the nature as a helper function only I don#t see that happening, and if it happens after all it's trivial to bring back.
* tree-wide: use memstream-utilYu Watanabe2023-05-311-4/+5
|
* fuzz: avoid a couple of NULL pointer dereferencesFrantisek Sumsal2023-05-202-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | In case one of the allocations fails. For example: AddressSanitizer:DEADLYSIGNAL ================================================================= ==17==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7fb352a476e5 bp 0x7ffe45154850 sp 0x7ffe45154008 T0) ==17==The signal is caused by a READ memory access. ==17==Hint: address points to the zero page. SCARINESS: 10 (null-deref) #0 0x7fb352a476e5 (/lib/x86_64-linux-gnu/libc.so.6+0x1886e5) (BuildId: 1878e6b475720c7c51969e69ab2d276fae6d1dee) #1 0x435878 in __interceptor_strlen /src/llvm-project/compiler-rt/lib/asan/../sanitizer_common/sanitizer_common_interceptors.inc #2 0x4de1e4 in LLVMFuzzerTestOneInput /work/build/../../src/systemd/src/fuzz/fuzz-calendarspec.c:20:21 #3 0x4deea8 in NaloFuzzerTestOneInput (/build/fuzz-calendarspec+0x4deea8) #4 0x4fde33 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:611:15 #5 0x4fd61a in fuzzer::Fuzzer::RunOne(unsigned char const*, unsigned long, bool, fuzzer::InputInfo*, bool, bool*) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:514:3 #6 0x4fece9 in fuzzer::Fuzzer::MutateAndTestOne() /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:757:19 #7 0x4ff9b5 in fuzzer::Fuzzer::Loop(std::__Fuzzer::vector<fuzzer::SizedFile, std::__Fuzzer::allocator<fuzzer::SizedFile> >&) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:895:5 #8 0x4eed1f in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerDriver.cpp:912:6 #9 0x4ef5e8 in LLVMFuzzerRunDriver /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerDriver.cpp:925:10 #10 0x4df105 in main (/build/fuzz-calendarspec+0x4df105) #11 0x7fb3528e3082 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24082) (BuildId: 1878e6b475720c7c51969e69ab2d276fae6d1dee) #12 0x41f80d in _start (/build/fuzz-calendarspec+0x41f80d) Found by Nallocfuzz.
* compress: replace compress_blob() with compress_blob_explicit()Yu Watanabe2023-04-111-1/+1
| | | | | | | And make compress_xyz() return 0 on success, as we know which compression algorithm is used when calling compress_blob(). Follow-up for 2360352ef02548723ac0c8eaf5ff6905eb9eeca5.
* meson: Add simple_fuzzers listJan Janssen2023-02-211-23/+13
|
* tree-wide: introduce PIPE_EBADF macroYu Watanabe2022-12-201-1/+1
|
* tree-wide: use -EBADF also in pipe initializersZbigniew Jędrzejewski-Szmek2022-12-191-1/+1
| | | | In some places, initialization is dropped when unnecesary.
* tree-wide: use -EBADF for fd initializationZbigniew Jędrzejewski-Szmek2022-12-192-2/+2
| | | | | | | | | | | | | | | | -1 was used everywhere, but -EBADF or -EBADFD started being used in various places. Let's make things consistent in the new style. Note that there are two candidates: EBADF 9 Bad file descriptor EBADFD 77 File descriptor in bad state Since we're initializating the fd, we're just assigning a value that means "no fd yet", so it's just a bad file descriptor, and the first errno fits better. If instead we had a valid file descriptor that became invalid because of some operation or state change, the other errno would fit better. In some places, initialization is dropped if unnecessary.
* fuzz: fuzz-compress: fix copy-and-paste error: buf -> buf2 (#25431)Li kunyu2022-11-181-1/+1
|
* basic: rename util.h to logarithm.hZbigniew Jędrzejewski-Szmek2022-11-081-1/+0
| | | | | util.h is now about logarithms only, so we can rename it. Many files included util.h for no apparent reason… Those includes are dropped.
* tree-wide: do not use "re" with fmemopenZbigniew Jędrzejewski-Szmek2022-10-191-1/+1
| | | | | | The man page says nothing about "e". Glibc clearly accepts it without fuss, but it is meaningless for a memory object (and probably doesn't work). This use is not portable, so let's avoid it.
* fuzz: Introduce DO_NOT_OPTIMIZEJan Janssen2022-09-251-0/+3
| | | | | | | | | | | | | | | The compiler may decide computations like these are not doing anything and decide to optimize them away. This would defeat the whole fuzzing exercise. This macro will force the compiler to materialize the value no matter what. It should be less prone to accidents compared to using log functions, which would either slow things down or still optimize the value away (or simply move it into the if branch the log macros create). The benefit over assert_se would be that no requirement is made on the value itself. If we are fine getting a string of any size (including zero), an assert_se would either create a noisy compiler warning about conditions that would alawys be met or yet again optimize the whole thing away.
* tree-wide: use ASSERT_PTR moreDavid Tardon2022-09-131-2/+1
|
* bootctl: add --root and --imageLuca Boccassi2022-07-081-1/+1
| | | | Operate on image/directory, and also take files to install from it
* fuzzers: ignore size limits when compiled standaloneZbigniew Jędrzejewski-Szmek2022-05-123-2/+14
| | | | | This way we can still call fuzzers on old samples, but oss-fuzz will not waste its and our time finding overly large inputs.
* fuzzers: add input size limits, always configure limits in two waysYu Watanabe2022-05-124-4/+4
| | | | | | | | | | | | | | | | | Without the size limits, oss-fuzz creates huge samples that time out. Usually this is because some of our code has bad algorithmic complexity. For data like configuration samples we don't need to care about this: non-rogue configs are rarely more than a few items, and a bit of a slowdown with a few hundred items is acceptable. This wouldn't be OK for processing of untrusted data though. We need to set the limit in two ways: through .options and in the code. The first because it nicely allows libFuzzer to avoid wasting time, and the second because fuzzers like hongfuzz and afl don't support .options. While at it, let's fix an off-by-one (65535 is the largest offset for a power-of-two size, but we're checking the size here). Co-authored-by: Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
* Merge pull request #23335 from keszybz/fuzz-json-more-coverageYu Watanabe2022-05-101-5/+94
|\ | | | | More coverage in fuzz-json
| * fuzz-json: also try self-merge operationsZbigniew Jędrzejewski-Szmek2022-05-101-2/+7
| | | | | | | | This might even work ;)
| * fuzz-json: also do sorting and normalizing and other easy callsZbigniew Jędrzejewski-Szmek2022-05-101-0/+75
| |
| * fuzz-json: optionally allow logging and outputZbigniew Jędrzejewski-Szmek2022-05-101-5/+14
| | | | | | | | Similarly to other fuzzers… this makes development easier.
* | fuzz-bootspec: limit input sizeZbigniew Jędrzejewski-Szmek2022-05-102-0/+5
| | | | | | | | | | | | | | https://oss-fuzz.com/testcase-detail/5680508182331392 has the first timeout with 811kb of input. As in the other cases, the code is known to be slow with lots of repeated entries and we're fine with that.
* | fuzz-calendarspec: increase coverage by calculating occurencesZbigniew Jędrzejewski-Szmek2022-05-101-4/+39
| | | | | | | | | | | | | | | | | | Coverage data shows that we didn't test calendar_spec_next_usec() and associated functions at all. The input samples so far were only used until the first NUL. We take advantage of that by using the part until the second NUL as the starting timestamp, retaining backwards compatibility for how the first part is used.
* | shared/calendarspec: make function static voidZbigniew Jędrzejewski-Szmek2022-05-101-1/+0
|/ | | | | | calendar_spec_from_string() already calls calendar_spec_normalize(), so there is no point in calling it from the fuzzer. Once that's removed, there's just one internal caller and it can be made static.
* fuzz-bootspec: also add loader autoentriesZbigniew Jędrzejewski-Szmek2022-05-082-1/+18
|
* Add fuzzer for the bootspec parserZbigniew Jędrzejewski-Szmek2022-05-083-0/+128
|
* meson: sort list of fuzzersZbigniew Jędrzejewski-Szmek2022-05-081-8/+8
|
* compress: make Compression a regular non-sparse enumLennart Poettering2022-04-261-1/+1
| | | | | | | Given we have two different types for the journal object flags and the Compression enum, let's make the latter a regular non-sparse enum, and thus remove some surprises. We have to convert anyway between the two, and already do via COMPRESSION_FROM_OBJECT().
* basic: move compress.[ch] → src/basic/Lennart Poettering2022-04-261-16/+5
| | | | | | | | | | | | 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.
* meson: Use files() for fuzzersJan Janssen2022-01-111-10/+10
| | | | | | Not having to provide the full path in the source tree is much nicer and the produced lists can also be used anywhere in the source tree.
* fuzz: no longer skip empty filesEvgeny Vereshchagin2022-01-044-13/+13
| | | | | | | | Empty files and empty strings seem to have triggered various issues in the past so it seems they shouldn't be ignore by the fuzzers just because fmemopen can't handle them. Prompted by https://github.com/systemd/systemd/pull/21939#issuecomment-1003113669
* fuzz-fido-id-desc: drop unused case fileZbigniew Jędrzejewski-Szmek2021-10-181-6/+0
| | | | | | It wasn't picked up automatically because it's not in test/fuzz/fuzz-fido-id-desc/. But looking at the contents, it doesn't seem to be in the expected input format either.
* alloc-util: simplify GREEDY_REALLOC() logic by relying on malloc_usable_size()Lennart Poettering2021-05-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | We recently started making more use of malloc_usable_size() and rely on it (see the string_erase() story). Given that we don't really support sytems where malloc_usable_size() cannot be trusted beyond statistics anyway, let's go fully in and rework GREEDY_REALLOC() on top of it: instead of passing around and maintaining the currenly allocated size everywhere, let's just derive it automatically from malloc_usable_size(). I am mostly after this for the simplicity this brings. It also brings minor efficiency improvements I guess, but things become so much nicer to look at if we can avoid these allocation size variables everywhere. Note that the malloc_usable_size() man page says relying on it wasn't "good programming practice", but I think it does this for reasons that don't apply here: the greedy realloc logic specifically doesn't rely on the returned extra size, beyond the fact that it is equal or larger than what was requested. (This commit was supposed to be a quick patch btw, but apparently we use the greedy realloc stuff quite a bit across the codebase, so this ends up touching *a*lot* of code.)
* fuzz-main: allow the number of runs to be overriddenZbigniew Jędrzejewski-Szmek2021-03-061-3/+14
| | | | This is useful when debugging.
* fuzz-bus-message: move sources to src/libsystemd/Zbigniew Jędrzejewski-Szmek2021-03-062-47/+0
| | | | | There's also fuzz-bus-label, but despite the name, it tests code that is in src/shared/, so it shouldn't move.
* treewide: tighten variable scope in loops (#18372)Susant Sahani2021-01-271-4/+4
| | | | Also use _cleanup_free_ in one more place.
* meson: move test or fuzzer definitions to relevant meson.build in subdirectoriesYu Watanabe2021-01-181-86/+0
|
* meson: drop unnecessary libraries from journal related testsYu Watanabe2021-01-181-3/+1
|
* meson: move source file list for systemd-xdg-autostart-generator and its testsYu Watanabe2021-01-181-4/+0
|
* meson: drop unnecessary loopYu Watanabe2021-01-181-2/+1
|