Commit Graph

79 Commits

Author SHA1 Message Date
Akihiko Odaki
2f5f1d3854 test-marshallers: Define generated_test_messages.h target
Define generated_test_messages.h target; otherwise Make may not be able
to find the file and fail.

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
2025-03-01 12:55:56 +00:00
Frediano Ziglio
18f753c52f meson: Generate missing intermediate target
Tell build system how to generate the intermediate file
generated_test_messages.h.
Otherwise if removed the build will then fail.
This is also probably the reason some build intermittently fail.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2021-05-18 15:01:31 +01:00
Frediano Ziglio
fcfe9104bd Fix make distcheck
We need to package generated_test_messages.h file

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
2021-04-14 17:29:08 +01:00
Marc-André Lureau
c39f4fd002 Fix build as meson subproject
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2021-04-13 23:37:10 +04:00
Stefan Weil
68188b0c21 Add missing include file string.h
It is required for strcmp. This fixes a compiler warning for mingw-w64.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
Acked-by: Frediano Ziglio <freddy77@gmail.com>
2021-04-08 15:42:20 +01:00
Frediano Ziglio
c48140c493 helper-fuzzer-demarshallers: Check also test demarshallers
Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-02-22 09:11:40 +00:00
Frediano Ziglio
6b662331f7 codegen: Handle zero_terminated attribute in demashaller
Make sure the output array is zero terminated to simplify
code using the output structures.

Changed in generated code:

    diff -ru gen/generated_client_demarshallers.c common/generated_client_demarshallers.c
    --- gen/generated_client_demarshallers.c	2021-02-21 15:13:42.004307087 +0000
    +++ common/generated_client_demarshallers.c	2021-02-21 15:13:58.916513426 +0000
    @@ -565,15 +565,24 @@
         return NULL;
     }

    -static uint8_t * parse_array_uint8(uint8_t *message_start, SPICE_GNUC_UNUSED uint8_t *message_end, uint8_t *struct_data, PointerInfo *this_ptr_info)
    +static uint8_t * parse_array_uint8_terminated(uint8_t *message_start, SPICE_GNUC_UNUSED uint8_t *message_end, uint8_t *struct_data, PointerInfo *this_ptr_info)
     {
         uint8_t *in = message_start + this_ptr_info->offset;
         uint8_t *end;

         end = struct_data;
         memcpy(end, in, this_ptr_info->nelements);
    +#if defined(__GNUC__)
    +#pragma GCC diagnostic push
    +#pragma GCC diagnostic ignored "-Wstringop-overflow"
    +#endif
    +    ((char *) (end))[this_ptr_info->nelements] = 0;
    +#if defined(__GNUC__)
    +#pragma GCC diagnostic pop
    +#endif
         in += this_ptr_info->nelements;
         end += this_ptr_info->nelements;
    +    end += 1;
         return end;
     }

    @@ -622,7 +631,8 @@
                 dst_info_host_data__array__nelements = host_size__value;

                 dst_info_host_data__array__nw_size = dst_info_host_data__array__nelements;
    -            dst_info_host_data__array__mem_size = sizeof(uint8_t) * dst_info_host_data__array__nelements;
    +            dst_info_host_data__array__mem_size = sizeof(uint8_t) * dst_info_host_data__array__nelements + sizeof(uint8_t);
    +            dst_info_host_data__array__mem_size = SPICE_ALIGN(dst_info_host_data__array__mem_size, 4);
                 if (SPICE_UNLIKELY(dst_info_host_data__array__nw_size > (uintptr_t) (message_end - message_start - host_data__value))) {
                     goto error;
                 }
    @@ -650,7 +660,8 @@
                 dst_info_cert_subject_data__array__nelements = cert_subject_size__value;

                 dst_info_cert_subject_data__array__nw_size = dst_info_cert_subject_data__array__nelements;
    -            dst_info_cert_subject_data__array__mem_size = sizeof(uint8_t) * dst_info_cert_subject_data__array__nelements;
    +            dst_info_cert_subject_data__array__mem_size = sizeof(uint8_t) * dst_info_cert_subject_data__array__nelements + sizeof(uint8_t);
    +            dst_info_cert_subject_data__array__mem_size = SPICE_ALIGN(dst_info_cert_subject_data__array__mem_size, 4);
                 if (SPICE_UNLIKELY(dst_info_cert_subject_data__array__nw_size > (uintptr_t) (message_end - message_start - cert_subject_data__value))) {
                     goto error;
                 }
    @@ -685,14 +696,14 @@
             out->dst_info.sport = consume_uint16(&in);
             out->dst_info.host_size = consume_uint32(&in);
             ptr_info[n_ptr].offset = consume_uint32(&in);
    -        ptr_info[n_ptr].parse = parse_array_uint8;
    +        ptr_info[n_ptr].parse = parse_array_uint8_terminated;
             ptr_info[n_ptr].dest = (void **)&out->dst_info.host_data;
             host_data__array__nelements = out->dst_info.host_size;
             ptr_info[n_ptr].nelements = host_data__array__nelements;
             n_ptr++;
             out->dst_info.cert_subject_size = consume_uint32(&in);
             ptr_info[n_ptr].offset = consume_uint32(&in);
    -        ptr_info[n_ptr].parse = parse_array_uint8;
    +        ptr_info[n_ptr].parse = parse_array_uint8_terminated;
             ptr_info[n_ptr].dest = (void **)&out->dst_info.cert_subject_data;
             cert_subject_data__array__nelements = out->dst_info.cert_subject_size;
             ptr_info[n_ptr].nelements = cert_subject_data__array__nelements;
    @@ -1050,7 +1061,8 @@
             host_data__array__nelements = host_size__value;

             host_data__array__nw_size = host_data__array__nelements;
    -        host_data__array__mem_size = sizeof(uint8_t) * host_data__array__nelements;
    +        host_data__array__mem_size = sizeof(uint8_t) * host_data__array__nelements + sizeof(uint8_t);
    +        host_data__array__mem_size = SPICE_ALIGN(host_data__array__mem_size, 4);
             if (SPICE_UNLIKELY(host_data__array__nw_size > (uintptr_t) (message_end - message_start - host_data__value))) {
                 goto error;
             }
    @@ -1078,7 +1090,8 @@
             cert_subject_data__array__nelements = cert_subject_size__value;

             cert_subject_data__array__nw_size = cert_subject_data__array__nelements;
    -        cert_subject_data__array__mem_size = sizeof(uint8_t) * cert_subject_data__array__nelements;
    +        cert_subject_data__array__mem_size = sizeof(uint8_t) * cert_subject_data__array__nelements + sizeof(uint8_t);
    +        cert_subject_data__array__mem_size = SPICE_ALIGN(cert_subject_data__array__mem_size, 4);
             if (SPICE_UNLIKELY(cert_subject_data__array__nw_size > (uintptr_t) (message_end - message_start - cert_subject_data__value))) {
                 goto error;
             }
    @@ -1107,13 +1120,13 @@
         out->sport = consume_uint16(&in);
         out->host_size = consume_uint32(&in);
         ptr_info[n_ptr].offset = consume_uint32(&in);
    -    ptr_info[n_ptr].parse = parse_array_uint8;
    +    ptr_info[n_ptr].parse = parse_array_uint8_terminated;
         ptr_info[n_ptr].dest = (void **)&out->host_data;
         ptr_info[n_ptr].nelements = host_data__array__nelements;
         n_ptr++;
         out->cert_subject_size = consume_uint32(&in);
         ptr_info[n_ptr].offset = consume_uint32(&in);
    -    ptr_info[n_ptr].parse = parse_array_uint8;
    +    ptr_info[n_ptr].parse = parse_array_uint8_terminated;
         ptr_info[n_ptr].dest = (void **)&out->cert_subject_data;
         ptr_info[n_ptr].nelements = cert_subject_data__array__nelements;
         n_ptr++;
    @@ -1338,7 +1351,8 @@
                 dst_info_host_data__array__nelements = host_size__value;

                 dst_info_host_data__array__nw_size = dst_info_host_data__array__nelements;
    -            dst_info_host_data__array__mem_size = sizeof(uint8_t) * dst_info_host_data__array__nelements;
    +            dst_info_host_data__array__mem_size = sizeof(uint8_t) * dst_info_host_data__array__nelements + sizeof(uint8_t);
    +            dst_info_host_data__array__mem_size = SPICE_ALIGN(dst_info_host_data__array__mem_size, 4);
                 if (SPICE_UNLIKELY(dst_info_host_data__array__nw_size > (uintptr_t) (message_end - message_start - host_data__value))) {
                     goto error;
                 }
    @@ -1366,7 +1380,8 @@
                 dst_info_cert_subject_data__array__nelements = cert_subject_size__value;

                 dst_info_cert_subject_data__array__nw_size = dst_info_cert_subject_data__array__nelements;
    -            dst_info_cert_subject_data__array__mem_size = sizeof(uint8_t) * dst_info_cert_subject_data__array__nelements;
    +            dst_info_cert_subject_data__array__mem_size = sizeof(uint8_t) * dst_info_cert_subject_data__array__nelements + sizeof(uint8_t);
    +            dst_info_cert_subject_data__array__mem_size = SPICE_ALIGN(dst_info_cert_subject_data__array__mem_size, 4);
                 if (SPICE_UNLIKELY(dst_info_cert_subject_data__array__nw_size > (uintptr_t) (message_end - message_start - cert_subject_data__value))) {
                     goto error;
                 }
    @@ -1401,14 +1416,14 @@
             out->dst_info.sport = consume_uint16(&in);
             out->dst_info.host_size = consume_uint32(&in);
             ptr_info[n_ptr].offset = consume_uint32(&in);
    -        ptr_info[n_ptr].parse = parse_array_uint8;
    +        ptr_info[n_ptr].parse = parse_array_uint8_terminated;
             ptr_info[n_ptr].dest = (void **)&out->dst_info.host_data;
             host_data__array__nelements = out->dst_info.host_size;
             ptr_info[n_ptr].nelements = host_data__array__nelements;
             n_ptr++;
             out->dst_info.cert_subject_size = consume_uint32(&in);
             ptr_info[n_ptr].offset = consume_uint32(&in);
    -        ptr_info[n_ptr].parse = parse_array_uint8;
    +        ptr_info[n_ptr].parse = parse_array_uint8_terminated;
             ptr_info[n_ptr].dest = (void **)&out->dst_info.cert_subject_data;
             cert_subject_data__array__nelements = out->dst_info.cert_subject_size;
             ptr_info[n_ptr].nelements = cert_subject_data__array__nelements;
    @@ -7582,7 +7597,8 @@
             name__array__nelements = name_size__value;

             name__array__nw_size = name__array__nelements;
    -        name__array__mem_size = sizeof(uint8_t) * name__array__nelements;
    +        name__array__mem_size = sizeof(uint8_t) * name__array__nelements + sizeof(uint8_t);
    +        name__array__mem_size = SPICE_ALIGN(name__array__mem_size, 4);
             if (SPICE_UNLIKELY(name__array__nw_size > (uintptr_t) (message_end - message_start - name__value))) {
                 goto error;
             }
    @@ -7609,7 +7625,7 @@

         out->name_size = consume_uint32(&in);
         ptr_info[n_ptr].offset = consume_uint32(&in);
    -    ptr_info[n_ptr].parse = parse_array_uint8;
    +    ptr_info[n_ptr].parse = parse_array_uint8_terminated;
         ptr_info[n_ptr].dest = (void **)&out->name;
         ptr_info[n_ptr].nelements = name__array__nelements;
         n_ptr++;

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2021-02-22 09:11:35 +00:00
Frediano Ziglio
d589542e04 test-quic: Add test cases for quic fuzzer
To use for start for the fuzzer.

Tests have been generated with a patch like:

	diff --git a/tests/test-quic.c b/tests/test-quic.c
	--- a/tests/test-quic.c
	+++ b/tests/test-quic.c
	@@ -372,8 +372,8 @@ static void pixbuf_compare(GdkPixbuf *pixbuf_a, GdkPixbuf *pixbuf_b)
	 static GdkPixbuf *pixbuf_new_random(int alpha)
	 {
	     gboolean has_alpha = alpha >= 0 ? alpha : g_random_boolean();
	-    gint width = g_random_int_range(100, 2000);
	-    gint height = g_random_int_range(100, 500);
	+    gint width = g_random_int_range(10, 100);
	+    gint height = g_random_int_range(10, 100);
	     GdkPixbuf *random_pixbuf;
	     guint i, size;
	     guint8 *pixels;
	@@ -401,6 +401,12 @@ static void test_pixbuf(GdkPixbuf *pixbuf)
	     compressed_data = quic_encode_from_pixbuf(pixbuf, imgbuf);

	     uncompressed_pixbuf = quic_decode_to_pixbuf(compressed_data);
	+    {
	+        static int num = 0;
	+        char fn[256];
	+        sprintf(fn, "test%d.quic", ++num);
	+        g_assert(g_file_set_contents(fn, (void *) compressed_data->data, compressed_data->len, NULL));
	+    }
	     image_buf_free(imgbuf, uncompressed_pixbuf);

	     //g_assert(memcmp(gdk_pixbuf_get_pixels(pixbuf), gdk_pixbuf_get_pixels(uncompressed_pixbuf), gdk_pixbuf_get_byte_length(uncompressed_pixbuf)));

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Uri Lublin <uril@redhat.com>
2020-09-17 06:46:57 +01:00
Frediano Ziglio
3b81e67979 test-quic: Add fuzzer capabilities to the test
Allows it to be used for fuzzying compressed images.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Uri Lublin <uril@redhat.com>
2020-09-17 06:46:57 +01:00
Frediano Ziglio
2f045752d5 helper-fuzzer-demarshallers: Provide replacement for ftello for MSVC
Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Uri Lublin <uril@redhat.com>
2020-08-10 09:55:31 +01:00
Frediano Ziglio
a5ee3cbac5 test-quic: Different "more_space" function for decode and encode
The "more_space" callback is used in both decode and encode path to provide
either more space to read or more space to write.
The current implementation was dealing only to provide more space to write
(that is encoding) crashing in case it was used for decoding.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Uri Lublin <uril@redhat.com>
2020-05-23 10:48:28 +01:00
Frediano Ziglio
8d969b66ed test-quic: Test fixed images
QUIC uses different methods to reduce image size.
One uses RLE on pixels. Using fixed images allows to better
test these paths increase code coverage.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
2020-05-06 12:22:09 +01:00
Frediano Ziglio
5b93090e60 test-utils: Add missing include file
In some environment memset was not declared.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
Acked-by: Uri Lublin <uril@redhat.com>
2020-05-06 12:21:10 +01:00
Frediano Ziglio
7a84f60267 build: Remove dependency to gio2 from common and server libraries
The dependency is required only for client part.

Signed-off-by: Frediano Ziglio <freddy77@gmail.com>
2020-04-26 16:50:00 +01:00
Frediano Ziglio
8470ef9df2 helper-fuzzer-demarshallers: Add an helper for fuzzy testing demarshallers code
See usage with AFL in the source file initial comment.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-04-09 09:11:04 +01:00
Frediano Ziglio
713a3e09fb build: Allow to build disabling code generation
Reduce dependencies if used by agents which do not need
marshallers/demarshallers code.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-04-03 14:31:26 +01:00
Frediano Ziglio
6a64d86d1d test-logging: Do not use G_PASTE to join level
"level" can have value "DEBUG". In some environment "DEBUG" is
used as preprocessor name to enable some debugging code.
Using -DDEBUG option (or similar) cause "DEBUG" to be defined as "1"
so "G_PASTE(G_LOG_LEVEL_, level)" will be expanded to "G_LOG_LEVEL_1"
instead of "G_LOG_LEVEL_DEBUG".
Just concatenate the two literal to avoid "DEBUG" expansion.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2020-03-19 14:47:08 +00:00
Frediano Ziglio
a3ec7c173d test-utils: Add a test for some utils.h functions
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Kevin Pouget <kpouget@redhat.com>
2020-03-05 18:38:12 +00:00
Frediano Ziglio
2cec5f99af test-quic: Run 1 random quic test per color mode
Reduce execution time. No need to run so much tests, coverage
stays more or less the same.
We iterate twice to check RGB mode with alpha, otherwise the
coverage reduce about 10-20%.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Marc-André Lureau <marcandre.lureau@gmail.com>
2020-03-02 09:57:56 +00:00
Frediano Ziglio
27fd63ff72 test-quic: Reduce height of test image
There's no much need for than size to be so big, limit to
reduce execution time, coverage stays more or less the same.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Marc-André Lureau <marcandre.lureau@gmail.com>
2020-03-02 09:57:54 +00:00
Frediano Ziglio
df66d9a151 test-quic: Cache gdk_pixbuf_get_byte_length value
Do not call the function for every iteration

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Marc-André Lureau <marcandre.lureau@gmail.com>
2020-03-02 09:57:50 +00:00
Frediano Ziglio
8e82bf5661 test-quic: Avoid namespace conflict with Gdk API
Avoid possible conflict in the future.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Marc-André Lureau <marcandre.lureau@gmail.com>
2020-03-02 09:57:44 +00:00
Frediano Ziglio
e761c2d4de log: Add spice_extra_assert
This macro was suggested to simplify hot path expensive checks
which should be disable in production environments.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Francesco Giudici <fgiudici@redhat.com>
2020-02-07 13:24:45 +00:00
Frediano Ziglio
151c23d235 test-quic: Convert image to get more testing (gray, rgb16)
Allows to check QUIC algorithm and code with multiple input/output
formats.
Was limited to just RGB and RGBA.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
2020-02-07 10:59:18 +00:00
Kevin Pouget
a16c7027c5 agent-interface: introduce the core of the Agent Interface
When initialized (recorder_initialization), the Agent Interface launch
a GThread (handle_communications) that opens a TCP server socket and
waits for Smart Local Agent connections. When a Local Agent connects
to the sockets, the communication is initialized
(agent_initialize_communication), the communication socket is stored
and the list of Recorders is sent. In return, the local agent
indicates which recorders to enable.

On the SPICE side, the Agent Interface handles the record() calls
(recorder_append*). When a record is received from SPICE, and if the
recorder is enabled, the record entry is sent through the TCP
connection. Otherwise, the record is dropped.

Signed-off-by: Kevin Pouget <kpouget@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-10-18 17:04:03 +01:00
Kevin Pouget
2640ff294a common/recorder.h: do not complain on unused (dummy) recorders
Signed-off-by: Kevin Pouget <kpouget@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-09-11 10:02:44 +01:00
Uri Lublin
01417b7533 test-marshallers.proto: ArrayMessage: make space for name
Do it by adding @end tag.
Without it the allocated memory has no space for 'name'.

Also fix SpiceMsgMainArrayMessage tests/test-marshallers.h,
replacing int8_t* name with int8_t name[0].
This makes name an "in-structure" array with no pre-defined size
instead of a pointer.
The size is defined by the message size.

Signed-off-by: Uri Lublin <uril@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-08-13 18:09:05 +01:00
Frediano Ziglio
4fc4c2db36 Do not check for HAVE_CONFIG_H
This should always be defined and including config.h is a requirement.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-05-02 09:33:05 +01:00
Christophe Fergeau
e123f94939 test-marshallers: Fix header guard
test-marshallers.h is missing a #define _H_TEST_MARSHALLERS in order to
prevent multiple #include for the same header.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-03-29 16:58:16 +01:00
Christophe Fergeau
5ef652b7e3 build: Add missing G_GNUC_PRINTF annotations
They were suggested by gcc when using -Wsuggest-attribute=format

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2019-03-29 16:58:07 +01:00
Frediano Ziglio
387d1842d1 test-ssl-verify: Improve subject_to_x509_name coverage
Check that attempting to quote an invalid character result in
a error.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2019-03-13 17:22:18 +00:00
Frediano Ziglio
3e116a6c71 Obsolete Glib cleanup
We require at least GLib 2.38, remove code and check to
support earlier versions.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
2019-02-06 14:24:03 +00:00
Frediano Ziglio
e3af47fe9d log: remove deprecated SPICE_DEBUG_LEVEL support
This feature was marked obsolete by efd1d3cb4d more than
three years ago.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2019-02-06 13:21:00 +00:00
Frediano Ziglio
ea20b8c013 log: remove deprecated SPICE_ABORT_LEVEL support
This feature was marked obsolete by efd1d3cb4d more than
three years ago.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2019-02-06 13:19:47 +00:00
Frediano Ziglio
2e914f3305 Integrate recorder library
Allow to use recorder library. See https://github.com/c3d/recorder for
details.
The main usage will be to collect statistics while the programs will run.
By default the recorder will be disabled at compile time. The idea of the
usage in SPICE is to collect data while the program run. Using current
SPICE logging facility was discussed but not easy to filter data. Other
solutions (SystemTap, LTTng) were discarded due to not cross platform.
A printf based solution was discussed too but missing the additional tools
which are useful. Currently we don't plan to use as extensively as to be a
problem to be replaced or removed in the future.

Both Autoconf and Meson build systems are supported.
Autoconf requires the addition of SPICE_CHECK_RECORDER call in configure.ac.
Meson requires to add recorder option.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
2019-01-23 14:44:19 +00:00
Frediano Ziglio
16aa8c98d8 test: Add a test for subject_to_x509_name function
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2019-01-08 21:26:58 +00:00
Frediano Ziglio
c01a4a6fc3 test-region: Add missing dependencies
The test uses both GLib and pixman libraries.
This does not seem to affect Linux but make the test fails under Windows.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2018-12-17 12:18:48 +00:00
Frediano Ziglio
a45f656aac test-marshaller: Make main declaration easier
Declare without argument instead of long declaration.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2018-12-17 09:54:56 +00:00
Frediano Ziglio
ac8d27104b test-marshaller: Make test_overflow static
Not used outside the test.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Uri Lublin <uril@redhat.com>
2018-12-17 09:52:29 +00:00
Frediano Ziglio
2060672e81 Create common header for demarshallers declarations
Code generated for demarshallers define and declare some types and
functions.
However these types and functions are also declared separately in other
headers (currently spice-common/client_demarshallers.h and
spice/server/demarshallers.h) resulting in potential ABI mismatch if the
different declarations do not match.
Using a common header shared between generated code and code using
these functions prevent potentially multiple different declarations.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2018-10-15 13:31:16 +01:00
Frediano Ziglio
bb15d4815a Fix flexible array buffer overflow
This is kind of a DoS, possibly flexible array in the protocol
causes the network size check to be ignored due to integer overflows.

The size of flexible array is computed as (message_end - position),
then this size is added to the number of bytes before the array and
this number is used to check if we overflow initial message.

An example is:

    message {
        uint32 dummy[2];
        uint8 data[] @end;
    } LenMessage;

which generated this (simplified remove useless code) code:

    { /* data */
        data__nelements = message_end - (start + 8);

        data__nw_size = data__nelements;
    }

    nw_size = 8 + data__nw_size;

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

Following code:
- data__nelements == message_end - (start + 8)
- data__nw_size == data__nelements == message_end - (start + 8)
- nw_size == 8 + data__nw_size == 8 + message_end - (start + 8) ==
  8 + message_end - start - 8 == message_end -start
- the check for overflow is (nw_size > (message_end - start)) but
  nw_size == message_end - start so the check is doing
  ((message_end - start) > (message_end - start)) which is always false.

If message_end - start < 8 then data__nelements (number of element
on the array above) computation generate an integer underflow that
later create a buffer overflow.

Add a check to make sure that the array starts before the message ends
to avoid the overflow.

Difference is:
    diff -u save/generated_client_demarshallers1.c common/generated_client_demarshallers1.c
    --- save/generated_client_demarshallers1.c	2018-06-22 22:13:48.626793919 +0100
    +++ common/generated_client_demarshallers1.c	2018-06-22 22:14:03.408163291 +0100
    @@ -225,6 +225,9 @@
         uint64_t data__nelements;

         { /* data */
    +        if (SPICE_UNLIKELY((start + 0) > message_end)) {
    +            goto error;
    +        }
             data__nelements = message_end - (start + 0);

             data__nw_size = data__nelements;
    @@ -243,6 +246,9 @@
         *free_message = nofree;
         return data;

    +   error:
    +    free(data);
    +    return NULL;
     }

     static uint8_t * parse_msg_set_ack(uint8_t *message_start, uint8_t *message_end, SPICE_GNUC_UNUSED int minor, size_t *size, message_destructor_t *free_message)
    @@ -301,6 +307,9 @@
         SpiceMsgPing *out;

         { /* data */
    +        if (SPICE_UNLIKELY((start + 12) > message_end)) {
    +            goto error;
    +        }
             data__nelements = message_end - (start + 12);

             data__nw_size = data__nelements;
    @@ -5226,6 +5235,9 @@
             uint64_t cursor_data__nw_size;
             uint64_t cursor_data__nelements;
             { /* data */
    +            if (SPICE_UNLIKELY((start2 + 22) > message_end)) {
    +                goto error;
    +            }
                 cursor_data__nelements = message_end - (start2 + 22);

                 cursor_data__nw_size = cursor_data__nelements;
    @@ -5305,6 +5317,9 @@
             uint64_t cursor_data__nw_size;
             uint64_t cursor_data__nelements;
             { /* data */
    +            if (SPICE_UNLIKELY((start2 + 22) > message_end)) {
    +                goto error;
    +            }
                 cursor_data__nelements = message_end - (start2 + 22);

                 cursor_data__nw_size = cursor_data__nelements;
    @@ -5540,6 +5555,9 @@
         SpiceMsgPlaybackPacket *out;

         { /* data */
    +        if (SPICE_UNLIKELY((start + 4) > message_end)) {
    +            goto error;
    +        }
             data__nelements = message_end - (start + 4);

             data__nw_size = data__nelements;
    @@ -5594,6 +5612,9 @@
         SpiceMsgPlaybackMode *out;

         { /* data */
    +        if (SPICE_UNLIKELY((start + 8) > message_end)) {
    +            goto error;
    +        }
             data__nelements = message_end - (start + 8);

             data__nw_size = data__nelements;
    diff -u save/generated_client_demarshallers.c common/generated_client_demarshallers.c
    --- save/generated_client_demarshallers.c	2018-06-22 22:13:48.626793919 +0100
    +++ common/generated_client_demarshallers.c	2018-06-22 22:14:03.004153195 +0100
    @@ -225,6 +225,9 @@
         uint64_t data__nelements;

         { /* data */
    +        if (SPICE_UNLIKELY((start + 0) > message_end)) {
    +            goto error;
    +        }
             data__nelements = message_end - (start + 0);

             data__nw_size = data__nelements;
    @@ -243,6 +246,9 @@
         *free_message = nofree;
         return data;

    +   error:
    +    free(data);
    +    return NULL;
     }

     static uint8_t * parse_msg_set_ack(uint8_t *message_start, uint8_t *message_end, SPICE_GNUC_UNUSED int minor, size_t *size, message_destructor_t *free_message)
    @@ -301,6 +307,9 @@
         SpiceMsgPing *out;

         { /* data */
    +        if (SPICE_UNLIKELY((start + 12) > message_end)) {
    +            goto error;
    +        }
             data__nelements = message_end - (start + 12);

             data__nw_size = data__nelements;
    @@ -6574,6 +6583,9 @@
             }

             { /* data */
    +            if (SPICE_UNLIKELY((start2 + 2 + cursor_u__nw_size) > message_end)) {
    +                goto error;
    +            }
                 cursor_data__nelements = message_end - (start2 + 2 + cursor_u__nw_size);

                 cursor_data__nw_size = cursor_data__nelements;
    @@ -6670,6 +6682,9 @@
             }

             { /* data */
    +            if (SPICE_UNLIKELY((start2 + 2 + cursor_u__nw_size) > message_end)) {
    +                goto error;
    +            }
                 cursor_data__nelements = message_end - (start2 + 2 + cursor_u__nw_size);

                 cursor_data__nw_size = cursor_data__nelements;
    @@ -6907,6 +6922,9 @@
         SpiceMsgPlaybackPacket *out;

         { /* data */
    +        if (SPICE_UNLIKELY((start + 4) > message_end)) {
    +            goto error;
    +        }
             data__nelements = message_end - (start + 4);

             data__nw_size = data__nelements;
    @@ -6961,6 +6979,9 @@
         SpiceMsgPlaybackMode *out;

         { /* data */
    +        if (SPICE_UNLIKELY((start + 6) > message_end)) {
    +            goto error;
    +        }
             data__nelements = message_end - (start + 6);

             data__nw_size = data__nelements;
    @@ -7559,6 +7580,9 @@
         SpiceMsgTunnelSocketData *out;

         { /* data */
    +        if (SPICE_UNLIKELY((start + 2) > message_end)) {
    +            goto error;
    +        }
             data__nelements = message_end - (start + 2);

             data__nw_size = data__nelements;
    @@ -7840,6 +7864,9 @@
         }

         { /* compressed_data */
    +        if (SPICE_UNLIKELY((start + 1 + u__nw_size) > message_end)) {
    +            goto error;
    +        }
             compressed_data__nelements = message_end - (start + 1 + u__nw_size);

             compressed_data__nw_size = compressed_data__nelements;
    diff -u save/generated_server_demarshallers.c common/generated_server_demarshallers.c
    --- save/generated_server_demarshallers.c	2018-06-22 22:13:48.627793944 +0100
    +++ common/generated_server_demarshallers.c	2018-06-22 22:14:05.231208847 +0100
    @@ -306,6 +306,9 @@
         uint64_t data__nelements;

         { /* data */
    +        if (SPICE_UNLIKELY((start + 0) > message_end)) {
    +            goto error;
    +        }
             data__nelements = message_end - (start + 0);

             data__nw_size = data__nelements;
    @@ -324,6 +327,9 @@
         *free_message = nofree;
         return data;

    +   error:
    +    free(data);
    +    return NULL;
     }

     static uint8_t * parse_msgc_disconnecting(uint8_t *message_start, uint8_t *message_end, SPICE_GNUC_UNUSED int minor, size_t *size, message_destructor_t *free_message)
    @@ -1259,6 +1265,9 @@
         SpiceMsgcRecordPacket *out;

         { /* data */
    +        if (SPICE_UNLIKELY((start + 4) > message_end)) {
    +            goto error;
    +        }
             data__nelements = message_end - (start + 4);

             data__nw_size = data__nelements;
    @@ -1313,6 +1322,9 @@
         SpiceMsgcRecordMode *out;

         { /* data */
    +        if (SPICE_UNLIKELY((start + 6) > message_end)) {
    +            goto error;
    +        }
             data__nelements = message_end - (start + 6);

             data__nw_size = data__nelements;
    @@ -1841,6 +1853,9 @@
         SpiceMsgcTunnelSocketData *out;

         { /* data */
    +        if (SPICE_UNLIKELY((start + 2) > message_end)) {
    +            goto error;
    +        }
             data__nelements = message_end - (start + 2);

             data__nw_size = data__nelements;
    @@ -2057,6 +2072,9 @@
         }

         { /* compressed_data */
    +        if (SPICE_UNLIKELY((start + 1 + u__nw_size) > message_end)) {
    +            goto error;
    +        }
             compressed_data__nelements = message_end - (start + 1 + u__nw_size);

             compressed_data__nw_size = compressed_data__nelements;

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
2018-08-16 15:02:24 +01:00
Frediano Ziglio
f4a0fec5e9 tests: Join test-overflow and test-marshallers
test-overflow was doing a specific test on demarshalling code.
Joining the 2 tests also allows to remove the dependency from the main
protocol allowing to run the test independently from generation setting.
Using Meson when building either SPICE server or spice-gtk, we only
generate the specific marshallers/demarshallers for that given case.
With this commit the test is built in any case.

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
2018-07-12 05:50:50 +01:00
Christophe Fergeau
31d4622687 log: Remove SPICE_DISABLE_ABORT
spice-gtk was the last user, and stopped using it on Jun 14th 2017
in 040090ccba34 "build-sys: remove -DSPICE_DISABLE_ABORT"

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2018-07-06 06:46:05 +01:00
Eduardo Lima (Etrunko)
75863fb69f test-region: Decrease loop count by a factor of 10
This test was timing out when running in gitlab-ci, so decreasing the
loop count in order to make it run faster. Example:

https://gitlab.freedesktop.org/etrunko/spice-common/-/jobs/6546

Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-07-03 11:43:24 -03:00
Frediano Ziglio
2b5cadcd8a test-marshallers: Check for "zero" attribute
Check the previous fix for "zero" attribute works correctly
(commit bc9df58162, "marshal: Fix a bug
with zero attribute").

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2018-07-03 12:25:31 +01:00
Frediano Ziglio
0385a67ef8 build: Reindent macros
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2018-06-28 13:34:14 +01:00
Frediano Ziglio
da4926bd26 build: Reuse TEST_MARSHALLERS macro
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Christophe Fergeau <cfergeau@redhat.com>
2018-06-28 13:34:14 +01:00
Christophe Fergeau
5110dbcbb7 test-region: Add g_assert() checks
At the moment, test success/failure is only printed to stdout. This
commit adds some g_assert() so that test failures can be automatically
detected.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-06-27 13:17:55 +01:00
Christophe Fergeau
cfbae20c48 test-region: Replace spice_assert() with g_assert_true()
Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-06-27 13:17:53 +01:00
Christophe Fergeau
968ce158f0 test-region: Remove unneeded printf
__FUNCTION__ will always be rect_is_valid, and there is a g_assert to
check the region is valid, so we will get notified anyway if the
validity check fails.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
2018-06-27 13:17:51 +01:00