summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuca BRUNO <luca.bruno@coreos.com>2022-01-10 10:22:28 +0000
committerLuca BRUNO <luca.bruno@coreos.com>2022-01-10 13:33:36 +0000
commit0bdba574d735ae37447d4c1e8bd0b6a4e622da79 (patch)
tree197674a5e932e37afe0b11b95575570de3a688af
parent92025018f6c64b608ef7f8d8fab27dc18ee90c7f (diff)
downloadostree-0bdba574d735ae37447d4c1e8bd0b6a4e622da79.tar.gz
ostree: check g_setenv return value
This adds proper return-value checks on g_setenv calls. It fixes a static analysis warning highlighted by Coverity.
-rw-r--r--src/libostree/ostree-sepolicy.c5
-rw-r--r--src/ostree/ot-main.c6
-rw-r--r--tests/libostreetest.c3
-rw-r--r--tests/test-gpg-verify-result.c3
-rw-r--r--tests/test-rollsum-cli.c3
-rw-r--r--tests/test-varint.c3
6 files changed, 17 insertions, 6 deletions
diff --git a/src/libostree/ostree-sepolicy.c b/src/libostree/ostree-sepolicy.c
index d8ff35cb..0fed6457 100644
--- a/src/libostree/ostree-sepolicy.c
+++ b/src/libostree/ostree-sepolicy.c
@@ -422,7 +422,10 @@ initable_init (GInitable *initable,
{
const char *policy_rootpath = gs_file_get_path_cached (policy_root);
- g_setenv ("LIBSELINUX_DISABLE_PCRE_PRECOMPILED", "1", FALSE);
+ /* TODO(lucab): get rid of this setenv(), it may be unsafe in a multi-thread context. */
+ if (!g_setenv ("LIBSELINUX_DISABLE_PCRE_PRECOMPILED", "1", FALSE))
+ return glnx_throw (error, "Failed to set environment variable LIBSELINUX_DISABLE_PCRE_PRECOMPILED");
+
if (selinux_set_policy_root (policy_rootpath) != 0)
return glnx_throw_errno_prefix (error, "selinux_set_policy_root(%s)", policy_rootpath);
diff --git a/src/ostree/ot-main.c b/src/ostree/ot-main.c
index 8ee73038..b72fa9d4 100644
--- a/src/ostree/ot-main.c
+++ b/src/ostree/ot-main.c
@@ -253,7 +253,11 @@ ostree_run (int argc,
int in, out;
/* avoid gvfs (http://bugzilla.gnome.org/show_bug.cgi?id=526454) */
- g_setenv ("GIO_USE_VFS", "local", TRUE);
+ if (!g_setenv ("GIO_USE_VFS", "local", TRUE))
+ {
+ (void) glnx_throw (res_error, "Failed to set environment variable GIO_USE_FVS");
+ return 1;
+ }
g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, message_handler, NULL);
diff --git a/tests/libostreetest.c b/tests/libostreetest.c
index d5671a1e..08abb9f1 100644
--- a/tests/libostreetest.c
+++ b/tests/libostreetest.c
@@ -155,7 +155,8 @@ ot_test_setup_sysroot (GCancellable *cancellable,
}
/* Make sure deployments are mutable */
- g_setenv ("OSTREE_SYSROOT_DEBUG", buf->str, TRUE);
+ if (!g_setenv ("OSTREE_SYSROOT_DEBUG", buf->str, TRUE))
+ return glnx_null_throw (error, "Failed to set environment variable OSTREE_SYSROOT_DEBUG");
g_autoptr(GFile) sysroot_path = g_file_new_for_path ("sysroot");
return ostree_sysroot_new (sysroot_path);
diff --git a/tests/test-gpg-verify-result.c b/tests/test-gpg-verify-result.c
index d49224ec..8485b888 100644
--- a/tests/test-gpg-verify-result.c
+++ b/tests/test-gpg-verify-result.c
@@ -78,7 +78,8 @@ test_fixture_setup (TestFixture *fixture,
* certificates for certain test cases. */
homedir = g_test_build_filename (G_TEST_DIST, "tests/gpg-verify-data", NULL);
- g_setenv ("GNUPGHOME", homedir, TRUE);
+ gboolean is_ok = g_setenv ("GNUPGHOME", homedir, TRUE);
+ g_assert (is_ok == TRUE);
result = g_initable_new (OSTREE_TYPE_GPG_VERIFY_RESULT,
NULL, &local_error, NULL);
diff --git a/tests/test-rollsum-cli.c b/tests/test-rollsum-cli.c
index 44e3390c..2cf730d3 100644
--- a/tests/test-rollsum-cli.c
+++ b/tests/test-rollsum-cli.c
@@ -35,7 +35,8 @@ main (int argc, char **argv)
OstreeRollsumMatches *matches;
GMappedFile *mfile;
- g_setenv ("GIO_USE_VFS", "local", TRUE);
+ gboolean is_ok = g_setenv ("GIO_USE_VFS", "local", TRUE);
+ g_assert (is_ok == TRUE);
if (argc < 3)
return 1;
diff --git a/tests/test-varint.c b/tests/test-varint.c
index e86c008f..3fea805e 100644
--- a/tests/test-varint.c
+++ b/tests/test-varint.c
@@ -58,7 +58,8 @@ int
main (int argc, char **argv)
{
- g_setenv ("GIO_USE_VFS", "local", TRUE);
+ gboolean is_ok = g_setenv ("GIO_USE_VFS", "local", TRUE);
+ g_assert (is_ok == TRUE);
g_test_init (&argc, &argv, NULL);