Commit Graph

3713 Commits

Author SHA1 Message Date
Frediano Ziglio
d17e7878cb Remove useless typedefs
Just use forward declaration if needed.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
2021-08-26 20:59:41 +01:00
Frediano Ziglio
55897eba0f Remove some constant usage, use size from arrays
Makes more clear that we are scanning entire arrays or
checking for some container boundaries.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
2021-08-26 09:02:41 +01:00
Frediano Ziglio
e0dab7f4ef reds: Use proper maximum constant for time_t
Some systems use 32-bits, other 64-bits.
Some systems use signed integers, other unsigned integers.
Compute maximum constant based on time_t type.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2021-08-26 07:37:51 +01:00
Rosen Penev
5513bce73e clang-tidy: replace C headers with C++
Found with modernize-deprecated-headers

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2021-08-26 07:35:09 +01:00
Rosen Penev
24f67439e4 several conversions to std::array
These conversions allowed extra conversions to for range loops in
addition to replacing macro usage with .size().

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2021-08-23 10:41:11 +01:00
Frediano Ziglio
258fda6290 Remove now useless check
display_channel_surface_id_unref resets the surface so
display_channel_surface_has_canvas will return false.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-07 07:46:15 +01:00
Frediano Ziglio
d8bca15f2b Allows surfaces to be updated without having to wait
Store pointers to surface object in "surfaces" and allows to
have different surfaces with same ID in memory.
The surface was keep "busy" if there was pending drawing around.

Consider the following case:
 1- receive drawing command
 2- queue command on DCCs
 3- destroy surface
 4- send draw
Previously at point 4) you would have to use a surface from
"surfaces" which was destroyed, that is we would have to maintain
the pointer (and canvas) to the surface until reference counter
was 0.

However consider this case:
 1- receive drawing command
 2- queue command on DCCs
 3- destroy surface
 4- create surface
 5- send draw
What would happen in point 4) ?
We could not change the surface as it will be used by point 5).
To avoid this the code attempts to wait the commands to release the
surface. However this can be an issue, you can't force the clients
to receive pending data if network is slow.

So this patch change this allowing to create surfaces while the old
version will still be used.

This is also more clean from the reference pointer prospective,
as the reference is increased for a specific surface.

Note that now instead of checking for canvas to not be NULL a
simple check for surface pointer is enough.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-07 07:46:12 +01:00
Frediano Ziglio
f5c2043143 Remove last direct surface IDs usages
Mostly left on dcc-send.cpp.
Other minor too.

The change in BitmapData seems odd but the id for cached image
was not used so the only information left was the surface.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-07 07:46:09 +01:00
Frediano Ziglio
4434c6fb96 Change validate_surface to return surface pointer
Instead of computing the value inside the function to then
compute also in the caller return it.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-07 07:46:07 +01:00
Frediano Ziglio
1d123192e7 Use directly surface instead of id
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-07 07:46:05 +01:00
Frediano Ziglio
74c660ddad Pass surface directly to dcc_push_surface_image
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-07 07:46:04 +01:00
Frediano Ziglio
3b790b8ad6 Pass surface directly to dcc_create_surface
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-07 07:46:02 +01:00
Frediano Ziglio
78bc3a637a New function to pass surface directly to display_channel_draw
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-07 07:46:01 +01:00
Frediano Ziglio
5a5d1e21b5 Pass surface directly calling display_channel_current_flush
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-07 07:45:59 +01:00
Frediano Ziglio
58a612a039 Pass surface directly calling dcc_clear_surface_drawables_from_pipe
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-07 07:45:57 +01:00
Frediano Ziglio
2b219cace5 Pass surface directly calling draw_depend_on_me and display_channel_destroy_surface
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-07 07:45:55 +01:00
Frediano Ziglio
493077d080 Pass surface directly in is_primary_surface
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-07 07:45:54 +01:00
Frediano Ziglio
f418bbb522 Pass surface directly to display_channel_surface_unref
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-07 07:45:52 +01:00
Frediano Ziglio
977e72eb48 Pass surface directly to current_remove_all
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-07 07:45:51 +01:00
Frediano Ziglio
19eb9995b2 Pass surface directly for surface_read_bits
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-07 07:45:48 +01:00
Frediano Ziglio
6933c6dd14 Use direct pointers for surface and surface dependencies from Drawable
As we use reference counting is more direct to use direct pointers.
Also this will allow to have a surface in a "released state"
reducing the complexity of code destroying a surface.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-07 07:45:38 +01:00
Frediano Ziglio
708cd97212 red-parse-qxl: Encapsulate QXL resource management
Reuse code.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-04 13:01:14 +01:00
Frediano Ziglio
b6aa5798b7 red-parse-qxl: Use a base reference class for RedDrawable
Don't code manually reference counting for this structure

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-04 13:01:12 +01:00
Frediano Ziglio
110b97e51e red-parse-qxl: Use a base reference class for RedUpdateCmd
Don't code manually reference counting for this structure

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-04 13:01:10 +01:00
Frediano Ziglio
45f2d94ac3 red-parse-qxl: Use a base reference class for RedMessage
Don't code manually reference counting for this structure

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-04 13:01:09 +01:00
Frediano Ziglio
6eac8cc08f red-parse-qxl: Use a base reference class for RedSurfaceCmd
Don't code manually reference counting for this structure

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-04 13:01:07 +01:00
Frediano Ziglio
1d4fb2fee7 red-parse-qxl: Use a base reference class for RedCursorCmd
Don't code manually reference counting for this structure

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-04 13:01:05 +01:00
Frediano Ziglio
a3656e217d utils: Add a base light class for reference counting
Similar to shared_ptr_counted but avoid atomic counter and
polymorphism.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-08-04 13:01:01 +01:00
Frediano Ziglio
cc4d6559b2 sound: Use SpiceAudioDataMode type for audio mode
Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2021-06-14 11:28:37 +01:00
Frediano Ziglio
0088659c37 cursor-channel-client: Remove unused variable
Both _cursor_count and DEBUG_CURSORS are not used.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-06-04 08:56:44 +01:00
Frediano Ziglio
71284c4984 red-worker: Limit visibility
Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-06-01 22:08:55 +01:00
Frediano Ziglio
1b02f2d3d0 red-worker: Associate message structure and numbers
Makes sure a message is sent with the proper message number.
Reduce mistakes associating types with wrong registered number.
Make easier to add new messages in the future.
Avoids having to type the message number every time, it's inferred
from the type.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-06-01 22:08:55 +01:00
Frediano Ziglio
c8e4e467be red-worker: Reduce casts needed in dispatcher handlers
Use a template to deduct type and avoid casts in every handler.
The reinterpret_cast seems strong but is safe as converting
a function with 2 typed pointers and a void return into a function
with 2 void pointers and a void return.
The unsafety left (not a regressions) is the association between
handler number and message type.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-06-01 22:08:55 +01:00
Frediano Ziglio
84e1788d3a reds: Fix closure of SpiceServer in case of connected clients
When spice_server_destroy is called with pending clients (currently
not a big issue, usually the programs using SPICE server are
exiting then), some leaks can happen.
This is due to the fact that some dispatcher messages are queued
to handle some serialization but then they are neved executed as
the entire system is closed.
Close all connections and handle all main dispatcher messages
to remove these leaks.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-06-01 21:47:29 +01:00
Frediano Ziglio
c63f166bb1 display-channel: Rename parameter for consistency
display_channel -> display.
In all the rest of the file display is used.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-06-01 21:47:27 +01:00
Frediano Ziglio
435ba9228f display-channel: Use constructor and destructor for Drawable
This will allow to use not trivial objects inside the structure.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-06-01 21:47:21 +01:00
Rosen Penev
3f5ba6e565 red-client: Remove FOREACH_CHANNEL_CLIENT macro
Since the conversion to a for range loop, there's no point to this
macro.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2021-06-01 09:02:48 +01:00
Rosen Penev
4b56942bf5 reds: Remove FOREACH_QXL_INSTANCE macro
Since the conversion to a for range loop, there's no point to this
macro.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2021-06-01 09:02:32 +01:00
Rosen Penev
115260e4e5 Manual algorithm changes
Signed-off-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2021-05-31 08:08:26 +01:00
Frediano Ziglio
3de587a76c red-stream: Fix issue with SASL and no-Glibc
Using Unix sockets and no-Glibc C libraries (like Musl) getnameinfo
will fail causing SASL code to fail initialization.
Replicate Glibc behavior and report "localhost" as host and an
empty port string.

This fixes https://gitlab.freedesktop.org/spice/spice/-/issues/58.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
2021-05-24 08:37:11 +01:00
Rosen Penev
8104fc3456 Manual algorithm changes
Signed-off-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2021-05-23 10:32:07 +01:00
Rosen Penev
51092046f7 Remove several usages of SPICE_N_ELEMENTS
It's simpler to just use a for range loop.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2021-05-23 10:01:39 +01:00
Frediano Ziglio
c5412b071a stream-channel: Fix compiler warning
This removes:

In function ‘stream_channel_get_supported_codecs’,
    inlined from ‘on_connect’ at ../server/stream-channel.cpp:364:60:
../server/stream-channel.cpp:326:31: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
  326 |             out_codecs[num++] = codec;
      |                               ^
../server/stream-channel.cpp: In member function ‘on_connect’:
/usr/include/spice-1/spice/stream-device.h:209:13: note: destination object ‘codecs’ of size 0
  209 |     uint8_t codecs[0];
      |             ^

Reported by by Tomasz Kłoczko in
https://gitlab.freedesktop.org/spice/spice/-/issues/44

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
2021-05-18 10:14:26 +01:00
Frediano Ziglio
0b86b6808a tests: Fix -Wodr warning compiling tests with LTO enabled
Avoid the compiler to see 2 different defines of the same
structure.
Reported by Tomasz Kłoczko in
https://gitlab.freedesktop.org/spice/spice/-/issues/44

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
2021-05-18 10:14:21 +01:00
Frediano Ziglio
cb9bd1b09e Make headers independent
Make sure all headers can be compiled alone.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
2021-05-18 10:13:41 +01:00
Frediano Ziglio
1201113acd build: Better version checks and handling for Meson
Strip dirty and git hash.
Check that there are at least 3 numbers at the beginning.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
2021-05-18 09:40:28 +01:00
Frediano Ziglio
a5e0f86bc2 Removed only written "items" field from PixmapCache
Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
2021-05-18 08:38:27 +01:00
orbea
c5fe3df1ef build: Fix undefined pthread references
The build fails with slibtool while GNU libtool hide the issue
by silently ignoring -no-undefined.

ax_pthread.m4 is sourced from:

e68e8f6f62/m4/ax_pthread.m4

Downstream issue: https://bugs.gentoo.org/780027

Signed-off-by: orbea <orbea@riseup.net>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2021-05-18 08:30:15 +01:00
Rosen Penev
9462537d24 clang-tidy: fix inconsistent declarations
Found with readability-inconsistent-declaration-parameter-name

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2021-05-09 11:19:30 +01:00
Rosen Penev
aefcd7d1c4 clang-tidy: use uppercase numeric literals
Found with readability-uppercase-literal-suffix

Avoids readability problems between lower case l and uppercase I.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2021-05-09 07:00:21 +01:00
Rosen Penev
9fb945c31b clang-tidy: replace typedef with using
Found with modernize-use-using

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2021-05-09 06:38:36 +01:00
Frediano Ziglio
748cc409f6 dispatcher: Avoid casts for raw buffers
Usually buffers to raw data are passed using void* pointers
to avoid casts and mark the buffer as raw.
Use them for read_safe and write_safe to avoid useless casts
in caller code.
As a minor convert a parameter to bool as changing the same
lines.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-05-05 09:13:33 +01:00
Rosen Penev
0bc7e80ec6 clang-tidy: convert C casts to C++ ones
Found with google-readability-casting

https://google.github.io/styleguide/cppguide.html#Casting

Makes the operation clearer.

This commit uses const_cast where needed.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2021-05-05 07:03:55 +01:00
Frediano Ziglio
62dd7e47e9 tests: Remove some compiler warnings
Remove warnings like:

In file included from /usr/include/glib-2.0/glib.h:86,
                 from ../server/tests/test-glib-compat.h:21,
                 from ../server/tests/test-channel.cpp:25:
In function 'void send_ack_sync(int, uint32_t)',
    inlined from 'void channel_loop()' at ../server/tests/test-channel.cpp:250:18:
../server/sys-socket.h:28:43: error: 'ssize_t write(int, const void*, size_t)' reading 10 bytes from a region of size 2 [-Werror=stringop-overread]
   28 | #define socket_write(sock, buf, len) write(sock, buf, len)
/usr/include/glib-2.0/glib/gtestutils.h:50:61: note: in definition of macro 'g_assert_cmpint'
   50 |                                              gint64 __n1 = (n1), __n2 = (n2); \
      |                                                             ^~
../server/tests/test-channel.cpp:132:21: note: in expansion of macro 'socket_write'
  132 |     g_assert_cmpint(socket_write(socket, &msg.type, 10), ==, 10);
      |                     ^~~~~~~~~~~~
../server/tests/test-channel.cpp: In function 'void channel_loop()':
../server/tests/test-channel.cpp:123:18: note: source object 'send_ack_sync(int, uint32_t)::<unnamed struct>::type' of size 2
  123 |         uint16_t type;
      |                  ^~~~
In file included from ../server/tests/test-channel.cpp:22:
/usr/include/unistd.h:367:16: note: in a call to function 'ssize_t write(int, const void*, size_t)' declared with attribute 'access (read_only, 2, 3)'
  367 | extern ssize_t write (int __fd, const void *__buf, size_t __n) __wur
      |                ^~~~~
cc1plus: all warnings being treated as errors

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2021-05-05 06:36:18 +01:00
Frediano Ziglio
e39412644c ci: Ignore a leak in glib threading pool
The leak is detected by Valgrind on Fedora 34as:

==19603== 400 bytes in 1 blocks are possibly lost in loss record 2,296 of 2,441
==19603==    at 0x4845464: calloc (vg_replace_malloc.c:1117)
==19603==    by 0x40135FB: _dl_allocate_tls (in /usr/lib64/ld-2.33.so)
==19603==    by 0x57EB008: pthread_create@@GLIBC_2.2.5 (in /usr/lib64/libpthread-2.33.so)
==19603==    by 0x53A1130: UnknownInlinedFun (gthread-posix.c:1323)
==19603==    by 0x53A1130: g_thread_new_internal (gthread.c:931)
==19603==    by 0x53C4953: g_thread_pool_start_thread.constprop.0 (gthreadpool.c:477)
==19603==    by 0x53A2902: g_thread_pool_push (gthreadpool.c:691)
==19603==    by 0x519AE11: g_task_run_in_thread_sync (gtask.c:1593)
==19603==    by 0x80D8A74: ??? (in /usr/lib64/gio/modules/libgiolibproxy.so)
==19603==    by 0x5181966: g_proxy_address_enumerator_next (gproxyaddressenumerator.c:176)
==19603==    by 0x519281A: g_socket_client_connect (gsocketclient.c:1098)

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2021-05-05 06:36:14 +01:00
Frediano Ziglio
7fe49b6465 Update glib.supp to new version
Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2021-05-05 06:36:12 +01:00
Frediano Ziglio
8c458fa35e Fix g_memdup deprecation warning with glib >= 2.68
Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2021-05-05 06:35:56 +01:00
Qiuhao Li
1fae1191e5 reds: fix nullptr deref in red-parse-qxl.cpp
At red-parse-qxl.cpp#L535

        if (qxl_flags & QXL_BITMAP_DIRECT) {
            red->u.bitmap.data = red_get_image_data_flat(slots, group_id,
                                                         qxl->bitmap.data,
                                                         bitmap_size);

Since qxl->bitmap.data may from the guest, an attacker can make the
memslot_get_virt() check in red_get_image_data_flat() fail and
return a nullptr.

Then at red-parse-qxl.cpp#L550

        if (qxl_flags & QXL_BITMAP_UNSTABLE) {
            red->u.bitmap.data->flags |= SPICE_CHUNKS_FLAGS_UNSTABLE;
        }

qxl_flags is assigned as qxl->bitmap.flags before, which can also be
controlled by the attacker, resulting in a NULL pointer dereference.

This dereference seems to be introduced by commit 5ac88aa7.

Signed-off-by: Qiuhao Li <Qiuhao.Li@outlook.com>
2021-04-23 06:52:48 +01:00
Roman Bogorodskiy
3c1d87ccfe Fix setsockopt on FreeBSD
FreeBSD's setsockopt() behaves just like Dawrin, i.e. sets errno to
EINVAL instead of ENOTSUP, so extend the Darwin workaround to work for
FreeBSD as well.

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2021-04-17 13:19:17 +01:00
Roman Bogorodskiy
8b03c6fb64 red-stream: add missing include
On FreeBSD, netinet/in.h needs to be included to use IPPROTO_TCP.

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2021-04-17 13:19:17 +01:00
Stefan Weil
691bd67ff8 Avoid build error caused by conflicting types for INT32
Compiler error for cross builds using mingw-w64:

In file included from /usr/share/mingw-w64/include/winnt.h:150,
                 from /usr/share/mingw-w64/include/minwindef.h:163,
                 from /usr/share/mingw-w64/include/windef.h:9,
                 from /usr/share/mingw-w64/include/windows.h:69,
                 from /usr/share/mingw-w64/include/winsock2.h:23,
                 from ../../../server/spice-core.h:29,
                 from ../../../server/spice.h:24,
                 from ../../../server/spice-wrapped.h:35,
                 from ../../../server/red-common.h:35,
                 from ../../../server/jpeg-encoder.c:22:
/usr/share/mingw-w64/include/basetsd.h:31:22: error: conflicting types for ‘INT32’
   typedef signed int INT32,*PINT32;
                      ^~~~~
In file included from /usr/x86_64-w64-mingw32/sys-root/mingw/include/jpeglib.h:31,
                 from ../../../server/jpeg-encoder.c:20:
/usr/x86_64-w64-mingw32/sys-root/mingw/include/jmorecfg.h:179:14: note: previous declaration of ‘INT32’ was here
 typedef long INT32;
              ^~~~~

Signed-off-by: Stefan Weil <sw@weilnetz.de>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2021-04-15 08:51:44 +01:00
Frediano Ziglio
9bd0d5cc81 Fix failure strings in tests
Otherwise tests will fail due to source code change.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
2021-04-14 19:05:09 +04:00
Rosen Penev
5f8d49efaa clang-tidy: remove pointless move
Found with performance-move-const-arg

Allows better optimization as the compiler does not have to deal with an
rvalue reference. Especially in C++17 where std::move can prevent copy
elision.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2021-04-14 13:07:40 +01:00
Rosen Penev
8af176b15e clang-tidy: use nullptr
Found with modernize-use-nullptr

NULL in C++ is 0 whereas it is a void pointer in C. Avoids implicit
conversions.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2021-04-12 06:50:05 +01:00
Rosen Penev
24dfe33c06 clang-tidy: use const reference for loop
Found with performance-for-range-copy

Avoids unnecessary copying when the loop does not modify the variable.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2021-04-12 06:50:03 +01:00
Rosen Penev
fc9ca6c71a clang-tidy: do not use else after return
Found with readability-else-after-return

Easier to read.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2021-04-11 07:49:21 +01:00
Rosen Penev
944dc8662e clang-tidy: use auto
Found with modernize-use-auto

auto is shorter and can sometimes disambiguate pointer constness.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2021-04-11 07:44:42 +01:00
Rosen Penev
04e885b291 clang-tidy: test for empty instead of size
Found with readability-container-size-empty

This has the potential for extra performance as it's not checking for
every single element.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2021-04-09 08:23:52 +01:00
Rosen Penev
23bd93bfb4 clang-tidy: use bool literals
Found with modernize-use-bool-literals

Avoids implicit conversions.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2021-04-09 08:21:48 +01:00
Rosen Penev
68b0f3029d clang-tidy: use const reference for loop
Found with performance-for-range-copy

Avoids unnecessary copying when the loop does not modify the variable.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2021-04-09 08:21:19 +01:00
Rosen Penev
e353f1a065 clang-tidy: use default
Found with modernize-use-equals-default

default allows extra optimization compared to an empty con/destructor.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2021-04-09 08:20:11 +01:00
Rosen Penev
f64e61e44d clang-tidy: use override and remove virtual
Found with modernize-use-override

This can be useful as compilers can generate a compile time error when:
	The base class implementation function signature changes.
        The user has not created the override with the correct
	signature.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2021-04-09 08:20:06 +01:00
Rosen Penev
20fa56d75d clang-tidy: simplify boolean expression
Found with readability-simplify-boolean-expr

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2021-04-08 16:24:39 +01:00
Rosen Penev
76f4dc436a clang-tidy: add explicit to single argument constructors
Found with google-explicit-constructor

Explicit prevents type conversions for safety reasons.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2021-04-08 16:21:10 +01:00
Rosen Penev
11374b28b4 clang-tidy: remove pointless void
Found with modernize-redundant-void-arg

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2021-04-08 16:18:17 +01:00
Rosen Penev
9f1514b804 clang-tidy: use using
Found with modernize-use-using

Also manually removed a bunch of typedefs as they are no longer useful
in C++.

https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rt-using

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2021-04-08 16:18:02 +01:00
Frediano Ziglio
9af2193f2c Fix non-trivial designated initializers for old Gnu C++ compilers
Fix this error reported by some older Gnu C++ compilers:

./server/tests/test-display-base.cpp:818:1: sorry, unimplemented: non-trivial designated initializers not supported

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2021-02-08 09:47:32 +00:00
Marc-André Lureau
51073b98cb worker: ignore subsequent stop messages
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2021-01-29 10:03:43 +00:00
Marc-André Lureau
c23cbd6fa8 reds: start QXL devices if VM is running
Like char devices, QXL devices need to be explicily started.

For some historical reason, char devices are started when in running
state. See commi bf1d9007b. Reading that commit comments, there was a
plan to provide an API to stop/start devices invidually, but that never
happened. Whether that API would really be useful now, I wonder.

For now, just follow the char devices behaviour and start QXL devices
added when vm_running.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.uuuuucom>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2021-01-29 10:03:24 +00:00
Marc-André Lureau
76c59470ef worker: ignore subsequent start messages
If the worker is already started, don't assert and just return.

This fixes calling spice_server_vm_start() multiple times.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2021-01-28 09:30:18 +00:00
Julien Ropé
95a0cfac8a With OpenSSL 1.0.2 and earlier: disable client-side renegotiation.
Fixed issue #49
Fixes BZ#1904459

Signed-off-by: Julien Ropé <jrope@redhat.com>
Reported-by: BlackKD
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2020-12-07 14:43:32 +00:00
Julien Ropé
ca5bbc5692 With OpenSSL 1.1: Disable client-initiated renegotiation.
Fixes issue #49
Fixes BZ#1904459

Signed-off-by: Julien Ropé <jrope@redhat.com>
Reported-by: BlackKD
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2020-12-07 14:43:24 +00:00
Julien Ropé
d8c6ff25b6 ci: suppress new possible loss coming with Fedora 33
- remove entry for g-type-register-static: the "possible" flag has been
  re-introduced in glib.supp
- add new entries for several calloc issues

Signed-off-by: Julien Ropé <jrope@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2020-12-07 11:13:13 +00:00
Julien Ropé
5f06f847dd ci: update glib.supp file
Sync with Glib master file.

Signed-off-by: Julien Ropé <jrope@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2020-12-07 11:13:07 +00:00
Frediano Ziglio
de5c20531e reds: Check VDAgentMonitorsConfig using spice-common code
Reduce code duplication.
Also this improve support for big endian machines as
agent_check_message fix also message endianess.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Uri Lublin <ulublin@redhat.com>
2020-10-25 20:02:16 +00:00
Frediano Ziglio
587c04f79e Improve big endian support for agent messages
Big endian machines on server are not officially supported but won't
hurt.
Messages from client are always encoded as little endian (as all
SPICE protocol).
Convert fields from little endian to host endian on some places
where numbers are used and not just binary copied.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Uri Lublin <ulublin@redhat.com>
2020-10-25 20:01:54 +00:00
Frediano Ziglio
4f71d0cdb7 Update spice-common submodule
This brings in the following changes:

Frediano Ziglio (18):
      snd_codec: Use better types for snd_codec_is_capable
      snd_codec: Use better type for function result
      snd_codec: Use better type for snd_codec_create mode
      backtrace: Do not attempt to compile if spice_backtrace is empty
      Avoid usage of GCC extension for __VA_ARGS__ where possible
      helper-fuzzer-demarshallers: Provide replacement for ftello for MSVC
      quic_tmpl: Remove unused bpc parameter
      ssl_verify: Do not check IP if we fail to resolve it
      proto: Add support for side mouse buttons
      quic: Constify a parameter
      quic: Fix typo in comment
      agent: Extend agent_check_message to support VDAgentMonitorsConfig extension
      quic: Check we have some data to start decoding quic image
      quic: Check image size in quic_decode_begin
      quic: Check RLE lengths
      quic: Avoid possible buffer overflow in find_bucket
      test-quic: Add fuzzer capabilities to the test
      test-quic: Add test cases for quic fuzzer

Haochen Tong (2):
      pixman_utils: fix clang "unused functions" warning
      marshal: fix clang "missing field initializer" warning on generated files

Marc-André Lureau (1):
      agent: fix vdagent monitor flag filtering

Changes in sound.cpp are required due to improved types.

In particular some security related changes are imported.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Uri Lublin <ulublin@redhat.com>
2020-10-24 14:34:39 +01:00
Frediano Ziglio
37fd91a51f build-sys: Fix computed version using Meson
In configure.ac the micro version is incremented if there is a
forth component in the version.
In Meson this was wrongly translated to "if contains git".

This fixes Gitlab issue #46.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
2020-09-30 14:03:45 +01:00
Marc-André Lureau
d1bea58002 reds: fix vdagent monitor flag filtering
Fixes commit 828c881bd0a8d73a5c2038bdf22cb8ae7c793482 ("agent/qxl: add
monitors physical dimensions handling").

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2020-09-17 06:43:48 +01:00
Frediano Ziglio
f1e89573b6 reds: Specify virtual functions override RedCharDevice functions
Remove some possible warning, like

reds.cpp:216:18: warning: 'remove_client' overrides a member function but is not marked 'override' [clang-diagnostic-inconsistent-missing-override]
    virtual void remove_client(RedCharDeviceClientOpaque *opaque);
                 ^

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Uri Lublin <ulublin@redhat.com>
2020-09-16 14:34:17 +01:00
Frediano Ziglio
efc02a8c0f spicevmc: Remove unused declarations
Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Uri Lublin <ulublin@redhat.com>
2020-09-16 14:34:15 +01:00
Marc-André Lureau
828c881bd0 agent/qxl: add monitors physical dimensions handling
Requires
https://gitlab.freedesktop.org/spice/spice-protocol/-/merge_requests/24

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2020-09-14 14:35:12 +01:00
Frediano Ziglio
5223aeed32 reds: Use g_strlcpy instead of strlen/strcpy
Some compiler could generate some warning, like

reds.cpp:2678:5: warning: Call to function 'strcpy' is insecure as it does not provide bounding of the memory buffer. Replace unbounded copy functions with analogous functions that support length arguments such as 'strlcpy'. CWE-119 [clang-analyzer-security.insecureAPI.strcpy]
    strcpy(buf, pass);
    ^

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Jakub Janků <jjanku@redhat.com>
2020-09-13 19:47:20 +01:00
Frediano Ziglio
8bb90e55aa inputs-channel: Support more mouse buttons
Extend mouse button bits support.
Allows to support up to 16 buttons.

Partly based on a patch from Kevin Pouget (RED_MOUSE_BUTTON_STATE_TO_AGENT
macro, updated on new protocol constants).

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Kevin Pouget <kpouget@redhat.com>
2020-09-02 09:21:03 +01:00
Frediano Ziglio
2899fd91fb dcc-send: Fix a regression adding an image item to the pipe
The regression was introduced by

    commit 22fc6a48e6

    red-channel-client: Change GQueue into a std::list

    Starts using smart pointers in the queue.

dcc_add_surface_area_image added a new pipe item in front if pos was
NULL. Before the commit red_add_lossless_drawable_dependencies passed
a pointer to the last element in the pipe adding the new item on the
back. The change caused the item to be inserted in front instead of
back. Restore the insert position.
This caused in some condition the pipe to grow uncontrollably (like
using a large notepad window on Windows 7 and moving it around).

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
2020-07-20 16:36:20 +01:00
Frediano Ziglio
8dcbc99d3f red-channel-client: Change gboolean -> bool
Avoid possible type conversion

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Julien Ropé <jrope@gmail.com>
2020-07-20 10:17:22 +01:00
Frediano Ziglio
30d917ba5d red-channel-client: Make RedChannelClient::pipe_item_is_linked const
Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Julien Ropé <jrope@gmail.com>
2020-07-20 10:17:20 +01:00
Frediano Ziglio
db61c35e7f red-channel-client: Make some members const
This is now easier moving from GQueue to std::list.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Julien Ropé <jrope@gmail.com>
2020-07-20 10:17:14 +01:00
Uri Lublin
8d8745211d mjpeg_encoder_reset_quality: do not hint inline
Let the compiler decide.

Apparently it causes CI makecheck to fail (see below).
Seems to me it's a gcc problem -- was working with version 9,
fails with version 10.
Making the function a non-inline one "fixes" this issue.
Alternatively adding to the structure "int dummy" above the "int type"
"fixes" the build too (but I went with the non-inline solution).

==== error ====
  CC       mjpeg-encoder.lo
In file included from /usr/include/string.h:495,
                 from ../../server/red-common.h:24,
                 from ../../server/mjpeg-encoder.c:25:
In function ‘memset’,
    inlined from ‘mjpeg_encoder_reset_quality’ at ../../server/mjpeg-encoder.c:385:5,
    inlined from ‘mjpeg_encoder_quality_eval_stop.part.0’ at ../../server/mjpeg-encoder.c:999:5:
/usr/include/bits/string_fortified.h:71:10: error: ‘__builtin_memset’ offset [788, 871] from the object at ‘encoder’ is out of the bounds of referenced subobject ‘type’ with type ‘int’ at offset 784 [-Werror=array-bounds]
   71 |   return __builtin___memset_chk (__dest, __ch, __len, __bos0 (__dest));
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../server/mjpeg-encoder.c: In function ‘mjpeg_encoder_quality_eval_stop.part.0’:
../../server/mjpeg-encoder.c:96:9: note: subobject ‘type’ declared here
   96 |     int type;
      |         ^~~~
cc1: all warnings being treated as errors

Acked-by: Frediano Ziglio <fziglio@redhat.com>
2020-07-17 07:45:16 +01:00
Frediano Ziglio
10749220dd Encapsulate more pipe item initialisation in constructors
Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Julien Ropé <jrope@gmail.com>
2020-07-13 19:48:27 +01:00