[gcr/tintou/fix-ci] secure-memory: Fix odr-violation by using a private setter




commit a86d9f25e68784358eca893823aa57b8e99a0be3
Author: Corentin Noël <corentin noel collabora com>
Date:   Mon May 30 23:52:41 2022 +0200

    secure-memory: Fix odr-violation by using a private setter

 egg/egg-secure-memory-private.h | 27 +++++++++++++++++++++++++++
 egg/egg-secure-memory.c         |  9 ++++++++-
 egg/test-secmem.c               |  8 +++-----
 gcr/test-secure-memory.c        | 11 +++++------
 4 files changed, 43 insertions(+), 12 deletions(-)
---
diff --git a/egg/egg-secure-memory-private.h b/egg/egg-secure-memory-private.h
new file mode 100644
index 00000000..7be32cc4
--- /dev/null
+++ b/egg/egg-secure-memory-private.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2022 Collabora Ltd. (https://collabora.com)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Corentin Noël <corentin noel collabora com>
+ */
+
+#ifndef EGG_SECURE_MEMORY_PRIVATE_H
+#define EGG_SECURE_MEMORY_PRIVATE_H
+
+#include <stdlib.h>
+
+void egg_set_secure_warnings (int val);
+
+#endif /* EGG_SECURE_MEMORY_PRIVATE_H */
diff --git a/egg/egg-secure-memory.c b/egg/egg-secure-memory.c
index bcc067ee..c244010a 100644
--- a/egg/egg-secure-memory.c
+++ b/egg/egg-secure-memory.c
@@ -71,7 +71,7 @@
        EGG_SECURE_GLOBALS.unlock ();
 
 static int show_warning = 1;
-int egg_secure_warnings = 1;
+static int egg_secure_warnings = 1;
 
 /*
  * We allocate all memory in units of sizeof(void*). This
@@ -1383,3 +1383,10 @@ egg_secure_strfree (char *str)
        egg_secure_strclear (str);
        egg_secure_free_full (str, EGG_SECURE_USE_FALLBACK);
 }
+
+void
+egg_set_secure_warnings (int val)
+{
+       egg_secure_warnings = val;
+}
+
diff --git a/egg/test-secmem.c b/egg/test-secmem.c
index 8a63983a..5fc0d1b7 100644
--- a/egg/test-secmem.c
+++ b/egg/test-secmem.c
@@ -23,6 +23,7 @@
 #include "config.h"
 
 #include "egg/egg-secure-memory.h"
+#include "egg/egg-secure-memory-private.h"
 
 #include <glib.h>
 
@@ -33,9 +34,6 @@
 
 EGG_SECURE_DEFINE_GLIB_GLOBALS ();
 
-/* Declared in egg-secure-memory.c */
-extern int egg_secure_warnings;
-
 EGG_SECURE_DECLARE (tests);
 
 /*
@@ -163,7 +161,7 @@ test_multialloc (void)
        memory = g_ptr_array_new ();
 
        /* Don't print "can't allocate" warnings */
-       egg_secure_warnings = 0;
+       egg_set_secure_warnings (0);
 
        for (i = 0; TRUE; ++i) {
 
@@ -216,7 +214,7 @@ test_multialloc (void)
                egg_secure_free (memory->pdata[i]);
        g_ptr_array_free (memory, TRUE);
 
-       egg_secure_warnings = 1;
+       egg_set_secure_warnings (1);
 }
 
 static void
diff --git a/gcr/test-secure-memory.c b/gcr/test-secure-memory.c
index 2b9061c0..c9e606d2 100644
--- a/gcr/test-secure-memory.c
+++ b/gcr/test-secure-memory.c
@@ -24,6 +24,7 @@
 #include "config.h"
 
 #include "gcr/gcr-secure-memory.h"
+#include "egg/egg-secure-memory-private.h"
 
 #include <glib.h>
 
@@ -50,8 +51,6 @@ find_non_zero (gpointer mem, gsize len)
        return -1;
 }
 
-extern int egg_secure_warnings;
-
 static gsize
 get_rlimit_memlock (void)
 {
@@ -141,12 +140,12 @@ test_alloc_oversized (void)
                return;
 
        /* Try the allocation. */
-       egg_secure_warnings = 0;
+       egg_set_secure_warnings (0);
 
        mem = gcr_secure_memory_try_alloc (limit + 1);
        g_assert_null (mem);
 
-       egg_secure_warnings = 1;
+       egg_set_secure_warnings (1);
 }
 
 static void
@@ -209,12 +208,12 @@ test_realloc_oversized (void)
        mem = gcr_secure_memory_alloc (64);
        g_assert_nonnull (mem);
 
-       egg_secure_warnings = 0;
+       egg_set_secure_warnings (0);
 
        new_mem = gcr_secure_memory_try_realloc (mem, limit + 1);
        g_assert_null (new_mem);
 
-       egg_secure_warnings = 1;
+       egg_set_secure_warnings (1);
 
        gcr_secure_memory_free (mem);
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]