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