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




commit 8a9ef88fbf69df45c4b8a328fdc0d6272fdc273e
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 | 29 +++++++++++++++++++++++++++++
 egg/egg-secure-memory.c         |  7 +++++++
 egg/test-secmem.c               |  8 +++-----
 gcr/test-secure-memory.c        | 11 +++++------
 4 files changed, 44 insertions(+), 11 deletions(-)
---
diff --git a/egg/egg-secure-memory-private.h b/egg/egg-secure-memory-private.h
new file mode 100644
index 00000000..35af1653
--- /dev/null
+++ b/egg/egg-secure-memory-private.h
@@ -0,0 +1,29 @@
+/* egg-secure-memory.h - library for allocating memory that is non-pageable
+
+   Copyright (C) 2007 Stefan Walter
+
+   The Gnome Keyring Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The Gnome Keyring Library 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the Gnome Library; see the file COPYING.LIB.  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..dbc5f246 100644
--- a/egg/egg-secure-memory.c
+++ b/egg/egg-secure-memory.c
@@ -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]