Skip to contentSkip to conversation

fix warnings in selinux-usr

PATCH In review Karl MacMillan 3 participants 9 messages May 5, 2006 – May 9, 2006 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix warnings in selinux-usr

Steve,

Attached is a patch that fixes many warnings that have crept into the selinux-usr code over time, making it difficult to ascertain whether code changes have introduced new warnings.

Fixing some of the warnings required the introduction of unsafe casts, but those casts were occurring implicitly anyway (see libsemanage/src/booleans_policydb.c for an example).

I fixed one of the long standing lex warnings that has always been irritating, but I was unable to fix the warnings in the semanage configuration file parser. That parser should not rewritten to remove the lex dependency in the future anyway.

Overview of changes:

 checkpolicy/policy_scan.l                           |    3
 checkpolicy/test/dismod.c                           |    1
 checkpolicy/test/dispol.c                           |    1
 libselinux/src/booleans.c                           |    2
 libselinux/src/context.c                            |    8
 libsemanage/src/booleans_policydb.c                 |   36 +++
 libsemanage/src/conf-scan.l                         |    1
 libsemanage/src/database_policydb.h                 |   91 +++++----
 libsemanage/src/fcontexts_local.c                   |    2
 libsemanage/src/interfaces_policydb.c               |   28 ++-
 libsemanage/src/nodes_policydb.c                    |   27 ++
 libsemanage/src/ports_policydb.c                    |   27 ++
 libsemanage/src/semanage_store.c                    |   10 -
 libsemanage/src/users_base_policydb.c               |   27 ++
 libsepol/include/sepol/policydb/policydb.h          |    3
 libsepol/include/sepol/policydb/util.h              |   32 +++
 libsepol/src/assertion.c                            |    1
 libsepol/src/debug.h                                |   39 +++-
 libsepol/src/policydb.c                             |  180
+++++++++++++++++++
 libsepol/src/util.c                                 |  186
--------------------
 policycoreutils/semodule_expand/semodule_expand.c   |   11 -
 policycoreutils/semodule_package/semodule_package.c |    4
 policycoreutils/setsebool/setsebool.c               |    8
 23 files changed, 440 insertions(+), 288 deletions(-)

This patch is relative to the test-framework patches that I sent earlier in the week, but I can re-base off HEAD if you would prefer.

Please apply.

Karl

Signature · 3 lines
Karl MacMillan
Tresys Technology
www.tresys.com
checkpolicy/policy_scan.l renamed from test_framework/checkpolicy/policy_scan.l +3 -0
diff --exclude=.svn -ruN ../test_framework/checkpolicy/policy_scan.l ./checkpolicy/policy_scan.l
@@ -40,6 +40,9 @@
 
 unsigned int policydb_errors = 0;
 %}
+
+%option nounput
+
 %array
 letter  [A-Za-z]
 digit   [0-9]
checkpolicy/test/dismod.c renamed from test_framework/checkpolicy/test/dismod.c +1 -0
diff --exclude=.svn -ruN ../test_framework/checkpolicy/test/dismod.c ./checkpolicy/test/dismod.c
@@ -33,6 +33,7 @@
 #include <sepol/policydb/flask.h>
 #include <sepol/policydb/link.h>
 #include <sepol/policydb/module.h>
+#include <sepol/policydb/util.h>
 
 #include <byteswap.h>
 #include <endian.h>
checkpolicy/test/dispol.c renamed from test_framework/checkpolicy/test/dispol.c +1 -0
diff --exclude=.svn -ruN ../test_framework/checkpolicy/test/dispol.c ./checkpolicy/test/dispol.c
@@ -22,6 +22,7 @@
 #include <sepol/policydb/services.h>
 #include <sepol/policydb/conditional.h>
 #include <sepol/policydb/expand.h>
+#include <sepol/policydb/util.h>
 #include <getopt.h>
 #include <assert.h>
 #include <unistd.h>
libselinux/src/booleans.c renamed from test_framework/libselinux/src/booleans.c +1 -1
diff --exclude=.svn -ruN ../test_framework/libselinux/src/booleans.c ./libselinux/src/booleans.c
@@ -309,7 +309,7 @@
 		int val;
 		char boolname[BUFSIZ];
 		char *buffer;
-		char *inbuf=NULL;
+		inbuf=NULL;
 		__fsetlocking(boolf, FSETLOCKING_BYCALLER);
 		while ((len=getline(&inbuf, &size, boolf)) > 0) {
 			buffer=strdup(inbuf);
libselinux/src/context.c renamed from test_framework/libselinux/src/context.c +4 -4
diff --exclude=.svn -ruN ../test_framework/libselinux/src/context.c ./libselinux/src/context.c
@@ -137,7 +137,7 @@
 
 /* Returns nonzero iff failed */
 
-static int set_comp(context_private_t* n,int index, const char *str)
+static int set_comp(context_private_t* n,int idx, const char *str)
 {
 	char *t = NULL;
         const char *p;
@@ -146,15 +146,15 @@
 		if ( !t ) { return 1; }
 		for ( p = str; *p; p++ ) {
 			if ( *p == '\t' || *p == '\n' || *p == '\r' ||
-			     ((*p == ':' || *p == ' ') && index != COMP_RANGE) ) {
+			     ((*p == ':' || *p == ' ') && idx != COMP_RANGE) ) {
 				free(t);
 				return 1;
 			}
 		}
 		strcpy(t,str);
 	}
-        conditional_free(&n->component[index]);
-        n->component[index] = t;
+        conditional_free(&n->component[idx]);
+        n->component[idx] = t;
         return 0;
 }
 
libsemanage/src/booleans_policydb.c renamed from test_framework/libsemanage/src/booleans_policydb.c +28 -8
diff --exclude=.svn -ruN ../test_framework/libsemanage/src/booleans_policydb.c ./libsemanage/src/booleans_policydb.c
@@ -1,3 +1,21 @@
+/*
+ * Copyright (C) 2006 Tresys Technology, LLC
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
 /* Copyright (C) 2005 Red Hat, Inc. */
 
 struct semanage_bool;
@@ -20,16 +38,18 @@
 record_policydb_table_t SEMANAGE_BOOL_POLICYDB_RTABLE = {
 	.add         = NULL, 
 	.modify      = NULL,
-	.set         = sepol_bool_set,
-	.query       = sepol_bool_query,
-	.count       = sepol_bool_count,
-	.exists      = sepol_bool_exists, 
-	.iterate     = sepol_bool_iterate,
+/* FIXME: these casts depend on stucts in libsepol matching structs
+ * in libsemanage. This is incredibly fragile - the casting gets
+ * rid of warnings, but is not type safe.
+ */
+	.set         = (record_policydb_table_set_t)sepol_bool_set,
+	.query       = (record_policydb_table_query_t)sepol_bool_query,
+	.count       = (record_policydb_table_count_t)sepol_bool_count,
+	.exists      = (record_policydb_table_exists_t)sepol_bool_exists, 
+	.iterate     = (record_policydb_table_iterate_t)sepol_bool_iterate,
 };
 
-int bool_policydb_dbase_init(
-	semanage_handle_t* handle,
-	dbase_config_t* dconfig) {
+int bool_policydb_dbase_init(semanage_handle_t* handle, dbase_config_t* dconfig) {
 
 	if (dbase_policydb_init(
 		handle, 
libsemanage/src/conf-scan.l renamed from test_framework/libsemanage/src/conf-scan.l +0 -1
diff --exclude=.svn -ruN ../test_framework/libsemanage/src/conf-scan.l ./libsemanage/src/conf-scan.l
@@ -18,7 +18,6 @@
  */
 
 %{
-        
 #include "conf-parse.h"
 
 #include <ctype.h>
libsemanage/src/database_policydb.h renamed from test_framework/libsemanage/src/database_policydb.h +47 -44

111 lines not on this page · raw message

libsemanage/src/fcontexts_local.c renamed from test_framework/libsemanage/src/fcontexts_local.c +1 -1
diff --exclude=.svn -ruN ../test_framework/libsemanage/src/fcontexts_local.c ./libsemanage/src/fcontexts_local.c
@@ -102,7 +102,7 @@
 	const char* type_str = semanage_fcontext_get_type_str(type);
 	semanage_context_t* con = semanage_fcontext_get_con(fcon);
 
-	if (con && sepol_context_check(handle->sepolh, policydb, con) < 0)
+	if (con && sepol_context_check(handle->sepolh, policydb, (sepol_context_t*)con) < 0)
 		goto invalid;
 
 	return 0;
libsemanage/src/interfaces_policydb.c renamed from test_framework/libsemanage/src/interfaces_policydb.c +23 -5
diff --exclude=.svn -ruN ../test_framework/libsemanage/src/interfaces_policydb.c ./libsemanage/src/interfaces_policydb.c
@@ -1,3 +1,21 @@
+/*
+ * Copyright (C) 2006 Tresys Technology, LLC
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
 /* Copyright (C) 2005 Red Hat, Inc. */
 
 struct semanage_iface;
@@ -19,12 +37,12 @@
 /* INTERFACE RECRORD (SEPOL): POLICYDB extension: method table */
 record_policydb_table_t SEMANAGE_IFACE_POLICYDB_RTABLE = {
 	.add         = NULL,
-	.modify      = sepol_iface_modify,
+	.modify      = (record_policydb_table_modify_t)sepol_iface_modify,
 	.set         = NULL,
-	.query       = sepol_iface_query,
-        .count       = sepol_iface_count,
-	.exists      = sepol_iface_exists, 
-	.iterate     = sepol_iface_iterate,
+	.query       = (record_policydb_table_query_t)sepol_iface_query,
+        .count       = (record_policydb_table_count_t)sepol_iface_count,
+	.exists      = (record_policydb_table_exists_t)sepol_iface_exists, 
+	.iterate     = (record_policydb_table_iterate_t)sepol_iface_iterate,
 };
 
 int iface_policydb_dbase_init(
libsemanage/src/nodes_policydb.c renamed from test_framework/libsemanage/src/nodes_policydb.c +22 -5
diff --exclude=.svn -ruN ../test_framework/libsemanage/src/nodes_policydb.c ./libsemanage/src/nodes_policydb.c
@@ -1,3 +1,20 @@
+/*
+ * Copyright (C) 2006 Tresys Technology, LLC
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
 /* Copyright (C) 2005 Red Hat, Inc. */
 
 struct semanage_node;
@@ -19,12 +36,12 @@
 /* NODE RECORD (SEPOL): POLICYDB extension : method table */
 record_policydb_table_t SEMANAGE_NODE_POLICYDB_RTABLE = {
 	.add         = NULL, 
-	.modify      = sepol_node_modify,
+	.modify      = (record_policydb_table_modify_t)sepol_node_modify,
 	.set         = NULL, 
-	.query       = sepol_node_query,
-        .count       = sepol_node_count,
-	.exists      = sepol_node_exists,
-	.iterate     = sepol_node_iterate,
+	.query       = (record_policydb_table_query_t)sepol_node_query,
+        .count       = (record_policydb_table_count_t)sepol_node_count,
+	.exists      = (record_policydb_table_exists_t)sepol_node_exists,
+	.iterate     = (record_policydb_table_iterate_t)sepol_node_iterate,
 };
 
 int node_policydb_dbase_init(
libsemanage/src/ports_policydb.c renamed from test_framework/libsemanage/src/ports_policydb.c +22 -5
diff --exclude=.svn -ruN ../test_framework/libsemanage/src/ports_policydb.c ./libsemanage/src/ports_policydb.c
@@ -1,3 +1,20 @@
+/*
+ * Copyright (C) 2006 Tresys Technology, LLC
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
 /* Copyright (C) 2005 Red Hat, Inc. */
 
 struct semanage_port;
@@ -19,12 +36,12 @@
 /* PORT RECORD (SEPOL): POLICYDB extension : method table */
 record_policydb_table_t SEMANAGE_PORT_POLICYDB_RTABLE = {
 	.add         = NULL, 
-	.modify      = sepol_port_modify,
+	.modify      = (record_policydb_table_modify_t)sepol_port_modify,
 	.set         = NULL, 
-	.query       = sepol_port_query,
-        .count       = sepol_port_count,
-	.exists      = sepol_port_exists,
-	.iterate     = sepol_port_iterate,
+	.query       = (record_policydb_table_query_t)sepol_port_query,
+        .count       = (record_policydb_table_count_t)sepol_port_count,
+	.exists      = (record_policydb_table_exists_t)sepol_port_exists,
+	.iterate     = (record_policydb_table_iterate_t)sepol_port_iterate,
 };
 
 int port_policydb_dbase_init(
libsemanage/src/semanage_store.c renamed from test_framework/libsemanage/src/semanage_store.c +5 -5
diff --exclude=.svn -ruN ../test_framework/libsemanage/src/semanage_store.c ./libsemanage/src/semanage_store.c
@@ -1813,15 +1813,15 @@
 /* Replicates strchr, but limits search to buf_len characters. */
 static char *semanage_fc_strnchr(const char *buf, size_t buf_len, char c)
 {
-	size_t index = 0;
+	size_t idx = 0;
 
 	if (buf == NULL) return NULL;
 	if (buf_len <= 0) return NULL;
 
-	while (index < buf_len) {
-		if (buf[index] == c) 
-			return (char *)buf+index;
-		index++;
+	while (idx < buf_len) {
+		if (buf[idx] == c) 
+			return (char *)buf+idx;
+		idx++;
 	}
 
 	return NULL;
libsemanage/src/users_base_policydb.c renamed from test_framework/libsemanage/src/users_base_policydb.c +22 -5
diff --exclude=.svn -ruN ../test_framework/libsemanage/src/users_base_policydb.c ./libsemanage/src/users_base_policydb.c
@@ -1,3 +1,20 @@
+/*
+ * Copyright (C) 2006 Tresys Technology, LLC
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
 /* Copyright (C) 2005 Red Hat, Inc. */
 
 struct semanage_user_base;
@@ -19,12 +36,12 @@
 /* USER BASE record: POLICYDB extension: method table */
 record_policydb_table_t SEMANAGE_USER_BASE_POLICYDB_RTABLE = {
 	.add         = NULL,
-	.modify      = sepol_user_modify,
+	.modify      = (record_policydb_table_modify_t)sepol_user_modify,
 	.set         = NULL,
-	.query       = sepol_user_query, 
-	.count       = sepol_user_count,
-	.exists      = sepol_user_exists,
-	.iterate     = sepol_user_iterate,
+	.query       = (record_policydb_table_query_t)sepol_user_query, 
+	.count       = (record_policydb_table_count_t)sepol_user_count,
+	.exists      = (record_policydb_table_exists_t)sepol_user_exists,
+	.iterate     = (record_policydb_table_iterate_t)sepol_user_iterate,
 };
 
 int user_base_policydb_dbase_init(
libsepol/include/sepol/policydb/policydb.h renamed from test_framework/libsepol/include/sepol/policydb/policydb.h +0 -3
diff --exclude=.svn -ruN ../test_framework/libsepol/include/sepol/policydb/policydb.h ./libsepol/include/sepol/policydb/policydb.h
@@ -510,9 +510,6 @@
                   uint32_t scope, uint32_t avrule_decl_id,
                   uint32_t *value);
 
-extern char *sepol_av_to_string(policydb_t *policydbp, uint32_t tclass, 
-			 sepol_access_vector_t av);
-
 /* A policy "file" may be a memory region referenced by a (data, len) pair
    or a file referenced by a FILE pointer. */
 typedef struct policy_file {
libsepol/include/sepol/policydb/util.h renamed from test_framework/libsepol/include/sepol/policydb/util.h +32 -0
diff --exclude=.svn -ruN ../test_framework/libsepol/include/sepol/policydb/util.h ./libsepol/include/sepol/policydb/util.h
@@ -0,0 +1,32 @@
+/* Authors: Karl MacMillan <[email protected]>
+ *
+ * A set of utility functions that aid policy decision when dealing
+ * with hierarchal namespaces.
+ *
+ * Copyright (C) 2006 Tresys Technology, LLC
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef __SEPOL_UTIL_H__
+#define __SEPOL_UTIL_H__
+
+
+extern int add_i_to_a(uint32_t i, uint32_t *cnt, uint32_t **a);
+
+extern char *sepol_av_to_string(policydb_t *policydbp, uint32_t tclass, 
+			 sepol_access_vector_t av);
+
+#endif
libsepol/src/assertion.c renamed from test_framework/libsepol/src/assertion.c +1 -0
diff --exclude=.svn -ruN ../test_framework/libsepol/src/assertion.c ./libsepol/src/assertion.c
@@ -23,6 +23,7 @@
 #include <sepol/policydb/avtab.h>
 #include <sepol/policydb/policydb.h>
 #include <sepol/policydb/expand.h>
+#include <sepol/policydb/util.h>
 
 #include "debug.h"
 
libsepol/src/debug.h renamed from test_framework/libsepol/src/debug.h +31 -8
diff --exclude=.svn -ruN ../test_framework/libsepol/src/debug.h ./libsepol/src/debug.h
@@ -1,3 +1,21 @@
+/*
+ * Copyright (C) 2006 Tresys Technology, LLC
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
 #ifndef _SEPOL_INTERNAL_DEBUG_H_
 #define _SEPOL_INTERNAL_DEBUG_H_
 
@@ -10,17 +28,22 @@
 #define STATUS_ERR -1
 #define STATUS_NODATA 1
 
+/* FIXME: this needs to become a real function. Declaring variables
+ * in a macro is _evil_ as it can shadow other variables in local scope.
+ * The variable h has been renamed to _sepol_h to reduce this chance, but
+ * it is still wrong.
+ */
 #define msg_write(handle_arg, level_arg,			   \
 		  channel_arg, func_arg, ...) do {		   \
-		sepol_handle_t *h = (handle_arg) ?: &sepol_compat_handle; \
-		if (h->msg_callback) {				   \
-			h->msg_fname = func_arg;		   \
-			h->msg_channel = channel_arg;		   \
-			h->msg_level = level_arg;		   \
+		sepol_handle_t *_sepol_h = (handle_arg) ?: &sepol_compat_handle; \
+		if (_sepol_h->msg_callback) {			   \
+			_sepol_h->msg_fname = func_arg;		   \
+			_sepol_h->msg_channel = channel_arg;	   \
+			_sepol_h->msg_level = level_arg;	   \
 								   \
-			h->msg_callback(			   \
-				h->msg_callback_arg,		   \
-				h, __VA_ARGS__);		   \
+			_sepol_h->msg_callback(			   \
+				_sepol_h->msg_callback_arg,	   \
+				_sepol_h, __VA_ARGS__);		   \
 		}                                                  \
 	} while(0)
 
libsepol/src/policydb.c renamed from test_framework/libsepol/src/policydb.c +180 -0

192 lines not on this page · raw message

libsepol/src/util.c renamed from test_framework/libsepol/src/util.c +2 -184

204 lines not on this page · raw message

policycoreutils/semodule_expand/semodule_expand.c renamed from test_framework/policycoreutils/semodule_expand/semodule_expand.c +8 -3
diff --exclude=.svn -ruN ../test_framework/policycoreutils/semodule_expand/semodule_expand.c ./policycoreutils/semodule_expand/semodule_expand.c
@@ -30,7 +30,7 @@
 
 static void usage(char *program_name)
 {
-        printf("usage: %s [-V -c [version]] basemodpkg outputfile\n", program_name);
+        printf("usage: %s [-V -a -c [version]] basemodpkg outputfile\n", program_name);
         exit(1);
 }
 
@@ -42,8 +42,9 @@
 	sepol_module_package_t *base;
 	sepol_policydb_t *out, *p;
 	FILE *fp, *outfile;
+	int check_assertions = 1;
 
-	while ((ch = getopt(argc, argv, "c:Vv")) != EOF) {
+	while ((ch = getopt(argc, argv, "c:Vva")) != EOF) {
                 switch (ch) {
                 case 'V':
                         show_version = 1;
@@ -67,6 +68,10 @@
 			policyvers = n;
 			break;
 		}
+		case 'a': {
+			check_assertions = 0;
+			break;
+		}
 		default:
 			usage(argv[0]);
 		}
@@ -130,7 +135,7 @@
                 exit(1);
         }
 
-        if (sepol_expand_module(NULL, p, out, verbose, 1)) {
+        if (sepol_expand_module(NULL, p, out, verbose, check_assertions)) {
         	fprintf(stderr, "%s:  Error while expanding policy\n", argv[0]);
         	exit(1);
         }
policycoreutils/semodule_package/semodule_package.c renamed from test_framework/policycoreutils/semodule_package/semodule_package.c +2 -2
diff --exclude=.svn -ruN ../test_framework/policycoreutils/semodule_package/semodule_package.c ./policycoreutils/semodule_package/semodule_package.c
@@ -22,9 +22,9 @@
 char *progname = NULL;
 extern char *optarg;
 
-static void usage(char *progname)
+static void usage(char *prog)
 {
-	printf("usage: %s -o <output file> -m <module> [-f <file contexts>]\n", progname);
+	printf("usage: %s -o <output file> -m <module> [-f <file contexts>]\n", prog);
         printf("Options:\n");
         printf("  -o --outfile		Output file (required)\n");
         printf("  -m --module		Module file (required)\n");
policycoreutils/setsebool/setsebool.c renamed from test_framework/policycoreutils/setsebool/setsebool.c +4 -4
diff --exclude=.svn -ruN ../test_framework/policycoreutils/setsebool/setsebool.c ./policycoreutils/setsebool/setsebool.c
@@ -78,9 +78,9 @@
 static int selinux_set_boolean_list(
 	size_t boolcnt, 
 	SELboolean *boollist, 
-	int permanent) {
+	int perm) {
 
-	if (security_set_boolean_list(boolcnt, boollist, permanent)) {
+	if (security_set_boolean_list(boolcnt, boollist, perm)) {
 		if (errno == ENOENT)
 			fprintf(stderr, "Could not change active booleans: "
 				"Invalid boolean\n");
@@ -97,7 +97,7 @@
 static int semanage_set_boolean_list(
 	size_t boolcnt, 
 	SELboolean *boollist,
-	int permanent) {
+	int perm) {
 
 	size_t j;
 	semanage_handle_t* handle = NULL;
@@ -141,7 +141,7 @@
 		if (semanage_bool_key_extract(handle, boolean, &bool_key) < 0)
 			goto err;
 
-		if (permanent && semanage_bool_modify_local(handle, bool_key, boolean) < 0)
+		if (perm && semanage_bool_modify_local(handle, bool_key, boolean) < 0)
 			goto err;
 
 		if (semanage_bool_set_active(handle, bool_key, boolean) < 0) {
#1 lore raw
Quoted 6 lines · Karl MacMillan

Steve,

Attached is a patch that fixes many warnings that have crept into the selinux-usr code over time, making it difficult to ascertain whether code changes have introduced new warnings.

record_policydb_table_t SEMANAGE_PORT_POLICYDB_RTABLE = {

.add = NULL,
- .modify = sepol_port_modify,
+ .modify = (record_policydb_table_modify_t)sepol_port_modify,
.set = NULL,
- .query = sepol_port_query,
- .count = sepol_port_count,

-	.exists      = sepol_port_exists,
-	.iterate     = sepol_port_iterate,
+	.query       = (record_policydb_table_query_t)sepol_port_query,

+ .count = (record_policydb_table_count_t)sepol_port_count,
+ .exists = (record_policydb_table_exists_t)sepol_port_exists,
+ .iterate = (record_policydb_table_iterate_t)sepol_port_iterate,
};

The semanage <--> sepol record key/data are not necessarily identical, and that's why warnings occur on query, modify, etc... Changing the type to void* removes the warning, without fixing the potential problem. The cast is marked unsafe, because it is unsafe. A better solution would be to add conversion functions from semanage key/record to sepol key/record and vice versa.

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#2 lore raw
Quoted 24 lines · Ivan Gyurdiev
Quoted 6 lines · Karl MacMillan

Steve,

Attached is a patch that fixes many warnings that have crept into the selinux-usr code over time, making it difficult to ascertain whether code changes have introduced new warnings.

record_policydb_table_t SEMANAGE_PORT_POLICYDB_RTABLE = {

libsemanage/src/ports_policydb.c renamed from test_framework/libsemanage/src/ports_policydb.c +5 -5
 	.add         = NULL, 
-	.modify      = sepol_port_modify,
+	.modify      = (record_policydb_table_modify_t)sepol_port_modify,
 	.set         = NULL, 
-	.query       = sepol_port_query,
-        .count       = sepol_port_count,
-	.exists      = sepol_port_exists,
-	.iterate     = sepol_port_iterate,
+	.query       = (record_policydb_table_query_t)sepol_port_query,
+        .count       = (record_policydb_table_count_t)sepol_port_count,
+	.exists      = (record_policydb_table_exists_t)sepol_port_exists,
+	.iterate     = (record_policydb_table_iterate_t)sepol_port_iterate,
 };
Quoted 4 lines

The semanage <--> sepol record key/data are not necessarily identical, and that's why warnings occur on query, modify, etc... Changing the type to void* removes the warning, without fixing the potential problem. The cast is marked unsafe, because it is unsafe.

Not certain if you are objecting to adding the casts or would prefer a void* cast. I prefer the casts as the patch has them because it makes it clear in the source that something unsafe is being done without completely punting with void*.

Quoted 3 lines

A
better solution would be to add conversion functions from semanage key/record to sepol key/record and vice versa.

Sure, conversions would solve the problem, though removing some of this duplication would be even better. Any chance you will have a chance to take care of this?

Thanks,

Karl

Signature · 8 lines
Karl MacMillan
Tresys Technology
www.tresys.com

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#3 lore raw
Quoted 4 lines · Karl MacMillan

Sure, conversions would solve the problem, though removing some of this duplication would be even better. Any chance you will have a chance to take care of this?

I've stopped working on these things for the moment...
How are you suggesting we should get rid of the duplication - use sepol structures directly?

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#4 lore raw
Quoted 6 lines · Ivan Gyurdiev
Quoted 4 lines · Karl MacMillan

Sure, conversions would solve the problem, though removing some of this duplication would be even better. Any chance you will have a chance to take care of this?

I've stopped working on these things for the moment...

That's too bad.

Quoted 2 lines

How are you suggesting we should get rid of the duplication - use sepol structures directly?

Potentially or investigate whether the presence of the same APIs in both places exposes some deeper issues.

Karl

Signature · 8 lines
Karl MacMillan
Tresys Technology
www.tresys.com

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#5 lore raw
In reply to Karl MacMillan
Quoted 6 lines · Karl MacMillan

Steve,

Attached is a patch that fixes many warnings that have crept into the selinux-usr code over time, making it difficult to ascertain whether code changes have introduced new warnings.

Quoted 8 lines

Fixing some of the warnings required the introduction of unsafe casts, but those casts were occurring implicitly anyway (see libsemanage/src/booleans_policydb.c for an example).

I fixed one of the long standing lex warnings that has always been irritating, but I was unable to fix the warnings in the semanage configuration file parser. That parser should not rewritten to remove the lex dependency in the future anyway.

Merged, although some of the changes seemed unnecessary to me (e.g. it is ok to name a variable 'index', and the compiler will let you know if you then try to use it as a function in the same scope), and leaving the libsemanage warnings was intentional by Ivan to flag the fact that we are making an assumption about the equivalence between the libsemanage and libsepol structs. The patch also included some changes that appeared to be unrelated to fixing warnings, like moving code from util.c to policydb.c and upgrading the scope of role/user statements from SCOPE_REQ to SCOPE_DECL automatically, and adding the -a option to semodule_expand.

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#6 lore raw
Quoted 11 lines · Stephen Smalley
Quoted 10 lines · Karl MacMillan

Steve,

Attached is a patch that fixes many warnings that have crept into the selinux-usr code over time, making it difficult to ascertain whether code changes have introduced new warnings.

Fixing some of the warnings required the introduction of unsafe casts, but those casts were occurring implicitly anyway (see libsemanage/src/booleans_policydb.c for an example).

Quoted 8 lines
Quoted 4 lines

I fixed one of the long standing lex warnings that has always been irritating, but I was unable to fix the warnings in the semanage configuration file parser. That parser should not rewritten to remove the lex dependency in the future anyway.

Merged, although some of the changes seemed unnecessary to me (e.g. it is ok to name a variable 'index', and the compiler will let you know if you then try to use it as a function in the same scope),

Sure, but my goal was simply to get rid or warnings. For me, constant warnings makes it much harder to scan the compiler output for problems.

Quoted 4 lines

and leaving the
libsemanage warnings was intentional by Ivan to flag the fact that we are making an assumption about the equivalence between the libsemanage and libsepol structs.

Again, I wanted to suppress these warnings. Additionally, I think that it makes it clearer in the code that something bad is going on.

Quoted 3 lines

The patch also included some changes that
appeared to be unrelated to fixing warnings, like moving code from util.c to policydb.c

I should have tagged this as an additional change. Those functions were already prototyped in policydb.h and were not really "utility" functions. I noticed the problem when fixing a warning so I went ahead and made the change.

Quoted 2 lines

and upgrading the scope of role/user statements
from SCOPE_REQ to SCOPE_DECL automatically,

Hmm . . . this must have been in the local copy I started from. Josh, is this change correct?

Quoted 3 lines

and adding the -a option to
semodule_expand.

Again, should have tagged this. I added this while doing some debugging and forgot about it.

Karl

Signature · 8 lines
Karl MacMillan
Tresys Technology
www.tresys.com

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#7 lore raw
Quoted 41 lines · Karl MacMillan
Quoted 11 lines · Stephen Smalley
Quoted 10 lines · Karl MacMillan

Steve,

Attached is a patch that fixes many warnings that have crept into the selinux-usr code over time, making it difficult to ascertain whether code changes have introduced new warnings.

Fixing some of the warnings required the introduction of unsafe casts, but those casts were occurring implicitly anyway (see libsemanage/src/booleans_policydb.c for an example).

Quoted 8 lines
Quoted 4 lines

I fixed one of the long standing lex warnings that has always been irritating, but I was unable to fix the warnings in the semanage configuration file parser. That parser should not rewritten to remove the lex dependency in the future anyway.

Merged, although some of the changes seemed unnecessary to me (e.g. it is ok to name a variable 'index', and the compiler will let you know if you then try to use it as a function in the same scope),

Sure, but my goal was simply to get rid or warnings. For me, constant warnings makes it much harder to scan the compiler output for problems.

Quoted 4 lines

and leaving the
libsemanage warnings was intentional by Ivan to flag the fact that we are making an assumption about the equivalence between the libsemanage and libsepol structs.

Again, I wanted to suppress these warnings. Additionally, I think that it makes it clearer in the code that something bad is going on.

Quoted 3 lines

The patch also included some changes that
appeared to be unrelated to fixing warnings, like moving code from util.c to policydb.c

I should have tagged this as an additional change. Those functions were already prototyped in policydb.h and were not really "utility" functions. I noticed the problem when fixing a warning so I went ahead and made the change.

Quoted 6 lines
Quoted 2 lines

and upgrading the scope of role/user statements
from SCOPE_REQ to SCOPE_DECL automatically,

Hmm . . . this must have been in the local copy I started from. Josh, is this change correct?

Looks like I cut-and-paste from the wrong window. Attached is a patch to revert this change until we have had a chance to test it for side-effects.

Karl

Signature · 3 lines
Karl MacMillan
Tresys Technology
www.tresys.com
Quoted 9 lines
Quoted 3 lines

and adding the -a option to
semodule_expand.

Again, should have tagged this. I added this while doing some debugging and forgot about it.

Karl

libsepol/src/policydb.c renamed from ../trunk/libsepol/src/policydb.c +1 -1
diff --exclude=.svn -pruN ../../trunk/libsepol/src/policydb.c ./libsepol/src/policydb.c
@@ -1118,7 +1118,7 @@ int symtab_insert(policydb_t *pol, uint3
                 if (sym != SYM_ROLES && sym != SYM_USERS) {
                         return -2;
                 }
-               	scope_datum->scope = SCOPE_DECL; 
+                
         }
         else if (scope_datum->scope != scope) {
                 /* scope does not match */
#8 lore raw
Quoted 3 lines · Karl MacMillan

Looks like I cut-and-paste from the wrong window. Attached is a patch to revert this change until we have had a chance to test it for side-effects.

Ok, reverted. Note that we originally resolved this problem by changing checkpolicy to move role/user requires processing to the 2nd pass.

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.