Ondrej Vasik 5f9af7
From a089634c855312a28f2ff3c2e7c08df5d030e2f5 Mon Sep 17 00:00:00 2001
Ondrej Vasik 5f9af7
From: Jim Meyering <meyering <at> redhat.com>
Ondrej Vasik 5f9af7
Date: Tue, 20 May 2008 17:58:42 +0200
Ondrej Vasik 5f9af7
Subject: [PATCH] install: avoid a leak in currently-ifdef'd-out code
Ondrej Vasik 5f9af7
Ondrej Vasik 5f9af7
* src/install.c (setdefaultfilecon)
Ondrej Vasik 5f9af7
[ENABLE_WHEN_MATCHPATHCON_IS_MORE_EFFICIENT]:
Ondrej Vasik 5f9af7
Call matchpathcon_init_prefix only once.
Ondrej Vasik 5f9af7
Suggestion from Stephen Smalley.  Reported by Ben Webb in
Ondrej Vasik 5f9af7
<http://bugzilla.redhat.com/447410>.
Ondrej Vasik 5f9af7
---
Ondrej Vasik 5f9af7
 src/install.c |    5 ++++-
Ondrej Vasik 5f9af7
 1 files changed, 4 insertions(+), 1 deletions(-)
Ondrej Vasik 5f9af7
Ondrej Vasik 5f9af7
diff --git a/src/install.c b/src/install.c
Ondrej Vasik 5f9af7
index 964ab36..b531f45 100644
Ondrej Vasik 5f9af7
--- a/src/install.c
Ondrej Vasik 5f9af7
+++ b/src/install.c
Ondrej Vasik 5f9af7
@@ -208,6 +208,8 @@ setdefaultfilecon (char const *file)
Ondrej Vasik 26314c
 {
Ondrej Vasik 26314c
   struct stat st;
Ondrej Vasik 5f9af7
   security_context_t scontext = NULL;
Ondrej Vasik 5f9af7
+  static bool first_call = true;
Ondrej Vasik 5f9af7
+
Ondrej Vasik 26314c
   if (selinux_enabled != 1)
Ondrej Vasik 26314c
     {
Ondrej Vasik 26314c
       /* Indicate no context found. */
Ondrej Vasik 5f9af7
@@ -216,7 +218,7 @@ setdefaultfilecon (char const *file)
Ondrej Vasik 26314c
   if (lstat (file, &st) != 0)
Ondrej Vasik 26314c
     return;
Ondrej Vasik 5f9af7
Ondrej Vasik 5f9af7
-  if (IS_ABSOLUTE_FILE_NAME (file))
Ondrej Vasik 5f9af7
+  if (first_call && IS_ABSOLUTE_FILE_NAME (file))
Ondrej Vasik 26314c
     {
Ondrej Vasik 5f9af7
       /* Calling matchpathcon_init_prefix (NULL, "/first_component/")
Ondrej Vasik 26314c
 	 is an optimization to minimize the expense of the following
Ondrej Vasik 5f9af7
@@ -247,6 +249,7 @@ setdefaultfilecon (char const *file)
Ondrej Vasik 5f9af7
 	    }
Ondrej Vasik 26314c
 	}
Ondrej Vasik 26314c
     }
Ondrej Vasik 5f9af7
+  first_call = false;
Ondrej Vasik 5f9af7
Ondrej Vasik 26314c
   /* If there's an error determining the context, or it has none,
Ondrej Vasik 26314c
      return to allow default context */
Ondrej Vasik 5f9af7
--
Ondrej Vasik 5f9af7
1.5.5.1.249.g68ef3