Commit Graph

723 Commits

Author SHA1 Message Date
Christophe Fergeau
f522473842 build: By default, error out if Opus is missing
Following the commit disabling celt by default, it's quite easy to have
a build without both celt and opus. After this commit, Opus will have to
be installed for a successful build unless one passes --disable-opus.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-06-05 14:10:02 +01:00
Christophe Fergeau
72b0d603e1 build: Disable celt 0.5.1 by default
This version of the CELT codec has long been obsolete, and Opus support
has been added nearly 5 years ago. It's time we move on and try to stop
using Celt ;)
This commit disables CELT by default, but since this could be an
unexpected change for packagers, if CELT 0.5.1 development headers are
installed, it will error out unless --enable-celt051/--disable-celt051
has been explicitly specified.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-06-05 14:09:55 +01:00
Christophe Fergeau
e98f8a430f build: Ensure we link with -lm if needed
lines.c uses hypot(), which is found in libm on some systems. This means
we are currently relying on getting -lm indirectly through some other
means, as otherwise linking any binary with spice-common would fail.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-06-05 14:09:50 +01:00
Frediano Ziglio
349a74d7c2 quic: Fix endianness encoding
The image is going to network and network protocol is little endian
so the numbers has to be little endian. Note that this is already done
during decoding.
Tested on a ppc64 machine.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2018-06-04 16:05:20 +01:00
Eduardo Lima (Etrunko)
55070333f6 Add support for building with meson/ninja
In a comparison with current autotools build system, meson/ninja
provides a huge improvement in build speed, while keeping the same
functionalities currently available and being considered more user
friendly.

The new system coexists within the same repository with the current one,
so we can do more extensive testing of its functionality before deciding
if the old system can be removed, or for some reason, has to stay for
good.

- Meson: https://mesonbuild.com

  This is the equivalent of autogen/configure step in autotools. It
  generates the files that will be used by ninja to actually build the
  source code.

  The project has received lots of traction recently, with many GNOME
  projects willing to move to this new build system. The following wiki
  page has more details of the status of the many projects being ported:

    https://wiki.gnome.org/Initiatives/GnomeGoals/MesonPorting

  Meson has a python-like syntax, easy to read, and the documentation
  on the project is very complete, with a dedicated page on how to port
  from autotools, explaining how most common use cases can be
  implemented using meson.

    http://mesonbuild.com/Porting-from-autotools.html

  Other important sources of information:

    http://mesonbuild.com/howtox.html
    http://mesonbuild.com/Syntax.html
    http://mesonbuild.com/Reference-manual.html

- Ninja: https://ninja-build.org

  Ninja is the equivalent of make in an autotools setup, which actually
  builds the source code. It has being used by large and complex
  projects such as Google Chrome, Android and LLVM. There is not much to
  say about ninja (other than it is much faster than make) because we
  won't interact directly with it as much, as meson does the middle man
  job here. The reasoning for creating ninja in the first place is
  explained on the following post:

    http://neugierig.org/software/chromium/notes/2011/02/ninja.html

  Also its manual provides more in-depth information about the design
  principles:

    https://ninja-build.org/manual.html

- Basic workflow:

  Meson package is available for most if not all distros, so, taking
  Fedora as an example, we only need to run:

    # dnf -y install meson ninja-build.

  With Meson, building in-tree is not possible at all, so we need to
  pass a directory as argument to meson where we want the build to be
  done. This has the advantage of creating builds with different options
  under the same parent directory, e.g.:

    $ meson ./build --prefix=/usr
    $ meson ./build-extra -Dextra-checks=true -Dalignment-checks=true

  After configuration is done, we call ninja to actually do the build.

    $ ninja -C ./build
    $ ninja -C ./build install

  Ninja defaults to parallel builds, and this can be changed with the -j
  flag.

    $ ninja -j 10 -C ./build

- Hacking:

  * meson.build: Mandatory for the project root and usually found under
                 each directory you want something to be built.

  * meson_options.txt: Options that can interfere with the result of the
                       build.

Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2018-06-01 21:27:04 +01:00
Eduardo Lima (Etrunko)
836bbd0e41 test-quic: Fix -Wsign-compare warning
../tests/test-quic.c: In function ‘gdk_pixbuf_new_random’:
../tests/test-quic.c:205:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 0; i < gdk_pixbuf_get_byte_length(random_pixbuf); i++) {
                   ^

Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-05-31 17:46:24 -03:00
Frediano Ziglio
68c0f93889 quic: Remove some too strict asserts in hot paths
Some assert in the code are doing some paranoid test and in code
paths quite hot.
The encoding time is reduced by 30-50% while the decoding time
is reduced by a 20-30%.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2018-05-31 07:34:17 +01:00
Frediano Ziglio
160232f8f6 quic: Remove 'no-inline' hack
The quic code goes through a function pointer in two places in order to
try to prevent the compiler from inlining code.
Doing performance measurements this trick does not work anymore
and just make code less readable.

This patch and message was based on a previous work of
Christophe Fergeau.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2018-05-28 11:27:01 +01:00
Christophe Fergeau
d58a5b6a5a quic: Add test case for compression/decompression
This only adds a basic test relying on gdk-pixbuf.
The main limitation is that gdk-pixbuf does not handle 16bpp images,
nor 32bpp/no alpha images. I should have picked something else instead ;)

This allows at least to exercise the QUIC_IMAGE_TYPE_RGB24 and
QUIC_IMAGE_TYPE_RGBA codepaths.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-05-25 17:04:23 +01:00
Frediano Ziglio
5312ea3f35 lz: Inline GET_{r,g,b} macros
With last changes are just used once and are straight forward.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: jonathon Jongsma <jjongsma@redhat.com>
2018-05-25 11:54:18 +01:00
Frediano Ziglio
70aa6d39b6 lz: Optimise SAME_PIXEL for RGB16
Do not extract all components and compare one by one, can be easily
compared together.
Performance measurements on a set of 16 bit images shown an improve of
about 10%.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2018-05-25 11:54:18 +01:00
Christophe Fergeau
a1f6f42a33 quic: Use channel->correlate_row in macros
This avoids the need for a local variable with the right name (which
was decorrelate_drow in some cases in quic_tmpl.c...)

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-05-24 17:20:38 +01:00
Christophe Fergeau
0e550416f1 quic: Remove unused argument in uncompress_row{0, }
'correlation_row' is always set to channel->colleration_row, and we
already pass 'channel' as an argument.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-05-24 12:18:49 +01:00
Christophe Fergeau
8152238618 quic: Add macros to make quic_tmpl.c much closer to quic_rgb_tmpl.c
Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-05-24 12:18:44 +01:00
Christophe Fergeau
423518768e quic: s/decorrelate_drow/correlate_row
The naming is odd as this is just an alias for channel->correlate_row.
This will also help in subsequent commits to make things more
consistent with quic_rgb_tmpl.c

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-05-24 12:18:40 +01:00
Christophe Fergeau
4690e7239d quic: Introduce CommonState *state variable in templates
Most functions in quic_tmpl.c/quic_rgb_tmpl.c have only superficial
differences. One of them is using channel->state or encoder->rgb_state.

This commit adds a local CommonState *state in all template methods
which will be used instead of channel->state or encoder->rgb_state.
This makes it easier to spot the common code between the 2 template
files...

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-05-24 12:18:37 +01:00
Christophe Fergeau
b9dd7ed8f1 quic: Factor common code
We don't need 2 different implementations when the only difference is
the CommonState which is being used.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-05-24 12:18:33 +01:00
Christophe Fergeau
d240af18a4 quic: Get rid of RLE #define
It's always set, no need to have conditional compilation based on it.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-05-24 11:01:31 +01:00
Christophe Fergeau
fce119be44 quic: Get rid of RLE_STAT #define
It's always set, no need to have conditional compilation based on it.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-05-24 11:01:28 +01:00
Christophe Fergeau
7b2c2e620e quic: Get rid of QUIC_RGB #define
It's always set, no need to have conditional compilation based on it.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-05-24 11:01:25 +01:00
Christophe Fergeau
763735d636 quic: Remove configurable PRED
It's hardcoded at compile-time, and I don't think it was changed in
years...

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-05-24 11:01:22 +01:00
Christophe Fergeau
0629153699 quic: Remove configurable RLE_PRED
It's hardcoded at compile-time, and I don't think it was changed in
years...

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-05-24 11:01:15 +01:00
Eduardo Lima (Etrunko)
d1d6210547 Bump glib requirements to 2.38
test-logging makes use of functions only available from this version

../tests/test-logging.c: In function ‘test_spice_abort_level’:
../tests/test-logging.c:50:5: error: ‘g_test_subprocess’ is deprecated: Not available before 2.38 [-Werror=deprecated-declarations]
     if (g_test_subprocess()) {
     ^~
In file included from /usr/include/glib-2.0/glib.h:82:0,
                 from ../tests/test-logging.c:23:
/usr/include/glib-2.0/glib/gtestutils.h:151:10: note: declared here
 gboolean g_test_subprocess (void);
          ^~~~~~~~~~~~~~~~~

Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-05-24 09:32:26 +01:00
Frediano Ziglio
b17894e764 Check for messages with duplicate values inside a channel
Make sure there are not 2 messages with the same value in the
same channel.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2018-05-23 10:33:05 +01:00
Frediano Ziglio
e2f7a9235f Check for messages with duplicate names inside a channel
Make sure there are not 2 messages with the same name in the
same channel.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2018-05-23 10:31:30 +01:00
Frediano Ziglio
abdef4fd2a codegen: Remove duplicate client and server code from ChannelType::resolve
Code that handled client and server messages check was the same, just
changed some variable names.
Instead use a class to store same information and reuse the code.
This allows easier extension of the 2 path of code.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Lukáš Hrázký <lhrazky@redhat.com>
2018-05-23 10:30:44 +01:00
Frediano Ziglio
78a17ba00a marshaller: Remove initial underscore from static function
This is the only function starting with an underscore, looks
out of style.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
2018-05-21 13:34:58 +01:00
Eduardo Lima (Etrunko)
8816d30e67 Fix cast to spice_marshaller_item_free_func function
Building with gcc 8.0.1 from Fedora 28 gives the following error:

FAILED: common/common@@spice-common@sta/marshaller.c.o
../common/marshaller.c: In function 'spice_marshaller_reserve_space':
../common/marshaller.c:311:27: error: cast between incompatible function types from 'void (*)(void *)' to 'void (*)(uint8_t *, void *)' {aka 'void (*)(unsigned char *, void *)'} [-Werror=cast-function-type]
         item->free_data = (spice_marshaller_item_free_func)free;
                           ^
cc1: all warnings being treated as errors

Which can be easily fixed by creating a new function with the correct
signature and calling free() from it.

Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2018-05-18 00:07:08 -03:00
Eduardo Lima (Etrunko)
d84f5a5e63 Fix field names for Smartcard protocol structures
Rename struct VSCMsgReaderAdd field 'reader_name' to 'name', and struct
VSCMsgATR field 'data' to 'atr' to match their definitions in file
vscard_common.h.

The error log follows:

generated_server_demarshallers.c:1985:30: note: each undeclared identifier is reported only once for each function it appears in
generated_server_demarshallers.c:1994:15: error: ‘VSCMsgReaderAdd {aka struct VSCMsgReaderAdd}’ has no member named ‘reader_name’
     memcpy(out->reader_name, in, reader_name__nelements);
               ^~

Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-05-17 21:03:01 +01:00
Eduardo Lima (Etrunko)
20bda4dba9 Fix demarshaller code generator
Even though commit df4ec5c318 commented
out most of smartcard code which triggered this error, it still might
happen if a new message is added with an array member.

The reason is a missing declaration of mem_size, which is fixed simply
by checking if the attribute 'nocopy' is present.

The error log follows:

generated_server_demarshallers.c: In function ‘parse_msgc_smartcard_reader_add’:
generated_server_demarshallers.c:1985:30: error: ‘mem_size’ undeclared (first use in this function); did you mean ‘nw_size’?
     data = (uint8_t *)malloc(mem_size);
                              ^~~~~~~~
                              nw_size

This patch also updates test-marshallers so that this bug is triggered.

The diff between generated demarshallers with the patch applied follows:

--- tests/generated_test_demarshallers.c.old    2018-05-17 14:35:29.234056487 -0300
+++ tests/generated_test_demarshallers.c        2018-05-17 14:35:40.554031295 -0300
@@ -286,6 +286,7 @@ static uint8_t * parse_msg_main_ArrayMes
     uint8_t *start = message_start;
     uint8_t *data = NULL;
     uint64_t nw_size;
+    uint64_t mem_size;
     uint8_t *in, *end;
     uint64_t name__nw_size;
     uint64_t name__nelements;
@@ -298,6 +299,7 @@ static uint8_t * parse_msg_main_ArrayMes
     }

     nw_size = 0 + name__nw_size;
+    mem_size = sizeof(SpiceMsgMainArrayMessage);

     /* Check if message fits in reported side */
     if (nw_size > (uintptr_t) (message_end - start)) {

Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-05-17 21:02:58 +01:00
Frediano Ziglio
129bd04766 test-overflow: Remove a leak in the test
This causes errors if Valgrind or sanitizer or similar memory
leak checkers are used.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
2018-05-17 15:16:28 +01:00
Eduardo Lima (Etrunko)
f97c9c3900 build: Remove FIXME_SERVER_SMARTCARD hack
This hack is now made obsolete by the previous commit. We can safely
remove those defines and the code now builds fine for both spice server
and spice-gtk.

commit df4ec5c318
Author: Frediano Ziglio <fziglio@redhat.com>
Date:   Fri May 11 16:59:46 2018 +0100

    Fix generation of Smartcard channel

Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-05-17 15:11:37 +01:00
Frediano Ziglio
df4ec5c318 Fix generation of Smartcard channel
The Smartcard channel definition has been always broken.
Multiple client messages with the same ID are defined in the channel.
This cause on server demarshaller to only have last message defined,
while on the client marshaller code all message marshallers are
defined but client uses only header message.

Following the difference of the generated code.

  diff -rup old/generated_client_marshallers.c common/generated_client_marshallers.c
  --- old/generated_client_marshallers.c	2018-05-14 22:49:07.641778414 +0100
  +++ common/generated_client_marshallers.c	2018-05-14 22:49:22.266329296 +0100
  @@ -389,27 +389,6 @@ static void spice_marshall_msgc_tunnel_s
   }

   #ifdef USE_SMARTCARD
  -static void spice_marshall_msgc_smartcard_data(SPICE_GNUC_UNUSED SpiceMarshaller *m, SPICE_GNUC_UNUSED SpiceMsgcSmartcard *msg, SpiceMarshaller **reader_name_out)
  -{
  -    SPICE_GNUC_UNUSED SpiceMarshaller *m2;
  -    SpiceMsgcSmartcard *src;
  -    *reader_name_out = NULL;
  -    src = (SpiceMsgcSmartcard *)msg;
  -
  -    /* header */ {
  -        spice_marshaller_add_uint32(m, src->header.type);
  -        spice_marshaller_add_uint32(m, src->header.reader_id);
  -        spice_marshaller_add_uint32(m, src->header.length);
  -    }
  -    if (src->header.type == SPICE_VSC_MESSAGE_TYPE_ReaderAdd) {
  -        /* Don't marshall @nomarshal reader_name */
  -    } else if (src->header.type == SPICE_VSC_MESSAGE_TYPE_ATR || src->header.type == SPICE_VSC_MESSAGE_TYPE_APDU) {
  -        /* Remaining data must be appended manually */
  -    } else if (src->header.type == SPICE_VSC_MESSAGE_TYPE_Error) {
  -        spice_marshaller_add_uint32(m, src->error.code);
  -    }
  -}
  -
   static void spice_marshall_msgc_smartcard_header(SPICE_GNUC_UNUSED SpiceMarshaller *m, SPICE_GNUC_UNUSED VSCMsgHeader *msg)
   {
       SPICE_GNUC_UNUSED SpiceMarshaller *m2;
  @@ -421,25 +400,6 @@ static void spice_marshall_msgc_smartcar
       spice_marshaller_add_uint32(m, src->length);
   }

  -static void spice_marshall_msgc_smartcard_error(SPICE_GNUC_UNUSED SpiceMarshaller *m, SPICE_GNUC_UNUSED VSCMsgError *msg)
  -{
  -    SPICE_GNUC_UNUSED SpiceMarshaller *m2;
  -    VSCMsgError *src;
  -    src = (VSCMsgError *)msg;
  -
  -    spice_marshaller_add_uint32(m, src->code);
  -}
  -
  -static void spice_marshall_msgc_smartcard_atr(SPICE_GNUC_UNUSED SpiceMarshaller *m, SPICE_GNUC_UNUSED VSCMsgATR *msg)
  -{
  -    SPICE_GNUC_UNUSED SpiceMarshaller *m2;
  -}
  -
  -static void spice_marshall_msgc_smartcard_reader_add(SPICE_GNUC_UNUSED SpiceMarshaller *m, SPICE_GNUC_UNUSED VSCMsgReaderAdd *msg)
  -{
  -    SPICE_GNUC_UNUSED SpiceMarshaller *m2;
  -}
  -
   #endif /* USE_SMARTCARD */
   static void spice_marshall_SpiceMsgCompressedData(SPICE_GNUC_UNUSED SpiceMarshaller *m, SPICE_GNUC_UNUSED SpiceMsgCompressedData *msg)
   {
  @@ -496,20 +456,8 @@ SpiceMessageMarshallers * spice_message_
       marshallers.msgc_record_mode = spice_marshall_msgc_record_mode;
       marshallers.msgc_record_start_mark = spice_marshall_msgc_record_start_mark;
   #ifdef USE_SMARTCARD
  -    marshallers.msgc_smartcard_atr = spice_marshall_msgc_smartcard_atr;
  -#endif /* USE_SMARTCARD */
  -#ifdef USE_SMARTCARD
  -    marshallers.msgc_smartcard_data = spice_marshall_msgc_smartcard_data;
  -#endif /* USE_SMARTCARD */
  -#ifdef USE_SMARTCARD
  -    marshallers.msgc_smartcard_error = spice_marshall_msgc_smartcard_error;
  -#endif /* USE_SMARTCARD */
  -#ifdef USE_SMARTCARD
       marshallers.msgc_smartcard_header = spice_marshall_msgc_smartcard_header;
   #endif /* USE_SMARTCARD */
  -#ifdef USE_SMARTCARD
  -    marshallers.msgc_smartcard_reader_add = spice_marshall_msgc_smartcard_reader_add;
  -#endif /* USE_SMARTCARD */
       marshallers.msgc_tunnel_service_add = spice_marshall_msgc_tunnel_service_add;
       marshallers.msgc_tunnel_service_remove = spice_marshall_msgc_tunnel_service_remove;
       marshallers.msgc_tunnel_socket_closed = spice_marshall_msgc_tunnel_socket_closed;
  diff -rup old/generated_client_marshallers.h common/generated_client_marshallers.h
  --- old/generated_client_marshallers.h	2018-05-14 22:49:07.641778414 +0100
  +++ common/generated_client_marshallers.h	2018-05-14 22:49:22.739358627 +0100
  @@ -61,11 +61,7 @@ typedef struct {
       void (*msgc_tunnel_socket_data)(SpiceMarshaller *m, SpiceMsgcTunnelSocketData *msg);
       void (*msgc_tunnel_socket_token)(SpiceMarshaller *m, SpiceMsgcTunnelSocketTokens *msg);
   #ifdef USE_SMARTCARD
  -    void (*msgc_smartcard_data)(SpiceMarshaller *m, SpiceMsgcSmartcard *msg, SpiceMarshaller **reader_name_out);
       void (*msgc_smartcard_header)(SpiceMarshaller *m, VSCMsgHeader *msg);
  -    void (*msgc_smartcard_error)(SpiceMarshaller *m, VSCMsgError *msg);
  -    void (*msgc_smartcard_atr)(SpiceMarshaller *m, VSCMsgATR *msg);
  -    void (*msgc_smartcard_reader_add)(SpiceMarshaller *m, VSCMsgReaderAdd *msg);
   #endif /* USE_SMARTCARD */
       void (*msg_SpiceMsgCompressedData)(SpiceMarshaller *m, SpiceMsgCompressedData *msg);
       void (*msgc_port_event)(SpiceMarshaller *m, SpiceMsgcPortEvent *msg);
  Only in common/: generated_client_marshallers.lo
  diff -rup old/generated_server_demarshallers.c common/generated_server_demarshallers.c
  --- old/generated_server_demarshallers.c	2018-05-14 22:49:07.641778414 +0100
  +++ common/generated_server_demarshallers.c	2018-05-14 22:49:23.498405695 +0100
  @@ -1957,24 +1957,18 @@ static uint8_t * parse_TunnelChannel_msg

   #ifdef USE_SMARTCARD

  -static uint8_t * parse_msgc_smartcard_reader_add(uint8_t *message_start, uint8_t *message_end, SPICE_GNUC_UNUSED int minor, size_t *size, message_destructor_t *free_message)
  +static uint8_t * parse_msgc_smartcard_header(uint8_t *message_start, uint8_t *message_end, SPICE_GNUC_UNUSED int minor, size_t *size, message_destructor_t *free_message)
   {
       SPICE_GNUC_UNUSED uint8_t *pos;
       uint8_t *start = message_start;
       uint8_t *data = NULL;
       uint64_t nw_size;
  +    uint64_t mem_size;
       uint8_t *in, *end;
  -    uint64_t reader_name__nw_size;
  -    uint64_t reader_name__nelements;
  -    VSCMsgReaderAdd *out;
  +    VSCMsgHeader *out;

  -    { /* reader_name */
  -        reader_name__nelements = message_end - (start + 0);
  -
  -        reader_name__nw_size = reader_name__nelements;
  -    }
  -
  -    nw_size = 0 + reader_name__nw_size;
  +    nw_size = 12;
  +    mem_size = sizeof(VSCMsgHeader);

       /* Check if message fits in reported side */
       if (nw_size > (uintptr_t) (message_end - start)) {
  @@ -1986,13 +1980,14 @@ static uint8_t * parse_msgc_smartcard_re
       if (SPICE_UNLIKELY(data == NULL)) {
           goto error;
       }
  -    end = data + sizeof(VSCMsgReaderAdd);
  +    end = data + sizeof(VSCMsgHeader);
       in = start;

  -    out = (VSCMsgReaderAdd *)data;
  +    out = (VSCMsgHeader *)data;

  -    memcpy(out->reader_name, in, reader_name__nelements);
  -    in += reader_name__nelements;
  +    out->type = consume_uint32(&in);
  +    out->reader_id = consume_uint32(&in);
  +    out->length = consume_uint32(&in);

       assert(in <= message_end);
       assert(end <= data + mem_size);
  @@ -2017,7 +2012,7 @@ static uint8_t * parse_SmartcardChannel_
           parse_msgc_disconnecting
       };
       static parse_msg_func_t funcs2[1] =  {
  -        parse_msgc_smartcard_reader_add
  +        parse_msgc_smartcard_header
       };
       if (message_type >= 1 && message_type < 7) {
           return funcs1[message_type-1](message_start, message_end, minor, size_out, free_message);

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2018-05-17 12:25:42 +01:00
Frediano Ziglio
617be0f74b Avoid integer overflow computing image sizes
Use always 64, sizes can be 32x32.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2018-05-11 17:00:26 +01:00
Frediano Ziglio
420a15b776 Write a small test to test possible crash
This small test prove a that current generated demarshaller code
is not safe to integer overflows leading to buffer overflows.
Actually from a quick look at the protocol it seems that client
can't cause these overflows but server can quite easily at
demonstrated by this test.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2018-05-11 17:00:26 +01:00
Frediano Ziglio
a69fb1ec34 Fix integer overflows computing sizes
Make code safe using both 32 and 64 bit machine.
Consider that this code can be compiled for machines with 32 bit.
There are some arrays length which are 32 bit.

If size_t this can cause easily an overflow. For instance message_len
sending SPICE_MSG_NOTIFY messages are 32 bit and code add a small
constant (currently 24) before doing the test for size. Now passing
(uint32_t) -20 as message_len would lead to a size of 4 after the
addition. This overflow does not happen on 64 bit machine as the length
is converted to size_t.

There are also some array length where some item are bigger than 1 byte.
For instance SPICE_MAIN_CHANNELS_LIST message have a number of channels
and each channel is composed by 2 bytes. Now the code generated try to do
length * 2 where length is still a 32 bit so if we put a value like
0x80000002u we get 4 as length. This will cause an overflow as code will
allocate very few bytes but try to fill with a huge number of elements.
This overflow happen in both 32 and 64 bit machine.

To avoid all these possible overflows this patch use only 64 bit for
nelements (number of elements), nw_size (network size) and mem_size
(memory size needed) checking the sizes to avoid other overflows
(like pointers conversions under 32 bit machines).

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe de Dinechin <dinechin@redhat.com>
2018-05-11 08:41:36 +01:00
Frediano Ziglio
75d9842e7d lz: Move ENCODE_PIXEL for RGB24 and RGB32 to a common place
The macro for both depth is the same, reuse the definition.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2018-05-10 19:50:50 +01:00
Frediano Ziglio
b98f19b168 protocol: Use a typedef to specify stream_id type
This change does not affect generated code but make source more
readable. Also document in a single location the range of this
type.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2018-05-10 19:49:03 +01:00
Jonathon Jongsma
fc46379b37 miLineArc(): initialize edge1, edge2
When compiling spice-common with meson/ninja under "release" mode, I get
several compiler warnings about possibly-uninitialized members. For
example:

    ../subprojects/spice-common/common/lines.c: In function ‘miLineArc’:
    ../subprojects/spice-common/common/lines.c:2167:17: error: ‘edge2.dx’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
             edge->e += edge->dx; \
                     ^~
    ../subprojects/spice-common/common/lines.c:2426:24: note: ‘edge2.dx’ was declared here
         PolyEdgeRec edge1, edge2;
                            ^~~~~

Initializing these structures to zero silences the warnings.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-05-10 10:05:41 -05:00
Frediano Ziglio
754cd54e1a codegen: Removed unused get_type methods
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Lukáš Hrázký <lhrazky@redhat.com>
2018-05-09 11:59:33 +01:00
Frediano Ziglio
46fa9d5efb codegen: Add some comments
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Lukáš Hrázký <lhrazky@redhat.com>
2018-05-09 11:59:33 +01:00
Victor Toso
5729664523 messages: document limitation of id in StreamCreate
Note that the ID limitation always existed but now we have the
limitation in the protocol itself with SPICE_MAX_NUM_STREAMS

Signed-off-by: Victor Toso <victortoso@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-05-05 13:00:56 +01:00
Jonathon Jongsma
885b1a6bb9 Remove extra self parameter from member function
When testing out some experimental protocol changes, I managed to
trigger the following error:

  GEN      generated_client_demarshallers.c
Traceback (most recent call last):
  File "../../../spice-common/spice_codegen.py", line 267, in <module>
    demarshal.write_protocol_parser(writer, proto, True)
  File "/home/jjongsma/work/spice/spice-common/python_modules/demarshal.py", line 1270, in write_protocol_parser
    parsers[channel.value] = (channel.channel_type, write_channel_parser(writer, channel.channel_type, is_server))
  File "/home/jjongsma/work/spice/spice-common/python_modules/demarshal.py", line 1163, in write_channel_parser
    func = write_msg_parser(helpers, ids[i].message_type)
  File "/home/jjongsma/work/spice/spice-common/python_modules/demarshal.py", line 1061, in write_msg_parser
    num_pointers = message.get_num_pointers()
  File "/home/jjongsma/work/spice/spice-common/python_modules/ptypes.py", line 855, in get_num_pointers
    count = count + m.get_num_pointers()
  File "/home/jjongsma/work/spice/spice-common/python_modules/ptypes.py", line 662, in get_num_pointers
    return self.member_type.get_num_pointers()
  File "/home/jjongsma/work/spice/spice-common/python_modules/ptypes.py", line 507, in get_num_pointers
    if self.is_constant_length(self):
TypeError: is_constant_length() takes exactly 1 argument (2 given)

Calling a member function will implicitly pass 'self' as the first
argument, but we were also explicitly passing it as an argument
(self.is_constant_length(self)). This resulted in the above error.

Acked-by: Lukáš Hrázký <lhrazky@redhat.com>
2018-04-17 14:14:22 +01:00
Frediano Ziglio
4c2d0e9772 Add --enable-extra-checks option
Allow to enable code to do additional or expensive checks.
The option should be used by higher level libraries.
By default the option is disabled.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
2018-03-19 14:47:21 +00:00
Frediano Ziglio
2eaef9c16d protocol: Add some documentation for inval_all_pixmaps message
This message is not straight forward to grasp.
Not clear by the name why we need to wait other channels messages
before resetting the image cache.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2018-03-18 09:14:29 +00:00
Frediano Ziglio
8096b1206b canvas: Use SPICE_UNALIGNED_CAST to avoid -Wcast-align warnings
This solves https://bugs.freedesktop.org/show_bug.cgi?id=104521.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2018-01-31 15:10:35 +00:00
Frediano Ziglio
fd0aba2750 canvas: Fix some semi transparent drawing
This is reproducible using desktop icons on Windows XP.

These drawing are sent for the icons on the desktop.
To get an extends.x1 >= 32 you have to move an icon out of the
screen on the left side. Set the icon size to 72 as the icon has
to be out of the screen quite a lot.
Disable the grid alignment on the desktop and move an icon out of
the screen. Select and unselect the icon.
Using "/ 32" the icon will have a white background instead of a
transparent one.
Using a "/ 8" the icon is rendered correctly.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe de Dinechin <cdupontd@redhat.com>
2018-01-25 22:27:34 +00:00
Frediano Ziglio
f3478aa4b6 canvas: Prevent some error compiling spice-gtk
Due to different warning setting some GCC reports:

In file included from ../spice-common/common/sw_canvas.c:27:0,
                 from client_sw_canvas.c:20:
../spice-common/common/canvas_base.c: In function ‘canvas_get_lz’:
../spice-common/common/canvas_base.c:768:13: error: ‘palette’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
             free(palette);
             ^~~~~~~~~~~~~
../spice-common/common/canvas_base.c:764:9: error: variable ‘free_palette’ might be clobbered by ‘longjmp’ or ‘vfork’ [-Werror=clobbered]
     int free_palette = FALSE;
         ^~~~~~~~~~~~
cc1: all warnings being treated as errors

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Snir Sheriber <ssheribe@redhat.com>
2018-01-24 10:41:02 +00:00
Paweł Pękala
122be3d1f7 Fix build with LibreSSL
Some FreeBSD configurations can use LibreSSL instead of OpenSSL.
The two libraries are really similar but need some minimal adjustment.

Signed-off-by: Paweł Pękala <pawelbsd@gmail.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-01-23 10:23:43 +00:00
Frediano Ziglio
41c7ea6611 canvas: Remove unused include header
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2018-01-18 14:34:26 +00:00