summaryrefslogtreecommitdiff
path: root/src/libelogind/sd-bus/bus-message.c
Commit message (Collapse)AuthorAge
* bus-message: avoid wrap-around when using length read from messageZbigniew Jędrzejewski-Szmek2018-10-29
| | | | | | | | | | We would read (-1), and then add 1 to it, call message_peek_body(..., 0, ...), and when trying to make use of the data. The fuzzer test case is just for one site, but they all look similar. v2: fix two UINT8_MAX/UINT32_MAX mismatches founds by LGTM (cherry picked from commit 902000c19830f5e5a96e8948d691b42e91ecb1e7)
* bus-message: return -EBADMSG not -EINVAL on invalid !gvariant messagesZbigniew Jędrzejewski-Szmek2018-10-29
| | | | (cherry picked from commit d831fb6f2bde829f9309aea242f502587662d1cc)
* bus-message: also properly copy struct signature when skippingZbigniew Jędrzejewski-Szmek2018-10-29
| | | | | | | The change is similar to that in the previous commit, but I don't have a reproducer / test case case for this one, so I'm keeping it seperate. (cherry picked from commit 3d338a302f56c0ef0445660d9856794abe1af8b5)
* bus-message: fix skipping of array fields in !gvariant messagesZbigniew Jędrzejewski-Szmek2018-10-29
| | | | | | | | | We copied part of the string into a buffer that was off by two. If the element signature had length one, we'd copy 0 bytes and crash when looking at the "first" byte. Otherwise, we would crash because strncpy would not terminate the string. (cherry picked from commit 73777ddba5100fe6c0791cd37a91f24a515f3202)
* bus-message: fix calculation of offsets table for arraysZbigniew Jędrzejewski-Szmek2018-10-29
| | | | | | | | | | This is similar to the grandparent commit 'fix calculation of offsets table', except that now the change is for array elements. Same story as before: we need to make sure that the offsets increase enough taking alignment into account. While at it, rename 'p' to 'previous' to match similar code in other places. (cherry picked from commit f88214cf9d66c93f4d22c4c8980de9ee3ff45bab)
* bus-message: fix calculation of offsets tableZbigniew Jędrzejewski-Szmek2018-10-29
| | | | | | | | | | | | | | | | | The offsets specify the ends of variable length data. We would trust the incoming data, putting the offsets specified in our message into the offsets tables after doing some superficial verification. But when actually reading the data we apply alignment, so we would take the previous offset, align it, making it bigger then current offset, and then we'd try to read data of negative length. In the attached example, the message specifies the following offsets: [1, 4] but the alignment of those items is [1, 8] so we'd calculate the second item as starting at 8 and ending at 4. (cherry picked from commit 12603b84d2fb07603e2ea94b240c6b78ad17510e)
* bus-message: do not crash on message with a string of zero lengthZbigniew Jędrzejewski-Szmek2018-10-29
| | | | | | | We'd calculate the "real" length of the string as 'item_size - 1', which does not work out well when item_size == 0. (cherry picked from commit 81b6e63029eefcb0ec03a3a7c248490e38106073)
* bus-message: let's always use -EBADMSG when the message is badZbigniew Jędrzejewski-Szmek2018-10-29
| | | | | | | -EINVAL means the arguments were somehow wrong, so translate the code we get internally into -EBADMSG when returning. (cherry picked from commit 69bd42ca072dfb2f7603b1f82053063293ab54b5)
* bus-message: avoid an infinite loop on empty structuresZbigniew Jędrzejewski-Szmek2018-10-29
| | | | | | | | | | The alternative would be to treat gvariant and !gvariant messages differently. But this is a problem because we check signatures is variuos places before we have an actual message, for example in sd_bus_add_object_vtable(). It seems better to treat things consistent (i.e. follow the lowest common denominator) and disallow empty structures everywhere. (cherry picked from commit ec6bda56cbca9509b1abde1122645630caca877c)
* sd-bus: unify three code-paths which free struct bus_containerZbigniew Jędrzejewski-Szmek2018-10-29
| | | | | | | | | | | | | | | | | | | | | | | | | | We didn't free one of the fields in two of the places. $ valgrind --show-leak-kinds=all --leak-check=full \ build/fuzz-bus-message \ test/fuzz/fuzz-bus-message/leak-c09c0e2256d43bc5e2d02748c8d8760e7bc25d20 ... ==14457== HEAP SUMMARY: ==14457== in use at exit: 3 bytes in 1 blocks ==14457== total heap usage: 509 allocs, 508 frees, 51,016 bytes allocated ==14457== ==14457== 3 bytes in 1 blocks are definitely lost in loss record 1 of 1 ==14457== at 0x4C2EBAB: malloc (vg_replace_malloc.c:299) ==14457== by 0x53AFE79: strndup (in /usr/lib64/libc-2.27.so) ==14457== by 0x4F52EB8: free_and_strndup (string-util.c:1039) ==14457== by 0x4F8E1AB: sd_bus_message_peek_type (bus-message.c:4193) ==14457== by 0x4F76CB5: bus_message_dump (bus-dump.c:144) ==14457== by 0x108F12: LLVMFuzzerTestOneInput (fuzz-bus-message.c:24) ==14457== by 0x1090F7: main (fuzz-main.c:34) ==14457== ==14457== LEAK SUMMARY: ==14457== definitely lost: 3 bytes in 1 blocks (cherry picked from commit 6d1e0f4fcba8d6f425da3dc91805db95399b3c8b)
* bus-message: use structured initialization to avoid use of unitialized memoryZbigniew Jędrzejewski-Szmek2018-10-29
| | | | | | | | | As far as I can see, we would either reuse some values from a previously exited container or just random bytes from the heap. Should fix #10127. (cherry picked from commit cf81c68e96aa29d0c28b5d3a26d1de9aa1b53b85)
* Introduce free_and_strndup and use it in bus-message.cZbigniew Jędrzejewski-Szmek2018-10-29
| | | | | | | | | | | | | | | | v2: fix error in free_and_strndup() When the orignal and copied message were the same, but shorter than specified length l, memory read past the end of the buffer would be performed. A test case is included: a string that had an embedded NUL ("q\0") is used to replace "q". v3: Fix one more bug in free_and_strndup and add tests. v4: Some style fixed based on review, one more use of free_and_replace, and make the tests more comprehensive. (cherry picked from commit 7f546026abbdc56c453a577e52d57159458c3e9c)
* sd-bus: verify destination and sender values when settingZbigniew Jędrzejewski-Szmek2018-10-29
| | | | | | | | We would verify destination e.g. in sd_bus_message_new_call, but allow setting any value later on with sd_bus_message_set_destination. I assume this check was omitted not on purpose. (cherry picked from commit 3d51a011f11523694f03c74cdd011c89beba05cc)
* sd-bus: fix typo in commentYu Watanabe2018-08-24
|
* tree-wide: remove Lennart's copyright linesLennart Poettering2018-08-24
| | | | | | | | | | | These lines are generally out-of-date, incomplete and unnecessary. With SPDX and git repository much more accurate and fine grained information about licensing and authorship is available, hence let's drop the per-file copyright notice. Of course, removing copyright lines of others is problematic, hence this commit only removes my own lines and leaves all others untouched. It might be nicer if sooner or later those could go away too, making git the only and accurate source of authorship information.
* tree-wide: drop 'This file is part of systemd' blurbLennart Poettering2018-08-24
| | | | | | | | | | | | | | | | This part of the copyright blurb stems from the GPL use recommendations: https://www.gnu.org/licenses/gpl-howto.en.html The concept appears to originate in times where version control was per file, instead of per tree, and was a way to glue the files together. Ultimately, we nowadays don't live in that world anymore, and this information is entirely useless anyway, as people are very welcome to copy these files into any projects they like, and they shouldn't have to change bits that are part of our copyright header for that. hence, let's just get rid of this old cruft, and shorten our codebase a bit.
* sd-bus: use _cleanup_ moreZbigniew Jędrzejewski-Szmek2018-08-24
|
* sd-bus: use automatic cleanup moreDavid Tardon2018-08-24
|
* tree-wide: be more careful with the type of array sizesLennart Poettering2018-08-24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously we were a bit sloppy with the index and size types of arrays, we'd regularly use unsigned. While I don't think this ever resulted in real issues I think we should be more careful there and follow a stricter regime: unless there's a strong reason not to use size_t for array sizes and indexes, size_t it should be. Any allocations we do ultimately will use size_t anyway, and converting forth and back between unsigned and size_t will always be a source of problems. Note that on 32bit machines "unsigned" and "size_t" are equivalent, and on 64bit machines our arrays shouldn't grow that large anyway, and if they do we have a problem, however that kind of overly large allocation we have protections for usually, but for overflows we do not have that so much, hence let's add it. So yeah, it's a story of the current code being already "good enough", but I think some extra type hygiene is better. This patch tries to be comprehensive, but it probably isn't and I missed a few cases. But I guess we can cover that later as we notice it. Among smaller fixes, this changes: 1. strv_length()' return type becomes size_t 2. the unit file changes array size becomes size_t 3. DNS answer and query array sizes become size_t Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=76745
* bus-message: use streq_ptr() (#8786)Yu Watanabe2018-08-24
|
* tree-wide: drop spurious newlines (#8764)Lennart Poettering2018-08-24
| | | | | | | | | Double newlines (i.e. one empty lines) are great to structure code. But let's avoid triple newlines (i.e. two empty lines), quadruple newlines, quintuple newlines, …, that's just spurious whitespace. It's an easy way to drop 121 lines of code, and keeps the coding style of our sources a bit tigther.
* tree-wide: drop license boilerplateZbigniew Jędrzejewski-Szmek2018-08-24
| | | | | | | | | | Files which are installed as-is (any .service and other unit files, .conf files, .policy files, etc), are left as is. My assumption is that SPDX identifiers are not yet that well known, so it's better to retain the extended header to avoid any doubt. I also kept any copyright lines. We can probably remove them, but it'd nice to obtain explicit acks from all involved authors before doing that.
* tree-wide: use TAKE_PTR() and TAKE_FD() macrosYu Watanabe2018-08-24
|
* Prep v238: Applied some upstream updates to src/libelogind (5/5)Sven Eden2018-06-04
|
* sd-bus: let's better not invade stdio territory when duplicating fdsLennart Poettering2018-05-30
|
* coccinelle: add reallocarray() coccinelle scriptLennart Poettering2018-05-30
| | | | | Let's systematically make use of reallocarray() whereever we invoke realloc() with a product of two values.
* bus-message: avoid -Wnull-pointer-arithmetic warning on new clangZbigniew Jędrzejewski-Szmek2018-05-30
| | | | | We just need some pointer, so use alignment directly converted to the right type.
* sd-bus: add API to optionally set a sender field on all outgoing messagesLennart Poettering2018-05-30
| | | | | | | | | | This is useful on direct connections to generate messages with valid sender fields. This is particularly useful for services that are accessible both through direct connections and the broker, as it allows clients to install matches on the sender service name, and they work the same in both cases.
* sd-bus: drop some unused fields from the sd_bus_message structureLennart Poettering2018-05-30
|
* Prep v236 : Add missing SPDX-License-Identifier (4/9) src/libelogindSven Eden2018-03-26
|
* tree-wide: adjust fall through comments so that gcc is happyShawn Landden2017-11-19
| | | | | | | | Distcc removes comments, making the comment silencing not work. I know there was a decision against a macro in commit ec251fe7d5bc24b5d38b0853bc5969f3a0ba06e2
* Prep 229.9: Make all supportable API functions visible.Sven Eden2017-12-12
| | | | | | | | | | The process of cleaning up elogind, meaning to mask all bits that are unneeded by elogind, has been finished a while ago. It is therefore time to re-enable all previously masked API functions that elogind can support. This will make it easier for future developers to integrate elogind into their software where they already support systemd-login.
* tree-wide: use IN_SET macro (#6977)Yu Watanabe2017-12-08
|
* libelogind: use IN_SET macroYu Watanabe2017-11-22
|
* Prep v235: Apply upstream fixes (5/10) [src/libelogind]Sven Eden2017-08-14
|
* Export sd_bus_message_append_ap. It is renamed to sd_bus_message_appendv to ↵Federico2017-07-25
| | | | | | | follow elogind naming conventions. (#5753) Moreover, man page for sd_bus_message_append is updated with reference to new exposed function. Makefile-man is updated too, to reflect new alias.
* Prep v233.3: Unmask various functions for future coverage tests.Sven Eden2017-07-19
| | | | | These functions, although not used by elogind itself, are mostly tiny and crucial for important tests to work.
* treewide: fix typos and remove accidental repetition of wordsTorstein Husebø2017-06-16
|
* Prep v230: Apply missing upstream fixes and updates (5/8) src/libelogind.Sven Eden2017-06-16
|
* tree-wide: use SET_FLAG() macro to make code more clearAlexander Kuleshov2017-06-16
|
* tree-wide: make ++/-- usage consistent WRT spacingVito Caputo2017-06-16
| | | | | | Throughout the tree there's spurious use of spaces separating ++ and -- operators from their respective operands. Make ++ and -- operator consistent with the majority of existing uses; discard the spaces.
* Add memcpy_safeZbigniew Jędrzejewski-Szmek2017-06-16
| | | | | | | | | | | | | | | | | ISO/IEC 9899:1999 §7.21.1/2 says: Where an argument declared as size_t n specifies the length of the array for a function, n can have the value zero on a call to that function. Unless explicitly stated otherwise in the description of a particular function in this subclause, pointer arguments on such a call shall still have valid values, as described in 7.1.4. In base64_append_width memcpy was called as memcpy(x, NULL, 0). GCC 4.9 started making use of this and assumes This worked fine under -O0, but does something strange under -O3. This patch fixes a bug in base64_append_width(), fixes a possible bug in journal_file_append_entry_internal(), and makes use of the new function to simplify the code in other places.
* Prep v229: Remove remaining emacs settings [3/6] src/libelogindSven Eden2017-05-17
|
* tree-wide: expose "p"-suffix unref calls in public APIs to make gcc cleanup easyLennart Poettering2017-05-17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | GLIB has recently started to officially support the gcc cleanup attribute in its public API, hence let's do the same for our APIs. With this patch we'll define an xyz_unrefp() call for each public xyz_unref() call, to make it easy to use inside a __attribute__((cleanup())) expression. Then, all code is ported over to make use of this. The new calls are also documented in the man pages, with examples how to use them (well, I only added docs where the _unref() call itself already had docs, and the examples, only cover sd_bus_unrefp() and sd_event_unrefp()). This also renames sd_lldp_free() to sd_lldp_unref(), since that's how we tend to call our destructors these days. Note that this defines no public macro that wraps gcc's attribute and makes it easier to use. While I think it's our duty in the library to make our stuff easy to use, I figure it's not our duty to make gcc's own features easy to use on its own. Most likely, client code which wants to make use of this should define its own: #define _cleanup_(function) __attribute__((cleanup(function))) Or similar, to make the gcc feature easier to use. Making this logic public has the benefit that we can remove three header files whose only purpose was to define these functions internally. See #2008.
* Prep v228: Condense elogind source masks (4/5)Sven Eden2017-04-26
|
* Prep v228: Add remaining updates from upstream (3/3)Sven Eden2017-04-26
| | | | | Apply remaining fixes and the performed move of utility functions into their own foo-util.[hc] files on the rest of elogind.
* Prep v227: Clean up some headers in src/systemdSven Eden2017-04-09
| | | | | | - src/systemd/sd-bus.h - src/systemd/sd-daemon.h - src/systemd/sd-event.h
* Unifiy free() usageSven Eden2017-03-14
| | | | | | | | This commit substitutes all occurrences of free(foo); foo = NULL; with foo = mfree(foo);
* sd-bus: it's not a user error to query the error contained in a bus messageLennart Poettering2017-03-14
| | | | | It's an OK way to check whether a message contains an erro, let's not consider this a loggable assertion event.
* Prep v225: Applying various fixes and changes to src/libelogind/sd-bus that ↵Sven Eden2017-03-14
| | | | got lost during git am transfer.