From b6a26c64394f924c2766f57a9218213ad9bf1d70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Corentin=20No=C3=ABl?= Date: Mon, 30 May 2022 23:52:41 +0200 Subject: 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 +++----- 3 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 egg/egg-secure-memory-private.h (limited to 'egg') diff --git a/egg/egg-secure-memory-private.h b/egg/egg-secure-memory-private.h new file mode 100644 index 0000000..7be32cc --- /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 . + * + * Author: Corentin Noël + */ + +#ifndef EGG_SECURE_MEMORY_PRIVATE_H +#define EGG_SECURE_MEMORY_PRIVATE_H + +#include + +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 bcc067e..c244010 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 8a63983..5fc0d1b 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 @@ -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 -- cgit v1.2.1