Commit Graph

751 Commits

Author SHA1 Message Date
Simon McVittie
4b159b11eb httpcache: Free the GError before exiting
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-15 20:33:06 +00:00
Simon McVittie
dfe995a457 testlibrary: Don't leak list of subpaths
flatpak_deploy_data_get_subpaths() returns a new array (of unowned
strings) and flatpak_dir_new_deploy_data() doesn't take ownership.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-15 20:33:06 +00:00
Simon McVittie
955e9ceed3 test_list_remote_related_refs: Don't leak list of subpaths
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-15 20:33:06 +00:00
Simon McVittie
7dc71e1fed testlibrary: Don't leak strings retrieved from remote
All of these getters are (transfer full) (but note that
flatpak_remote_get_name() isn't).

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-15 20:33:06 +00:00
Simon McVittie
6636592d2d testlibrary: Don't leak an array of related refs
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-15 20:33:06 +00:00
Simon McVittie
88a919a32e testlibrary: Don't leak icon data 2024-02-15 20:33:06 +00:00
Simon McVittie
5cd581d0ae testlibrary: Don't leak FlatpakInstance
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-15 20:33:06 +00:00
Simon McVittie
843eca7958 testlibrary: Don't leak several installed references
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-15 20:33:06 +00:00
Simon McVittie
3cf98a3118 testlibrary: Don't leak transactions
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-15 20:33:06 +00:00
Simon McVittie
80c1fc5f78 tests: Fix a double-free when exercising argument parsing
g_option_context_add_group() takes ownership of the group that it's
given, so we can't also free it.

Fixes: fab0f8ed "test-context: Exercise some corner cases for merging filesystems"
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-15 20:33:06 +00:00
Simon McVittie
2a363d7569 build: Consistently put libglnx.la last in lists of dependencies
It needs to be able to satisfy dependencies of higher-level Flatpak
static libraries.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-15 16:06:41 +00:00
Weng Xuetian
0402e1614c Limit the usage of WAYLAND_SOCKET to an opt-in feature
1. For security context creation, only relies on WAYLAND_DISPLAY, do not
   use WAYLAND_SOCKET since the file descriptor defined by WAYLAND_SOCKET
   can be only consumed once.
2. Due to the incompatiblity between WAYLAND_SOCKET and the security
   context, add a new permission --socket=inherit-wayland-socket
   to limit the usage of WAYLAND_SOCKET to an opt-in feature. Only when
   this flag is set, WAYLAND_SOCKET will be passed to the sandbox.
3. When WAYLAND_SOCKET is not inherited, set FD_CLOEXEC to avoid it to
   be leaked the to sandbox.

Closes: #5614
2024-02-14 19:39:50 +00:00
Hubert Figuière
6e3cc82af3 Fix memory leaks
Build with address sanitizer and run the tests

Signed-off-by: Hubert Figuière <hub@figuiere.net>
2024-02-13 08:20:57 -06:00
Simon McVittie
3a297d8e1d test-run.sh: Assert that fd redirections pass through into the app
Before the previous commit, this would normally work, but would fail if
we had FLATPAK_TEST_COVERAGE=1 in the environment.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-02-13 13:48:38 +00:00
Patrick Griffis
8c26798991 update: Make autopruned refs automatically removed
In order to maintain a system over time update automatically removes any EOL runtimes that are unused.

This extends it to also remove any autopruned refs. In practice this means removing no longer used driver versions as the system is updated.

Closes #5261
2024-01-07 18:51:46 -06:00
Dan Nicholson
65bc369a9f tests: Skip more tests when FUSE isn't available
These tests try to install flatpaks, which fails in the system case when
FUSE isn't available to mount revokefs-fuse.
2023-12-08 11:33:12 +00:00
Simon McVittie
9bf3620aef common: Move locale utils to their own small translation unit
This reduces the size of flatpak-utils and flatpak-dir, which are both
too large.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-11-14 18:39:22 +00:00
Simon McVittie
eb858fb8c7 tests: Test individual locale code paths
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-11-14 18:39:22 +00:00
Simon McVittie
b2ed82feec tests: Smoke-test flatpak_get_user_locales, flatpak_get_system_locales
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-11-14 18:39:22 +00:00
Simon McVittie
4c32ffecd5 tests: Expand test coverage for flatpak_get_lang_from_locale()
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-11-14 18:39:22 +00:00
Georges Basile Stavracas Neto
6a57fa42e4 tests: Check if program exists before using it
The tests/make-test-runtime.sh scripts sets '-e' in lieu of
implementing useful error checking, but doesn't actually check
if the programs it uses exist in the first place; and aborts
silently when they're not available.

It is more useful to warn about them, and stop execution earlier.
This leaves some leftover files, but arguably that's better than
leaving leftover files AND people scratching their heads.

Warn about missing required programs.

Related: https://github.com/flatpak/flatpak/issues/5020
2023-10-04 13:04:08 +01:00
Simon McVittie
5009857b5a Use g_steal_fd()
This was new in GLib 2.70, but libglnx now provides a backport, so we
can use it unconditionally.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-09-04 13:25:32 +01:00
Simon McVittie
ad17979018 tests: Move test coverage for app/ into a new executable
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-07-03 20:19:00 +02:00
Simon McVittie
ae2579637a app: Move terminal-related utility functions from common into app
These functions are to do with being an interactive, terminal-oriented
CLI/TUI, so it would be inappropriate for library code in libflatpak
to call them, and it would also be inappropriate for daemons like the
session and system helpers to call them.

In fact all calls to these were already isolated to app/, so we can
easily move the terminal-related utilities themselves into app/.

As well as shrinking libflatpak, this makes it obvious that the system
helper does not actually need to call flatpak_disable_fancy_output():
it does not link any code that would be affected by that API call.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-07-03 20:19:00 +02:00
Simon McVittie
a898065a66 common: Move metadata to its own header
This cuts more circular dependencies between flatpak-run and
flatpak-exports.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-07-03 20:07:57 +02:00
Simon McVittie
bf8e91cedc common: Stop including utils-http in utils
utils-http is conceptually larger than utils.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-07-03 20:07:57 +02:00
Simon McVittie
ecab882896 glib-backports: Use g_ascii_string_to_unsigned if GLib is new enough
Use the real GLib function if we can, and resync the backport with the
version in GLib 2.76.2: use a compatibility replacement for
G_NUMBER_PARSER_ERROR so that it can be textually identical to the
version in GLib, and revert Flatpak changes to the whitespace.

The only functional change is that if the function fails, we'll raise
G_NUMBER_PARSER_ERROR_INVALID if GLib is new enough.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-05-17 11:35:44 +01:00
Simon McVittie
db7a8bb598 common: Split up socket setup from flatpak-run into multiple files
flatpak-run is large enough to be getting unwieldy, so separate it out
into various smaller modules.

A side benefit of these is that they'll be easier to reuse in other
projects, like Steam's pressure-vessel tool.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-05-15 19:54:51 +01:00
Dan Nicholson
5069fd6a21 tests: Add a test for atomicity of eol-rebase updates
This adds a test to cover the changes in the previous commit.

Helps: #3991
2023-03-30 14:54:18 +02:00
Simon McVittie
cffc3aed5b testlibrary: Initialize autofree variable to silence a compiler warning
As with commit 43085c0e "dir: Consistently initialize g_autofree
variables", this is currently harmless because we never actually
early-return or goto out of the region between declaration and
initialization, but some compiler versions log a warning here anyway.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-03-30 14:42:44 +02:00
Simon McVittie
a058d9617f tests: Call g_test_init() before isolated_test_dir_global_setup()
g_test_init() is meant to be called before any other use of GTest APIs,
and isolated_test_dir_global_setup() can call g_test_message(). GLib
2.76 makes this more of a practical problem.

(isolated_test_dir_global_setup() is essentially a reimplementation of
G_TEST_OPTION_ISOLATE_DIRS, since we don't depend on GLib 2.60.)

Alternative to https://github.com/flatpak/flatpak/pull/5355.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-03-17 16:34:09 +00:00
Simon McVittie
8e63de9a7d run: Prevent TIOCLINUX ioctl, the same as TIOCSTI
The TIOCLINUX ioctl is only available on Linux virtual consoles such as
/dev/tty1. It has several Linux-specific functions, one of which is a
copy/paste operation which can be used for attacks similar to TIOCSTI.

This vulnerability does not affect typical graphical terminal emulators
such as xterm, gnome-terminal and Konsole, and Flatpak is primarily
designed to be run from a Wayland or X11 graphical environment, so this
is relatively unlikely to be a practical problem.

CVE-2023-28100, GHSA-7qpw-3vjv-xrqp

Resolves: https://github.com/flatpak/flatpak/security/advisories/GHSA-7qpw-3vjv-xrqp
Signed-off-by: Simon McVittie <smcv@debian.org>
2023-03-16 09:54:14 +00:00
Ryan Gonzalez
7fe63f2e8f Reject paths given to --filesystem/--persist with special characters
There isn't much in the way of legit reasons for this, but it's a
potential security footgun when displaying the text.

CVE-2023-28101, GHSA-h43h-fwqx-mpp8

Signed-off-by: Ryan Gonzalez <ryan.gonzalez@collabora.com>
Co-authored-by: Simon McVittie <smcv@collabora.com>
2023-03-16 09:54:14 +00:00
Ryan Gonzalez
6cac99dafe Ensure special characters in permissions and metadata are escaped
This prevents someone from placing special characters in order to
manipulate the appearance of the permissions list.

CVE-2023-28101, GHSA-h43h-fwqx-mpp8

Signed-off-by: Ryan Gonzalez <ryan.gonzalez@collabora.com>
2023-03-16 09:54:14 +00:00
Dan Nicholson
fba3a7d35e transaction: Ignore uninstall operations for no deploy
If `no_deploy` has been set to `TRUE` in a transaction, then the
intention is that no changes will be made to the installed flatpaks.
Currently that's not the case for explicitly or implicitly added
uninstall operations. That's particularly bad for eol-rebase flatpaks
since they old version will be automatically removed without the new
version being installed. To address this, prevent uninstall operations
from being added for no deploy transactions.

Closes: #5172
2023-02-18 14:48:47 +00:00
Simon McVittie
0aa0284c10 exports: Test that a symlink to the root directory is rejected
Reproduces: https://github.com/flatpak/flatpak/issues/1357
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-01-12 15:13:34 +00:00
Simon McVittie
fe49f8f7ca exports: Assert that recently-excluded paths are excluded
Reproduces: https://github.com/flatpak/flatpak/issues/5205
Reproduces: https://github.com/flatpak/flatpak/issues/5207
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-01-12 15:13:34 +00:00
Simon McVittie
073bdccd9e exports: Move error handling up into caller
This lets flatpak_context_export() or other callers decide how they want
to handle failure to export each path. For now, the callers in
FlatpakExports are still using g_debug() unconditionally, but we can now
have somewhat better test coverage.

Helps: https://github.com/flatpak/flatpak/issues/1357
Helps: https://github.com/flatpak/flatpak/issues/5035
Helps: https://github.com/flatpak/flatpak/issues/5205
Helps: https://github.com/flatpak/flatpak/issues/5207
Signed-off-by: Simon McVittie <smcv@collabora.com>
2023-01-12 15:13:34 +00:00
Simon McVittie
c2c034733e common: Make flatpak_debug2() use the same domain as g_debug()
Now that we are logging `flatpak -v` messages with log level INFO,
and printing INFO messages in the same way as DEBUG, we can reserve
log level DEBUG for `flatpak -v -v` messages. This means we no longer
need a weird secondary debug domain.

There is a very small behaviour change here: G_MESSAGES_DEBUG=flatpak
is now similar to `flatpak -v -v` (previously `flatpak -v`), and
G_MESSAGES_DEBUG=flatpak2 no longer has any effect. This seems more in
line with what would be expected from a GLib-based application.

In flatpak(1) and the system helper, this does not change behaviour
other than that: the same messages are logged by `-v` and by `-v -v`
as before.

In daemons that do not implement `-v -v` (the OCI authenticator, portal
and session helper), it continues to be necessary to use
G_MESSAGES_DEBUG to see flatpak_debug2() messages.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-12-15 16:45:35 +00:00
Simon McVittie
86c9d7d4c7 daemons, etc.: Use g_info() for messages that are enabled by -v
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-12-15 16:45:35 +00:00
Simon McVittie
ea584acf20 daemons: Treat g_info() as equivalent to g_debug()
Same as the previous commit, but for anything that runs in the
background.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-12-14 20:02:35 +00:00
Simon McVittie
435be4da14 meson: Depend on Meson 0.50.0
This sacrifices compatibility with Debian 10 to let us simplify how
tests are set up.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-24 16:12:14 +01:00
Simon McVittie
9eb824f863 Add a Meson build system
Resolves: https://github.com/flatpak/flatpak/issues/2241
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-24 16:12:14 +01:00
Simon McVittie
ad1dc62f26 testlib: Remove local backport of g_assert_no_errno()
libglnx now provides this.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-24 16:10:49 +01:00
Phaedrus Leeds
600e18567c Add a vim modeline and .editorconfig
To make indentation work with less effort. The modeline was copied from
libostree with minor modification and the .editorconfig from GLib.

The advantage of having both a modeline and an editorconfig is we can
work out of the box on more editor setups, and the modeline allows us to
specify the style with a lot more fine grained control.
2022-08-22 19:48:10 -07:00
Simon McVittie
022be7b6db tests: Add valgrind suppression for ostreedev/ostree#2592
This is fixed in v2022.3, but that version missed the boat for Ubuntu
22.04.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-08-16 13:27:04 +02:00
Simon McVittie
4018419b15 revokefs: Use FUSE version 3 if possible
Based on a change contributed by Léo Stefanesco; but instead of
unconditionally using FUSE 3, leave a fallback code path for FUSE 2 for
older distros.

Co-authored-by: Léo Stefanesco <leo.lveb@gmail.com>
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-08-16 13:27:04 +02:00
Phaedrus Leeds
53a0b528bf Add DeploySideloadCollectionID flatpakref/flatpakrepo key
When Flatpak's P2P updates support was replaced with the "sideloading"
implementation in 1.7.1, a new server side repo config key
"deploy-sideload-collection-id" was added which gets set when you pass
"--deploy-sideload-collection-id" to "flatpak build-update-repo", and
has the effect of setting "xa.deploy-collection-id" in the repo metadata
that is pulled by clients, which itself causes a collection id to be set
on the remote for clients using Flatpak >= 1.7.1.

This commit adds an analogous key in flatpakref and flatpakrepo files,
so the collection id can be set when the remote is configured, rather
than later on when the repo metadata is pulled and acted upon. As before
with DeployCollectionID, it has no difference in function compared to
DeployCollectionID or CollectionID and the only difference is which
Flatpak versions are affected.

It would've been better if this were added in 1.7.1 when the sideload
support was added, but alas here we are.

(Also update the docs and unit tests)
2022-08-16 10:37:36 +02:00
Simon McVittie
0c5e4abbea try-syscall: Cope with old glibc without PR_SET_CHILD_SUBREAPER defined
Originally part of containers/bubblewrap#496 in bubblewrap.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-06-27 10:02:25 -07:00
Simon McVittie
836b0fb604 try-syscall: Use compiler-predefined macros to detect mips ABI
_MIPS_SIM_ABI32 etc. are defined by Linux <asm/sgidefs.h>, which is
included by glibc <sys/syscall.h> (which defers to Linux headers to
get syscall numbers), but not by musl <sys/syscall.h>.

_ABIO32 etc. are predefined by the compiler, so they are always
available, regardless of libc. References:

https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=27d54b2a6c18ef1ae50f1a5b432d590438445b90
https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=0ea339ea4d9c3e04ae17da6bf389617eb0251e57

Originally containers/bubblewrap#492 in bubblewrap.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-06-27 10:02:25 -07:00