10b3671
diff --git libselinux-2.8/man/man3/selinux_boolean_sub.3 libselinux-2.8/man/man3/selinux_boolean_sub.3
10b3671
index 308c268..a29a38d 100644
10b3671
--- libselinux-2.8/man/man3/selinux_boolean_sub.3
10b3671
+++ libselinux-2.8/man/man3/selinux_boolean_sub.3
10b3671
@@ -1,6 +1,6 @@
10b3671
 .TH "selinux_boolean_sub" "3" "11 June 2012" "dwalsh@redhat.com" "SELinux API documentation"
10b3671
 .SH "NAME"
10b3671
-selinux_boolean_sub \-
10b3671
+selinux_boolean_sub \- Search the translated name for a boolean_name record
10b3671
 .
10b3671
 .SH "SYNOPSIS"
10b3671
 .B #include <selinux/selinux.h>
10b3671
@@ -12,7 +12,7 @@ selinux_boolean_sub \-
10b3671
 searches the
10b3671
 .I \%/etc/selinux/{POLICYTYPE}/booleans.subs_dist
10b3671
 file
10b3671
-for a maching boolean_name record.  If the record exists the boolean substitution name is returned.  If not
10b3671
+for a matching boolean_name record.  If the record exists the boolean substitution name is returned.  If not
10b3671
 .BR \%selinux_boolean_sub ()
10b3671
 returns the original
10b3671
 .IR \%boolean_name .
10b3671
diff --git libselinux-2.8/man/man3/selinux_restorecon_xattr.3 libselinux-2.8/man/man3/selinux_restorecon_xattr.3
10b3671
index 7280c95..516d266 100644
10b3671
--- libselinux-2.8/man/man3/selinux_restorecon_xattr.3
10b3671
+++ libselinux-2.8/man/man3/selinux_restorecon_xattr.3
10b3671
@@ -119,7 +119,7 @@ By default
10b3671
 .BR selinux_restorecon_xattr (3)
10b3671
 will use the default set of specfiles described in
10b3671
 .BR files_contexts (5)
10b3671
-to calculate the initial SHA1 digest to be used for comparision.
10b3671
+to calculate the initial SHA1 digest to be used for comparison.
10b3671
 To change this default behavior
10b3671
 .BR selabel_open (3)
10b3671
 must be called specifying the required
10b3671
diff --git libselinux-2.8/man/man5/selabel_file.5 libselinux-2.8/man/man5/selabel_file.5
10b3671
index e738824..e97bd82 100644
10b3671
--- libselinux-2.8/man/man5/selabel_file.5
10b3671
+++ libselinux-2.8/man/man5/selabel_file.5
10b3671
@@ -92,7 +92,7 @@ The optional local and distribution substitution files that perform any path ali
10b3671
 .RE
10b3671
 .sp
10b3671
 The default file context series of files are:
10b3671
-.RS
10b3671
+.RS 6
10b3671
 .I /etc/selinux/{SELINUXTYPE}/contexts/files/file_contexts
10b3671
 .br
10b3671
 .I  /etc/selinux/{SELINUXTYPE}/contexts/files/file_contexts.local
cd8baf7
diff --git libselinux-2.8/man/man8/selinux.8 libselinux-2.8/man/man8/selinux.8
2f49e06
index e37aee6..bf23b65 100644
cd8baf7
--- libselinux-2.8/man/man8/selinux.8
cd8baf7
+++ libselinux-2.8/man/man8/selinux.8
e58e944
@@ -91,11 +91,13 @@ This manual page was written by Dan Walsh <dwalsh@redhat.com>.
e58e944
 .BR sepolicy (8),
e58e944
 .BR system-config-selinux (8),
e58e944
 .BR togglesebool (8),
e58e944
-.BR restorecon (8),
e58e944
 .BR fixfiles (8),
e58e944
+.BR restorecon (8),
e58e944
 .BR setfiles (8),
e58e944
 .BR semanage (8),
2f49e06
 .BR sepolicy (8)
2f49e06
+.BR seinfo (8),
2f49e06
+.BR sesearch (8)
e58e944
 
e58e944
 Every confined service on the system has a man page in the following format:
e58e944
 .br
10b3671
diff --git libselinux-2.8/src/audit2why.c libselinux-2.8/src/audit2why.c
10b3671
index 0331fdf..5a1e69a 100644
10b3671
--- libselinux-2.8/src/audit2why.c
10b3671
+++ libselinux-2.8/src/audit2why.c
10b3671
@@ -354,7 +354,7 @@ static PyObject *analyze(PyObject *self __attribute__((unused)) , PyObject *args
10b3671
 	/* iterate over items of the list, grabbing strings, and parsing
10b3671
 	   for numbers */
10b3671
 	for (i=0; i
10b3671
-		char *permstr;
10b3671
+		const char *permstr;
10b3671
 
10b3671
 		/* grab the string object from the next element of the list */
10b3671
 		strObj = PyList_GetItem(listObj, i); /* Can't fail */
cd8baf7
diff --git libselinux-2.8/src/avc_sidtab.c libselinux-2.8/src/avc_sidtab.c
e58e944
index 9669264..c775430 100644
cd8baf7
--- libselinux-2.8/src/avc_sidtab.c
cd8baf7
+++ libselinux-2.8/src/avc_sidtab.c
e58e944
@@ -81,6 +81,11 @@ sidtab_context_to_sid(struct sidtab *s,
e58e944
 	int hvalue, rc = 0;
e58e944
 	struct sidtab_node *cur;
e58e944
 
e58e944
+	if (! ctx) {
e58e944
+		errno=EINVAL;
e58e944
+		return -1;
e58e944
+	}
e58e944
+
e58e944
 	*sid = NULL;
e58e944
 	hvalue = sidtab_hash(ctx);
e58e944
 
cd8baf7
diff --git libselinux-2.8/src/booleans.c libselinux-2.8/src/booleans.c
9d8d73f
index b3ea362..a6d46fe 100644
cd8baf7
--- libselinux-2.8/src/booleans.c
cd8baf7
+++ libselinux-2.8/src/booleans.c
7f0ad32
@@ -55,6 +55,7 @@ int security_get_boolean_names(char ***names, int *len)
7f0ad32
 	snprintf(path, sizeof path, "%s%s", selinux_mnt, SELINUX_BOOL_DIR);
7f0ad32
 	*len = scandir(path, &namelist, &filename_select, alphasort);
7f0ad32
 	if (*len <= 0) {
7f0ad32
+		errno = ENOENT;
7f0ad32
 		return -1;
7f0ad32
 	}
7f0ad32
 
cd8baf7
diff --git libselinux-2.8/src/canonicalize_context.c libselinux-2.8/src/canonicalize_context.c
2f49e06
index ba4c9a2..c815872 100644
cd8baf7
--- libselinux-2.8/src/canonicalize_context.c
cd8baf7
+++ libselinux-2.8/src/canonicalize_context.c
e58e944
@@ -17,6 +17,11 @@ int security_canonicalize_context_raw(const char * con,
e58e944
 	size_t size;
e58e944
 	int fd, ret;
e58e944
 
e58e944
+	if (! con) {
e58e944
+		errno=EINVAL;
e58e944
+		return -1;
e58e944
+	}
e58e944
+
e58e944
 	if (!selinux_mnt) {
e58e944
 		errno = ENOENT;
e58e944
 		return -1;
9588e46
diff --git libselinux-2.8/src/checkAccess.c libselinux-2.8/src/checkAccess.c
9588e46
index 8de5747..16bfcfb 100644
9588e46
--- libselinux-2.8/src/checkAccess.c
9588e46
+++ libselinux-2.8/src/checkAccess.c
9588e46
@@ -89,8 +89,10 @@ int selinux_check_passwd_access(access_vector_t requested)
9588e46
 		int retval;
9588e46
 
9588e46
 		passwd_class = string_to_security_class("passwd");
9588e46
-		if (passwd_class == 0)
9588e46
+		if (passwd_class == 0) {
9588e46
+			freecon(user_context);
9588e46
 			return 0;
9588e46
+		}
9588e46
 
9588e46
 		retval = security_compute_av_raw(user_context,
9588e46
 						     user_context,
cd8baf7
diff --git libselinux-2.8/src/check_context.c libselinux-2.8/src/check_context.c
2f49e06
index 8a7997f..5be8434 100644
cd8baf7
--- libselinux-2.8/src/check_context.c
cd8baf7
+++ libselinux-2.8/src/check_context.c
e58e944
@@ -14,6 +14,11 @@ int security_check_context_raw(const char * con)
e58e944
 	char path[PATH_MAX];
e58e944
 	int fd, ret;
e58e944
 
e58e944
+	if (! con) {
e58e944
+		errno=EINVAL;
e58e944
+		return -1;
e58e944
+	}
e58e944
+
e58e944
 	if (!selinux_mnt) {
e58e944
 		errno = ENOENT;
e58e944
 		return -1;
cd8baf7
diff --git libselinux-2.8/src/compute_av.c libselinux-2.8/src/compute_av.c
2f49e06
index 1d05e7b..d9095cc 100644
cd8baf7
--- libselinux-2.8/src/compute_av.c
cd8baf7
+++ libselinux-2.8/src/compute_av.c
e58e944
@@ -26,6 +26,11 @@ int security_compute_av_flags_raw(const char * scon,
e58e944
 		return -1;
e58e944
 	}
e58e944
 
e58e944
+	if ((! scon) || (! tcon)) {
e58e944
+		errno=EINVAL;
e58e944
+		return -1;
e58e944
+	}
e58e944
+
e58e944
 	snprintf(path, sizeof path, "%s/access", selinux_mnt);
2f49e06
 	fd = open(path, O_RDWR | O_CLOEXEC);
e58e944
 	if (fd < 0)
cd8baf7
diff --git libselinux-2.8/src/compute_create.c libselinux-2.8/src/compute_create.c
2f49e06
index 0975aea..3e6a48c 100644
cd8baf7
--- libselinux-2.8/src/compute_create.c
cd8baf7
+++ libselinux-2.8/src/compute_create.c
e58e944
@@ -64,6 +64,11 @@ int security_compute_create_name_raw(const char * scon,
e58e944
 		return -1;
e58e944
 	}
e58e944
 
e58e944
+	if ((! scon) || (! tcon)) {
e58e944
+		errno=EINVAL;
e58e944
+		return -1;
e58e944
+	}
e58e944
+
e58e944
 	snprintf(path, sizeof path, "%s/create", selinux_mnt);
2f49e06
 	fd = open(path, O_RDWR | O_CLOEXEC);
e58e944
 	if (fd < 0)
cd8baf7
diff --git libselinux-2.8/src/compute_member.c libselinux-2.8/src/compute_member.c
2f49e06
index 4e2d221..d1dd977 100644
cd8baf7
--- libselinux-2.8/src/compute_member.c
cd8baf7
+++ libselinux-2.8/src/compute_member.c
e58e944
@@ -25,6 +25,11 @@ int security_compute_member_raw(const char * scon,
e58e944
 		return -1;
e58e944
 	}
e58e944
 
e58e944
+	if ((! scon) || (! tcon)) {
e58e944
+		errno=EINVAL;
e58e944
+		return -1;
e58e944
+	}
e58e944
+
e58e944
 	snprintf(path, sizeof path, "%s/member", selinux_mnt);
2f49e06
 	fd = open(path, O_RDWR | O_CLOEXEC);
e58e944
 	if (fd < 0)
cd8baf7
diff --git libselinux-2.8/src/compute_relabel.c libselinux-2.8/src/compute_relabel.c
2f49e06
index 49f77ef..c3db7c0 100644
cd8baf7
--- libselinux-2.8/src/compute_relabel.c
cd8baf7
+++ libselinux-2.8/src/compute_relabel.c
e58e944
@@ -25,6 +25,11 @@ int security_compute_relabel_raw(const char * scon,
e58e944
 		return -1;
e58e944
 	}
e58e944
 
e58e944
+	if ((! scon) || (! tcon)) {
e58e944
+		errno=EINVAL;
e58e944
+		return -1;
e58e944
+	}
e58e944
+
e58e944
 	snprintf(path, sizeof path, "%s/relabel", selinux_mnt);
2f49e06
 	fd = open(path, O_RDWR | O_CLOEXEC);
e58e944
 	if (fd < 0)
cd8baf7
diff --git libselinux-2.8/src/compute_user.c libselinux-2.8/src/compute_user.c
2f49e06
index 7b88121..401fd10 100644
cd8baf7
--- libselinux-2.8/src/compute_user.c
cd8baf7
+++ libselinux-2.8/src/compute_user.c
e58e944
@@ -24,6 +24,11 @@ int security_compute_user_raw(const char * scon,
e58e944
 		return -1;
e58e944
 	}
e58e944
 
e58e944
+	if (! scon) {
e58e944
+		errno=EINVAL;
e58e944
+		return -1;
e58e944
+	}
e58e944
+
e58e944
 	snprintf(path, sizeof path, "%s/user", selinux_mnt);
2f49e06
 	fd = open(path, O_RDWR | O_CLOEXEC);
e58e944
 	if (fd < 0)
cd8baf7
diff --git libselinux-2.8/src/fsetfilecon.c libselinux-2.8/src/fsetfilecon.c
e58e944
index 52707d0..0cbe12d 100644
cd8baf7
--- libselinux-2.8/src/fsetfilecon.c
cd8baf7
+++ libselinux-2.8/src/fsetfilecon.c
e58e944
@@ -9,8 +9,12 @@
e58e944
 
e58e944
 int fsetfilecon_raw(int fd, const char * context)
e58e944
 {
e58e944
-	int rc = fsetxattr(fd, XATTR_NAME_SELINUX, context, strlen(context) + 1,
e58e944
-			 0);
e58e944
+	int rc;
e58e944
+	if (! context) {
e58e944
+		errno=EINVAL;
e58e944
+		return -1;
e58e944
+	}
e58e944
+	rc = fsetxattr(fd, XATTR_NAME_SELINUX, context, strlen(context) + 1, 0);
e58e944
 	if (rc < 0 && errno == ENOTSUP) {
e58e944
 		char * ccontext = NULL;
e58e944
 		int err = errno;
9588e46
diff --git libselinux-2.8/src/label_db.c libselinux-2.8/src/label_db.c
9588e46
index c46d0a1..fa481e0 100644
9588e46
--- libselinux-2.8/src/label_db.c
9588e46
+++ libselinux-2.8/src/label_db.c
9588e46
@@ -283,10 +283,12 @@ db_init(const struct selinux_opt *opts, unsigned nopts,
9588e46
 	}
9588e46
 	if (fstat(fileno(filp), &sb) < 0) {
9588e46
 		free(catalog);
9588e46
+    fclose(filp);
9588e46
 		return NULL;
9588e46
 	}
9588e46
 	if (!S_ISREG(sb.st_mode)) {
9588e46
 		free(catalog);
9588e46
+    fclose(filp);
9588e46
 		errno = EINVAL;
9588e46
 		return NULL;
9588e46
 	}
9588e46
@@ -340,6 +342,7 @@ out_error:
9588e46
 		free(spec->lr.ctx_trans);
9588e46
 	}
9588e46
 	free(catalog);
9588e46
+	fclose(filp);
9588e46
 
9588e46
 	return NULL;
9588e46
 }
9588e46
diff --git libselinux-2.8/src/label_file.c libselinux-2.8/src/label_file.c
9588e46
index 560d8c3..21c8d36 100644
9588e46
--- libselinux-2.8/src/label_file.c
9588e46
+++ libselinux-2.8/src/label_file.c
9588e46
@@ -317,8 +317,10 @@ end_arch_check:
9588e46
 			goto out;
9588e46
 		}
9588e46
 		rc = next_entry(str_buf, mmap_area, entry_len);
9588e46
-		if (rc < 0)
9588e46
+		if (rc < 0) {
9588e46
+			free(str_buf);
9588e46
 			goto out;
9588e46
+		}
9588e46
 
9588e46
 		if (str_buf[entry_len - 1] != '\0') {
9588e46
 			free(str_buf);
9588e46
diff --git libselinux-2.8/src/load_policy.c libselinux-2.8/src/load_policy.c
9588e46
index e9f1264..20052be 100644
9588e46
--- libselinux-2.8/src/load_policy.c
9588e46
+++ libselinux-2.8/src/load_policy.c
9588e46
@@ -262,8 +262,10 @@ checkbool:
9588e46
 			rc = security_get_boolean_names(&names, &len;;
9588e46
 			if (!rc) {
9588e46
 				values = malloc(sizeof(int) * len);
9588e46
-				if (!values)
9588e46
+				if (!values) {
9588e46
+					free(names);
9588e46
 					goto unmap;
9588e46
+				}
9588e46
 				for (i = 0; i < len; i++)
9588e46
 					values[i] =
9588e46
 						security_get_boolean_active(names[i]);
cd8baf7
diff --git libselinux-2.8/src/lsetfilecon.c libselinux-2.8/src/lsetfilecon.c
e58e944
index 1d3b28a..ea6d70b 100644
cd8baf7
--- libselinux-2.8/src/lsetfilecon.c
cd8baf7
+++ libselinux-2.8/src/lsetfilecon.c
e58e944
@@ -9,8 +9,13 @@
e58e944
 
e58e944
 int lsetfilecon_raw(const char *path, const char * context)
e58e944
 {
e58e944
-	int rc = lsetxattr(path, XATTR_NAME_SELINUX, context, strlen(context) + 1,
e58e944
-			 0);
e58e944
+	int rc;
e58e944
+	if (! context) {
e58e944
+		errno=EINVAL;
e58e944
+		return -1;
e58e944
+	}
e58e944
+
e58e944
+	rc = lsetxattr(path, XATTR_NAME_SELINUX, context, strlen(context) + 1, 0);
e58e944
 	if (rc < 0 && errno == ENOTSUP) {
e58e944
 		char * ccontext = NULL;
e58e944
 		int err = errno;
9588e46
diff --git libselinux-2.8/src/selinux_config.c libselinux-2.8/src/selinux_config.c
9588e46
index 292728f..b06cb63 100644
9588e46
--- libselinux-2.8/src/selinux_config.c
9588e46
+++ libselinux-2.8/src/selinux_config.c
9588e46
@@ -177,8 +177,7 @@ static void init_selinux_config(void)
9588e46
 
9588e46
 			if (!strncasecmp(buf_p, SELINUXTYPETAG,
9588e46
 					 sizeof(SELINUXTYPETAG) - 1)) {
9588e46
-				selinux_policytype = type =
9588e46
-				    strdup(buf_p + sizeof(SELINUXTYPETAG) - 1);
9588e46
+				type = strdup(buf_p + sizeof(SELINUXTYPETAG) - 1);
9588e46
 				if (!type)
9588e46
 					return;
9588e46
 				end = type + strlen(type) - 1;
9588e46
@@ -187,6 +186,11 @@ static void init_selinux_config(void)
9588e46
 					*end = 0;
9588e46
 					end--;
9588e46
 				}
9588e46
+				if (setpolicytype(type) != 0) {
9588e46
+					free(type);
9588e46
+					return;
9588e46
+				}
9588e46
+				free(type);
9588e46
 				continue;
9588e46
 			} else if (!strncmp(buf_p, SETLOCALDEFS,
9588e46
 					    sizeof(SETLOCALDEFS) - 1)) {
9588e46
@@ -212,13 +216,10 @@ static void init_selinux_config(void)
9588e46
 		fclose(fp);
9588e46
 	}
9588e46
 
9588e46
-	if (!type) {
9588e46
-		selinux_policytype = type = strdup(SELINUXDEFAULT);
9588e46
-		if (!type)
9588e46
-			return;
9588e46
-	}
9588e46
+	if (!selinux_policytype && setpolicytype(SELINUXDEFAULT) != 0)
9588e46
+		return;
9588e46
 
9588e46
-	if (asprintf(&selinux_policyroot, "%s%s", SELINUXDIR, type) == -1)
9588e46
+	if (asprintf(&selinux_policyroot, "%s%s", SELINUXDIR, selinux_policytype) == -1)
9588e46
 		return;
9588e46
 
9588e46
 	for (i = 0; i < NEL; i++)
9588e46
diff --git libselinux-2.8/src/selinux_restorecon.c libselinux-2.8/src/selinux_restorecon.c
afbe0c7
index ced4115..1e9a978 100644
9588e46
--- libselinux-2.8/src/selinux_restorecon.c
9588e46
+++ libselinux-2.8/src/selinux_restorecon.c
9588e46
@@ -350,12 +350,19 @@ static int add_xattr_entry(const char *directory, bool delete_nonmatch,
9588e46
 	new_entry->next = NULL;
9588e46
 
9588e46
 	new_entry->directory = strdup(directory);
9588e46
-	if (!new_entry->directory)
9588e46
+	if (!new_entry->directory) {
9588e46
+		free(new_entry);
9588e46
+		free(sha1_buf);
9588e46
 		goto oom;
9588e46
+	}
9588e46
 
9588e46
 	new_entry->digest = strdup(sha1_buf);
9588e46
-	if (!new_entry->digest)
9588e46
+	if (!new_entry->digest) {
9588e46
+		free(new_entry->directory);
9588e46
+		free(new_entry);
9588e46
+		free(sha1_buf);
9588e46
 		goto oom;
9588e46
+	}
9588e46
 
9588e46
 	new_entry->result = digest_result;
9588e46
 
afbe0c7
@@ -671,8 +678,8 @@ static int restorecon_sb(const char *pathname, const struct stat *sb,
afbe0c7
 				selinux_log(SELINUX_INFO,
afbe0c7
 				 "%s not reset as customized by admin to %s\n",
afbe0c7
 							    pathname, curcon);
afbe0c7
-				goto out;
afbe0c7
 			}
afbe0c7
+			goto out;
afbe0c7
 		}
afbe0c7
 
afbe0c7
 		if (!flags->set_specctx && curcon) {
9588e46
@@ -849,6 +856,7 @@ int selinux_restorecon(const char *pathname_orig,
9588e46
 
9588e46
 	if (lstat(pathname, &sb) < 0) {
9588e46
 		if (flags.ignore_noent && errno == ENOENT) {
9588e46
+			free(xattr_value);
9588e46
 			free(pathdnamer);
9588e46
 			free(pathname);
9588e46
 			return 0;
afbe0c7
@@ -880,7 +888,7 @@ int selinux_restorecon(const char *pathname_orig,
afbe0c7
 		setrestoreconlast = false;
afbe0c7
 
afbe0c7
 	/* Ignore restoreconlast on in-memory filesystems */
afbe0c7
-	if (statfs(pathname, &sfsb) == 0) {
afbe0c7
+	if (setrestoreconlast && statfs(pathname, &sfsb) == 0) {
afbe0c7
 		if (sfsb.f_type == RAMFS_MAGIC || sfsb.f_type == TMPFS_MAGIC)
afbe0c7
 			setrestoreconlast = false;
afbe0c7
 	}
cd8baf7
diff --git libselinux-2.8/src/setfilecon.c libselinux-2.8/src/setfilecon.c
e58e944
index d05969c..3f0200e 100644
cd8baf7
--- libselinux-2.8/src/setfilecon.c
cd8baf7
+++ libselinux-2.8/src/setfilecon.c
e58e944
@@ -9,8 +9,12 @@
e58e944
 
e58e944
 int setfilecon_raw(const char *path, const char * context)
e58e944
 {
e58e944
-	int rc = setxattr(path, XATTR_NAME_SELINUX, context, strlen(context) + 1,
e58e944
-			0);
e58e944
+	int rc;
e58e944
+	if (! context) {
e58e944
+		errno=EINVAL;
e58e944
+		return -1;
e58e944
+	}
e58e944
+	rc = setxattr(path, XATTR_NAME_SELINUX, context, strlen(context) + 1, 0);
e58e944
 	if (rc < 0 && errno == ENOTSUP) {
e58e944
 		char * ccontext = NULL;
e58e944
 		int err = errno;
cd8baf7
diff --git libselinux-2.8/utils/matchpathcon.c libselinux-2.8/utils/matchpathcon.c
2f49e06
index 67e4a43..9756d7d 100644
cd8baf7
--- libselinux-2.8/utils/matchpathcon.c
cd8baf7
+++ libselinux-2.8/utils/matchpathcon.c
2f49e06
@@ -14,7 +14,7 @@
2f49e06
 static __attribute__ ((__noreturn__)) void usage(const char *progname)
7f0ad32
 {
7f0ad32
 	fprintf(stderr,
7f0ad32
-		"usage:  %s [-N] [-n] [-f file_contexts] [ -P policy_root_path ] [-p prefix] [-Vq] path...\n",
7f0ad32
+		"usage:  %s [-V] [-N] [-n] [-m type] [-f file_contexts_file] [-p prefix] [-P policy_root_path] filepath...\n",
7f0ad32
 		progname);
7f0ad32
 	exit(1);
7f0ad32
 }