Commit Graph

16 Commits

Author SHA1 Message Date
Simon McVittie
8deef94f9d icon-validator: Remove remnants of GSpawn error handling
Now that validate-icon uses execvpe(), status and error were never set,
so rerun_in_sandbox() would have crashed while dereferencing a NULL
error if execvpe() failed. This is reproducible with, for example:

    FLATPAK_BWRAP=/bin/nope flatpak-validate-icon --sandbox 48 48 /path/to/icon

execvpe() does not return on success (the process image is replaced),
and sets errno on failure, so behave accordingly.

Also print the error message to stderr, even if G_MESSAGES_DEBUG is not
set, since it's our only opportunity to indicate to a caller what has
gone wrong.

Signed-off-by: Simon McVittie <smcv@collabora.com>

Closes: #2950
Approved by: alexlarsson
2019-06-12 06:51:53 +00:00
Simon McVittie
e360005d8b Check for missing sentinels in NULL-terminated varargs
Signed-off-by: Simon McVittie <smcv@collabora.com>

Closes: #2876
Approved by: matthiasclasen
2019-05-02 16:58:36 +00:00
Simon McVittie
89dc344ccb icon-validator, portal: Guard against overlong symlink targets
If the buffer is too small, readlink() returns the number of bytes that
would have been stored if the buffer had been large enough.

Signed-off-by: Simon McVittie <smcv@collabora.com>

Closes: #2873
Approved by: matthiasclasen
2019-05-01 16:39:18 +00:00
Matthias Clasen
11aface66e icon-validator: Add the max size to the error
This helps to explain why an icon was rejected.

Closes: #2813
Approved by: alexlarsson
2019-04-10 06:58:13 +00:00
Bastien Nocera
32c5b15326 icon-validator: Don't check SVG size
The size is just a number, but the resulting GdkPixbuf could still be
quite big compared to the amount of data we're processing, so keep
4096x4096 as maximum dimensions.

Closes: #2747
Approved by: alexlarsson
2019-03-12 13:07:41 +00:00
Bastien Nocera
8008fe38a1 icon-validator: Check image format first
Closes: #2747
Approved by: alexlarsson
2019-03-12 13:07:41 +00:00
Matthew Leeds
e8816b7663 Remove extra newlines in variable definiton blocks
Uncrustify has an option "nl_func_var_def_blk" which is supposed to
ensure there's a newline character between the block of variable
definitions and the rest of the function body, but it gets confused and
thinks that the first instance of "g_autoptr" or "g_auto" being used on
a variable is the start of the function body. So this commit removes
those extra newline characters and removes that option in uncrustify.cfg
so they don't get re-added the next time uncrustify is run.

Here's the command I used:

perl -0777 -i -pe 's/\n(\n\s*g_auto\()/\1/g' `git ls-tree --name-only
-r HEAD | grep \\\.[ch]$ | grep -v common/valgrind-private.h |
grep -v app/flatpak-polkit-agent-text-listener\\\.[ch]`

I ran it again with "g_autoptr" in place of "g_auto", and made a few
manual edits to add back the newline when the g_auto* was in the middle
of a function body rather than at the top.

Closes: #2715
Approved by: matthiasclasen
2019-02-25 18:12:30 +00:00
Matthew Leeds
8d962a686f Run uncrustify
I had to make a few manual edits but other than those the changes look
reasonable.

Closes: #2715
Approved by: matthiasclasen
2019-02-25 18:12:30 +00:00
Matthias Clasen
2bf420b93a icon validator: Use exec for the sandboxing
We don't really need a separate process here, and
doing things this way makes output from the sandbox
appear outside, thereby giving us meaningful error
messages for invalid icons.

Related: #2669

Closes: #2677
Approved by: alexlarsson
2019-02-05 10:00:15 +00:00
Alexander Larsson
bcc53c2454 validate-icon: Search the path for bwrap
Closes: #2640
Approved by: alexlarsson
2019-01-28 09:40:22 +00:00
Matthias Clasen
57b55d9781 icon-validator: Use readlink() properly
This function helpfully does not 0-terminate the buffer,
so we have to do that ourselves. Also make the buffer
as large as possibly required, and handle errors.

Closes: #2630
Approved by: matthiasclasen
2019-01-23 12:44:38 +00:00
Matthias Clasen
ae1dc979df Make tests work
We can't look at the FLATPAK_VALIDATE_ICON environment variable
inside the sandbox. Use /proc/self/exe to find the binary to reexec.

Closes: #2618
Approved by: alexlarsson
2019-01-21 09:17:29 +00:00
Matthias Clasen
39152a6d40 Copy sandbox setup from libgnome-desktop
We need to handle source directories not existing, for example /lib64
on a pure 32-bit system.

Because relative symlinks in a directory that is itself a symlink do
not have the same meaning as the same relative symlink in a bind-mount
of that directory, ideally we want to use --symlink for /lib and /lib64
on merged-/usr systems, but --ro-bind on non-merged-/usr systems.

Also bind /etc/ld.so.cache into the sandbox.

This is especially important for libstdc++ on distributions that
don't have it directly in a libdir and the runtime linker doesn't
look where needed without /etc/ld.so.cache (e.g. if libstdc++ is
in a GCC per-version subdirectory handled via /etc/ld.so.conf.d/).

Changes originally made in libgnome-desktop by Iain Lane (see
<https://bugzilla.gnome.org/show_bug.cgi?id=787072>).

Adapted from https://github.com/flatpak/xdg-desktop-portal/pull/289
by Simon McVittie.

Closes: #2618
Approved by: alexlarsson
2019-01-21 09:17:29 +00:00
Matthias Clasen
81265f5115 Make the icon validator sandbox itself
Make the icon validator reexec itself inside a sandbos
if the --sandbox option is given. This lets us share
the sandbox setup between all users of this tool.

An additional advantage is that this makes the sandbox
setup code testable by iself.

Closes: #2618
Approved by: alexlarsson
2019-01-21 09:17:29 +00:00
Matthias Clasen
64958b4d80 icon validator: Fix an off-by-one
I meant to allow 16 as a size limit.
2019-01-18 07:47:38 -05:00
Matthias Clasen
730dab95f5 Add a utility to validate icons
This is copied from xdg-desktop-portal.

Closes: #2523
Approved by: alexlarsson
2019-01-17 07:27:31 +00:00