Received: from jazzband.ncsc.mil (jazzband.ncsc.mil [144.51.5.4]) by tycho.ncsc.mil (8.12.8/8.12.8) with ESMTP id h9MJ29Wt005335 for ; Wed, 22 Oct 2003 15:02:09 -0400 (EDT) Received: from jazzband.ncsc.mil (localhost [127.0.0.1]) by jazzband.ncsc.mil with ESMTP id h9MJ28IE004678 for ; Wed, 22 Oct 2003 19:02:08 GMT Received: from a141.shuttle.de (home.nightdaughter.de [194.95.224.141]) by jazzband.ncsc.mil with ESMTP id h9MJ261J004673 for ; Wed, 22 Oct 2003 19:02:07 GMT Date: Wed, 22 Oct 2003 21:02:41 +0200 From: Joerg Hoh To: Stephen Smalley Cc: selinux@tycho.nsa.gov, James Morris Subject: Re: [PATCH] checkpolicy/policy_scan.y Message-ID: <20031022190241.GA4671@hydra.joerghoh.de> References: <20031022175608.GB4531@hydra.joerghoh.de> <1066847603.32228.76.camel@moss-spartans.epoch.ncsc.mil> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="/9DWx/yDrRhgMJTb" In-Reply-To: <1066847603.32228.76.camel@moss-spartans.epoch.ncsc.mil> Sender: owner-selinux@tycho.nsa.gov List-Id: selinux@tycho.nsa.gov --/9DWx/yDrRhgMJTb Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Oct 22, 2003 at 02:33:23PM -0400, Stephen Smalley wrote: > On Wed, 2003-10-22 at 13:56, Joerg Hoh wrote: > > The following patch fixes some warnings in policy_parse.y (add -W to the > > CFLAGS to display this warnings): > > - You forgot to use diff -u to generate your patch. The unified patch is attached, sorry about that. > - As is noted in the gcc man page, some of the warnings generated by -W > options not implied by -Wall are constructions that users generally do > not consider questionable. They might indicate a problem, but we > shouldn't just blindly stamp them out. policy_parse.y:1666: warning: comparison between signed and unsigned IMHO this is a warning we should fix (because it is easy to fix). Sure, a warning is no error, but no warning is better than a warning that is suppressed by the compiler. > - Casting -1 to an unsigned type is an ugly construct, IMHO. I much > prefer ~0, as that clearly indicates the intent. If we need to > explicitly cast it to (access_vector_t) or add a UL suffix, then that is > fine, but I don't see it as an improvement to replace it with -1. ~0 is not clearly to me :-| Ok, I'll try to extract some coding conventions from your last mails. Joerg --/9DWx/yDrRhgMJTb Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=policy_parse --- ../../upstream/current/checkpolicy/policy_parse.y 2003-10-19 19:29:30.000000000 +0200 +++ policy_parse.y 2003-10-20 21:01:39.000000000 +0200 @@ -10,6 +10,7 @@ #include "services.h" #include "queue.h" #include "checkpolicy.h" +#include #define TRUE 1 #define FALSE 0 @@ -48,25 +49,25 @@ static int define_role_trans(void); static int define_role_allow(void); static int define_constraint(constraint_expr_t *expr); -static constraint_expr_t *define_cexpr(__u32 expr_type, void *arg1, void* arg2); +static uintptr_t define_cexpr(__u32 expr_type, uintptr_t arg1, uintptr_t arg2); static int define_user(void); static int parse_security_context(context_struct_t *c); static int define_initial_sid_context(void); static int define_fs_use(int behavior); static int define_genfs_context(int has_type); -static int define_fs_context(int major, int minor); -static int define_port_context(int low, int high); +static int define_fs_context(uintptr_t major, uintptr_t minor); +static int define_port_context(uintptr_t low, uintptr_t high); static int define_netif_context(void); -static int define_node_context(int addr, int mask); +static int define_node_context(uintptr_t addr, uintptr_t mask); %} %union { - int val; + uintptr_t val; void *ptr; } -%type role_def roles cexpr cexpr_prim op roleop -%type ipv4_addr_def number +%type role_def roles +%type ipv4_addr_def number cexpr cexpr_prim op roleop %token PATH %token CLONE @@ -322,64 +323,64 @@ { $$ = $1; } ; cexpr_prim : U1 op U2 - { $$ = define_cexpr(CEXPR_ATTR, (void*)CEXPR_USER, $2); + { $$ = define_cexpr(CEXPR_ATTR, CEXPR_USER, $2); if ($$ == 0) return -1; } | R1 roleop R2 - { $$ = define_cexpr(CEXPR_ATTR, (void*)CEXPR_ROLE, $2); + { $$ = define_cexpr(CEXPR_ATTR, CEXPR_ROLE, $2); if ($$ == 0) return -1; } | T1 op T2 - { $$ = define_cexpr(CEXPR_ATTR, (void*)CEXPR_TYPE, $2); + { $$ = define_cexpr(CEXPR_ATTR, CEXPR_TYPE, $2); if ($$ == 0) return -1; } | U1 op { if (insert_separator(1)) return -1; } user_names_push - { $$ = define_cexpr(CEXPR_NAMES, (void*)CEXPR_USER, $2); + { $$ = define_cexpr(CEXPR_NAMES, CEXPR_USER, $2); if ($$ == 0) return -1; } | U2 op { if (insert_separator(1)) return -1; } user_names_push - { $$ = define_cexpr(CEXPR_NAMES, (void*)(CEXPR_USER | CEXPR_TARGET), $2); + { $$ = define_cexpr(CEXPR_NAMES, (CEXPR_USER | CEXPR_TARGET), $2); if ($$ == 0) return -1; } | R1 op { if (insert_separator(1)) return -1; } names_push - { $$ = define_cexpr(CEXPR_NAMES, (void*)CEXPR_ROLE, $2); + { $$ = define_cexpr(CEXPR_NAMES, CEXPR_ROLE, $2); if ($$ == 0) return -1; } | R2 op { if (insert_separator(1)) return -1; } names_push - { $$ = define_cexpr(CEXPR_NAMES, (void*)(CEXPR_ROLE | CEXPR_TARGET), $2); + { $$ = define_cexpr(CEXPR_NAMES, (CEXPR_ROLE | CEXPR_TARGET), $2); if ($$ == 0) return -1; } | T1 op { if (insert_separator(1)) return -1; } names_push - { $$ = define_cexpr(CEXPR_NAMES, (void*)CEXPR_TYPE, $2); + { $$ = define_cexpr(CEXPR_NAMES, CEXPR_TYPE, $2); if ($$ == 0) return -1; } | T2 op { if (insert_separator(1)) return -1; } names_push - { $$ = define_cexpr(CEXPR_NAMES, (void*)(CEXPR_TYPE | CEXPR_TARGET), $2); + { $$ = define_cexpr(CEXPR_NAMES, (CEXPR_TYPE | CEXPR_TARGET), $2); if ($$ == 0) return -1; } | SAMEUSER - { $$ = define_cexpr(CEXPR_ATTR, (void*)CEXPR_USER, (void*)CEXPR_EQ); + { $$ = define_cexpr(CEXPR_ATTR, CEXPR_USER, CEXPR_EQ); if ($$ == 0) return -1; } | SOURCE ROLE { if (insert_separator(1)) return -1; } names_push - { $$ = define_cexpr(CEXPR_NAMES, (void*)CEXPR_ROLE, (void*)CEXPR_EQ); + { $$ = define_cexpr(CEXPR_NAMES, CEXPR_ROLE, CEXPR_EQ); if ($$ == 0) return -1; } | TARGET ROLE { if (insert_separator(1)) return -1; } names_push - { $$ = define_cexpr(CEXPR_NAMES, (void*)(CEXPR_ROLE | CEXPR_TARGET), (void*)CEXPR_EQ); + { $$ = define_cexpr(CEXPR_NAMES, (CEXPR_ROLE | CEXPR_TARGET), CEXPR_EQ); if ($$ == 0) return -1; } | ROLE roleop - { $$ = define_cexpr(CEXPR_ATTR, (void*)CEXPR_ROLE, (void*)$2); + { $$ = define_cexpr(CEXPR_ATTR, CEXPR_ROLE, $2); if ($$ == 0) return -1; } | SOURCE TYPE { if (insert_separator(1)) return -1; } names_push - { $$ = define_cexpr(CEXPR_NAMES, (void*)CEXPR_TYPE, (void*)CEXPR_EQ); + { $$ = define_cexpr(CEXPR_NAMES, CEXPR_TYPE, CEXPR_EQ); if ($$ == 0) return -1; } | TARGET TYPE { if (insert_separator(1)) return -1; } names_push - { $$ = define_cexpr(CEXPR_NAMES, (void*)(CEXPR_TYPE | CEXPR_TARGET), (void*)CEXPR_EQ); + { $$ = define_cexpr(CEXPR_NAMES, (CEXPR_TYPE | CEXPR_TARGET), CEXPR_EQ); if ($$ == 0) return -1; } ; op : EQUALS - { $$ = (void*)CEXPR_EQ; } + { $$ = CEXPR_EQ; } | NOTEQUAL - { $$ = (void*)CEXPR_NEQ; } + { $$ = CEXPR_NEQ; } ; roleop : op { $$ = $1; } | DOM - { $$ = (void*)CEXPR_DOM; } + { $$ = CEXPR_DOM; } | DOMBY - { $$ = (void*)CEXPR_DOMBY; } + { $$ = CEXPR_DOMBY; } | INCOMP - { $$ = (void*)CEXPR_INCOMP; } + { $$ = CEXPR_INCOMP; } ; users : user_def | users user_def @@ -1659,7 +1660,7 @@ char *id) { type_datum_t *t; - int i; + unsigned int i; if (strcmp(id, "*") == 0) { /* set all types */ @@ -1715,7 +1716,8 @@ class_datum_t *cladatum; ebitmap_t stypes, ttypes, tclasses; __u32 newtype = 0; - int ret, i, j, k; + int ret; + unsigned int i, j, k; if (pass == 1) { while ((id = queue_remove(id_queue))) @@ -1864,7 +1866,8 @@ static char avbuf[1024]; class_datum_t *cladatum; char *perm = NULL, *p; - int i, rc; + unsigned int i; + int rc; cladatum = policydbp->class_val_to_struct[tclass-1]; p = avbuf; @@ -1891,13 +1894,14 @@ } -static int te_avtab_helper(int which, int stype, int ttype, +static int te_avtab_helper(int which, unsigned int stype, unsigned int ttype, ebitmap_t *tclasses, access_vector_t *avp) { avtab_key_t avkey; avtab_datum_t avdatum, *avdatump; - int ret, k; + int ret; + unsigned int k; if (which == -AVTAB_ALLOWED) { yyerror("neverallow should not reach this function."); @@ -1958,7 +1962,8 @@ perm_datum_t *perdatum; ebitmap_t stypes, ttypes, tclasses; access_vector_t *avp; - int i, j, hiclass, self = 0; + unsigned int i, j, hiclass; + int self = 0; te_assert_t *newassert; if (pass == 1) { @@ -2021,7 +2026,7 @@ if (strcmp(id, "*") == 0) { /* set all permissions in the class */ - avp[i] = ~0; + avp[i] = (access_vector_t) -1; continue; } @@ -2219,7 +2224,8 @@ { role_datum_t *role; char *role_id; - int i, ret; + unsigned int i; + int ret; if (pass == 1) { role_id = queue_remove(id_queue); @@ -2274,7 +2280,7 @@ char *id) { role_datum_t *r; - int i; + unsigned int i; if (strcmp(id, "*") == 0) { /* set all roles */ @@ -2317,7 +2323,7 @@ role_datum_t *role; ebitmap_t roles, types; struct role_trans *tr = 0; - int i, j; + unsigned int i, j; if (pass == 1) { while ((id = queue_remove(id_queue))) @@ -2398,7 +2404,7 @@ char *id; ebitmap_t roles, new_roles; struct role_allow *ra = 0; - int i, j; + unsigned int i, j; if (pass == 1) { while ((id = queue_remove(id_queue))) @@ -2462,7 +2468,8 @@ perm_datum_t *perdatum; ebitmap_t classmap; constraint_expr_t *e; - int i, depth; + unsigned int i; + int depth; if (pass == 1) { while ((id = queue_remove(id_queue))) @@ -2572,8 +2579,8 @@ } -static constraint_expr_t * - define_cexpr(__u32 expr_type, void* arg1, void* arg2) +static uintptr_t + define_cexpr(__u32 expr_type, uintptr_t arg1, uintptr_t arg2) { struct constraint_expr *expr, *e1 = NULL, *e2; user_datum_t *user; @@ -2586,13 +2593,13 @@ while ((id = queue_remove(id_queue))) free(id); } - return (constraint_expr_t *)1; /* any non-NULL value */ + return 1; /* any non-NULL value */ } expr = malloc(sizeof(struct constraint_expr)); if (!expr) { yyerror("out of memory"); - return NULL; + return 0; } memset(expr, 0, sizeof(constraint_expr_t)); expr->expr_type = expr_type; @@ -2608,10 +2615,10 @@ if (!e1 || e1->next) { yyerror("illegal constraint expression"); free(expr); - return NULL; + return 0; } e1->next = expr; - return (struct constraint_expr *) arg1; + return arg1; case CEXPR_AND: case CEXPR_OR: e1 = NULL; @@ -2623,7 +2630,7 @@ if (!e1 || e1->next) { yyerror("illegal constraint expression"); free(expr); - return NULL; + return 0; } e1->next = (struct constraint_expr *) arg2; @@ -2636,17 +2643,17 @@ if (!e1 || e1->next) { yyerror("illegal constraint expression"); free(expr); - return NULL; + return 0; } e1->next = expr; - return (struct constraint_expr *) arg1; + return arg1; case CEXPR_ATTR: - expr->attr = (__u32)arg1; - expr->op = (__u32)arg2; - return expr; + expr->attr = arg1; + expr->op = arg2; + return (uintptr_t) expr; case CEXPR_NAMES: - expr->attr = (__u32)arg1; - expr->op = (__u32)arg2; + expr->attr = arg1; + expr->op = arg2; while ((id = (char *) queue_remove(id_queue))) { if (expr->attr & CEXPR_USER) { user = (user_datum_t *) hashtab_search(policydbp->p_users.table, @@ -2655,7 +2662,7 @@ sprintf(errormsg, "unknown user %s", id); yyerror(errormsg); free(expr); - return NULL; + return 0; } val = user->value; } else if (expr->attr & CEXPR_ROLE) { @@ -2665,38 +2672,38 @@ sprintf(errormsg, "unknown role %s", id); yyerror(errormsg); free(expr); - return NULL; + return 0; } val = role->value; } else if (expr->attr & CEXPR_TYPE) { if (set_types(&expr->names, id)) { free(expr); - return NULL; + return 0; } continue; } else { yyerror("invalid constraint expression"); free(expr); - return NULL; + return 0; } if (ebitmap_set_bit(&expr->names, val - 1, TRUE)) { yyerror("out of memory"); ebitmap_destroy(&expr->names); free(expr); - return NULL; + return 0; } free(id); } - return expr; + return (uintptr_t) expr; default: yyerror("invalid constraint expression"); free(expr); - return NULL; + return 0; } yyerror("invalid constraint expression"); free(expr); - return NULL; + return 0; } @@ -2704,7 +2711,7 @@ char *id) { role_datum_t *r; - int i; + unsigned int i; if (strcmp(id, "*") == 0) { /* set all roles */ @@ -3137,7 +3144,7 @@ return 0; } -static int define_fs_context(int major, int minor) +static int define_fs_context(uintptr_t major, uintptr_t minor) { ocontext_t *newc, *c, *head; @@ -3154,13 +3161,14 @@ } memset(newc, 0, sizeof(ocontext_t)); - newc->u.name = (char *) malloc(6); + newc->u.name = malloc((size_t) 6); if (!newc->u.name) { yyerror("out of memory"); free(newc); return -1; } - sprintf(newc->u.name, "%02x:%02x", major, minor); + sprintf(newc->u.name, "%02lx:%02lx", (unsigned long) major, + (unsigned long)minor); if (parse_security_context(&newc->context[0])) { free(newc->u.name); @@ -3193,7 +3201,7 @@ return 0; } -static int define_port_context(int low, int high) +static int define_port_context(uintptr_t low, uintptr_t high) { ocontext_t *newc; char *id; @@ -3292,7 +3300,7 @@ return 0; } -static int define_node_context(int addr, int mask) +static int define_node_context(uintptr_t addr, uintptr_t mask) { ocontext_t *newc, *c, *l, *head; --/9DWx/yDrRhgMJTb-- -- This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with the words "unsubscribe selinux" without quotes as the message.