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