Skip to content

Commit ca21b17

Browse files
committed
Test for "Don't call g_variant_store() with NULL"
For #623
1 parent 9284ed3 commit ca21b17

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

modulemd/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ c_tests = {
365365
'service_level' : [ 'tests/test-modulemd-service-level.c' ],
366366
'translation' : [ 'tests/test-modulemd-translation.c' ],
367367
'translation_entry' : [ 'tests/test-modulemd-translation-entry.c' ],
368+
'variant_deep_copy' : [ 'tests/test-modulemd-variant_deep_copy.c' ],
368369
'obsoletes' : [ 'tests/test-modulemd-obsoletes.c' ],
369370
'quoting' : [ 'tests/test-modulemd-quoting.c' ],
370371
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* This file is part of libmodulemd
3+
* Copyright (C) 2025 Red Hat, Inc.
4+
*
5+
* Fedora-License-Identifier: MIT
6+
* SPDX-2.0-License-Identifier: MIT
7+
* SPDX-3.0-License-Identifier: MIT
8+
*
9+
* This program is free software.
10+
* For more information on the license, see COPYING.
11+
* For more information on free software, see <https://www.gnu.org/philosophy/free-sw.en.html>.
12+
*/
13+
14+
#include <glib.h>
15+
#include <glib/gprintf.h>
16+
#include <locale.h>
17+
#include <stdlib.h>
18+
19+
#include "private/modulemd-util.h"
20+
21+
/*
22+
* modulemd_variant_deep_copy() triggered a GLib critical warning
23+
* from glib >= 2.84.1 when parsing a /data/xmd modulemd-stream-v2 element
24+
* with {} value (an empty flow mapping). This test exhibits that code path
25+
* and relies on G_DEBUG=fatal-criticals environment variable to crash the
26+
* test.
27+
* <https://github.com/fedora-modularity/libmodulemd/issues/623>.
28+
*/
29+
static void
30+
test_empty_a_sv (void)
31+
{
32+
g_autoptr (GVariantDict) dictionary =
33+
NULL; /* g_variant_dict_end() does not free */
34+
g_autoptr (GVariant) input = NULL;
35+
g_autoptr (GVariant) output = NULL;
36+
37+
/* Build a GVariant with an empty dictionary, results to an "a{sv}" of
38+
* zero size. */
39+
dictionary = g_variant_dict_new (NULL);
40+
input = g_variant_dict_end (dictionary);
41+
42+
/* Exhibit the library. */
43+
output = modulemd_variant_deep_copy (input);
44+
g_assert_true (output != NULL);
45+
46+
/* Compare the content. */
47+
g_assert_true (g_variant_get_type (output) == g_variant_get_type (input));
48+
g_assert_true (g_variant_get_size (output) == g_variant_get_size (input));
49+
}
50+
51+
52+
int
53+
main (int argc, char *argv[])
54+
{
55+
setlocale (LC_ALL, "");
56+
g_test_init (&argc, &argv, NULL);
57+
g_test_set_nonfatal_assertions ();
58+
59+
if (!g_setenv ("G_DEBUG", "fatal-criticals", TRUE))
60+
{
61+
g_fprintf (stderr, "Failed to set G_DEBUG environment variable.\n");
62+
exit (EXIT_FAILURE);
63+
}
64+
65+
g_test_add_func ("/modulemd/util/variant_deep_copy/empty_a{sv}",
66+
test_empty_a_sv);
67+
68+
return g_test_run ();
69+
}

0 commit comments

Comments
 (0)