mirror of
https://github.com/SELinuxProject/setools
synced 2025-03-11 07:18:15 +00:00
Cast the 2nd parameter of hashtab_search to hashtab_key_t
"gcc -Wwrite-strings" reported warnings when using hashtab_search (from libsepol) with string literals as its second parameter is a non-constant string. Indeed /usr/include/sepol/policydb/hashtab.h contains: typedef char *hashtab_key_t; /* ... */ extern hashtab_datum_t hashtab_search(hashtab_t h, const hashtab_key_t k); This means the second parameter is "char *const k", not "const char *k". As a consequence: * Casting to "const hashtab_key_t" leads to misunderstanding the code. * "const char*" variables need to be explicitly casted to "char*" or "hashtab_key_t" before calling hashtab_search. * When using "gcc -Wwrite-strings", literal strings need to be casted to "char*" or "hashtab_key_t" before calling hashtab_search. * "gcc -Wcast-qual" reports an awful amount of warnings due to const-to-nonconst pointer casts. Add missing casts to hashtab_key_t to help finding real bugs in setools/libqpol with gcc flags.
This commit is contained in:
parent
2b380727e0
commit
2994d1ca1d
@ -48,7 +48,7 @@ int qpol_policy_get_bool_by_name(const qpol_policy_t * policy, const char *name,
|
||||
}
|
||||
|
||||
db = &policy->p->p;
|
||||
internal_datum = hashtab_search(db->p_bools.table, (const hashtab_key_t)name);
|
||||
internal_datum = hashtab_search(db->p_bools.table, (hashtab_key_t)name);
|
||||
if (internal_datum == NULL) {
|
||||
ERR(policy, "could not find datum for bool %s", name);
|
||||
*datum = NULL;
|
||||
|
@ -376,7 +376,7 @@ int qpol_policy_get_class_by_name(const qpol_policy_t * policy, const char *name
|
||||
}
|
||||
|
||||
db = &policy->p->p;
|
||||
internal_datum = hashtab_search(db->p_classes.table, (const hashtab_key_t)name);
|
||||
internal_datum = hashtab_search(db->p_classes.table, (hashtab_key_t)name);
|
||||
if (internal_datum == NULL) {
|
||||
*obj_class = NULL;
|
||||
ERR(policy, "could not find class %s", name);
|
||||
@ -541,7 +541,7 @@ int qpol_policy_get_common_by_name(const qpol_policy_t * policy, const char *nam
|
||||
}
|
||||
|
||||
db = &policy->p->p;
|
||||
internal_datum = hashtab_search(db->p_commons.table, (const hashtab_key_t)name);
|
||||
internal_datum = hashtab_search(db->p_commons.table, (hashtab_key_t)name);
|
||||
if (internal_datum == NULL) {
|
||||
*common = NULL;
|
||||
ERR(policy, "could not find common %s", name);
|
||||
|
@ -47,7 +47,7 @@ int qpol_policy_get_level_by_name(const qpol_policy_t * policy, const char *name
|
||||
return STATUS_ERR;
|
||||
}
|
||||
db = &policy->p->p;
|
||||
internal_datum = hashtab_search(db->p_levels.table, (const hashtab_key_t)name);
|
||||
internal_datum = hashtab_search(db->p_levels.table, (hashtab_key_t)name);
|
||||
if (internal_datum == NULL) {
|
||||
ERR(policy, "could not find datum for level %s", name);
|
||||
errno = ENOENT;
|
||||
@ -335,7 +335,7 @@ int qpol_policy_get_cat_by_name(const qpol_policy_t * policy, const char *name,
|
||||
}
|
||||
|
||||
db = &policy->p->p;
|
||||
internal_datum = hashtab_search(db->p_cats.table, (const hashtab_key_t)name);
|
||||
internal_datum = hashtab_search(db->p_cats.table, (hashtab_key_t)name);
|
||||
if (internal_datum == NULL) {
|
||||
*datum = NULL;
|
||||
ERR(policy, "could not find datum for cat %s", name);
|
||||
|
@ -1257,7 +1257,7 @@ int is_id_in_scope(uint32_t symbol_type, hashtab_key_t id)
|
||||
{
|
||||
scope_datum_t *scope =
|
||||
(scope_datum_t *) hashtab_search(policydbp->scope[symbol_type].
|
||||
table, id);
|
||||
table, (hashtab_key_t)id);
|
||||
if (scope == NULL) {
|
||||
return 1; /* id is not known, so return success */
|
||||
}
|
||||
@ -1304,13 +1304,13 @@ int is_perm_in_scope(hashtab_key_t perm_id, hashtab_key_t class_id)
|
||||
{
|
||||
class_datum_t *cladatum =
|
||||
(class_datum_t *) hashtab_search(policydbp->p_classes.table,
|
||||
class_id);
|
||||
(hashtab_key_t)class_id);
|
||||
perm_datum_t *perdatum;
|
||||
if (cladatum == NULL) {
|
||||
return 1;
|
||||
}
|
||||
perdatum = (perm_datum_t *) hashtab_search(cladatum->permissions.table,
|
||||
perm_id);
|
||||
(hashtab_key_t)perm_id);
|
||||
if (perdatum == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
@ -503,7 +503,7 @@ static int infer_policy_version(qpol_policy_t * policy)
|
||||
}
|
||||
|
||||
/* 18 : the netlink_audit_socket class added */
|
||||
else if (hashtab_search(db->p_classes.table, (const hashtab_key_t)"netlink_audit_socket")) {
|
||||
else if (hashtab_search(db->p_classes.table, (hashtab_key_t)"netlink_audit_socket")) {
|
||||
db->policyvers = 18;
|
||||
}
|
||||
|
||||
@ -664,7 +664,7 @@ static int union_multiply_declared_symbols(qpol_policy_t * policy) {
|
||||
avrule_decl_t *decl = blk->enabled;
|
||||
if (!decl)
|
||||
continue; /* disabled */
|
||||
type_datum_t *internal_datum = hashtab_search(decl->symtab[SYM_TYPES].table, (const hashtab_key_t)name);
|
||||
type_datum_t *internal_datum = hashtab_search(decl->symtab[SYM_TYPES].table, (hashtab_key_t)name);
|
||||
if (internal_datum == NULL) {
|
||||
continue; /* not declared here */
|
||||
}
|
||||
@ -695,7 +695,7 @@ static int union_multiply_declared_symbols(qpol_policy_t * policy) {
|
||||
goto err;
|
||||
}
|
||||
policydb_t *db = &policy->p->p;
|
||||
scope_datum_t* scope_datum = hashtab_search(db->scope[SYM_ROLES].table, (const hashtab_key_t)name);
|
||||
scope_datum_t* scope_datum = hashtab_search(db->scope[SYM_ROLES].table, (hashtab_key_t)name);
|
||||
if (scope_datum == NULL) {
|
||||
ERR(policy, "could not find scope datum for role %s", name);
|
||||
error = ENOENT;
|
||||
@ -705,7 +705,7 @@ static int union_multiply_declared_symbols(qpol_policy_t * policy) {
|
||||
{
|
||||
if (db->decl_val_to_struct[scope_datum->decl_ids[i] - 1]->enabled == 0)
|
||||
continue; /* block is disabled */
|
||||
role_datum_t *internal_datum = hashtab_search(db->decl_val_to_struct[scope_datum->decl_ids[i] - 1]->symtab[SYM_ROLES].table, (const hashtab_key_t)name);
|
||||
role_datum_t *internal_datum = hashtab_search(db->decl_val_to_struct[scope_datum->decl_ids[i] - 1]->symtab[SYM_ROLES].table, (hashtab_key_t)name);
|
||||
if (internal_datum == NULL) {
|
||||
continue; /* not declared here */
|
||||
}
|
||||
@ -736,7 +736,7 @@ static int union_multiply_declared_symbols(qpol_policy_t * policy) {
|
||||
goto err;
|
||||
}
|
||||
policydb_t *db = &policy->p->p;
|
||||
scope_datum_t* scope_datum = hashtab_search(db->scope[SYM_USERS].table, (const hashtab_key_t)name);
|
||||
scope_datum_t* scope_datum = hashtab_search(db->scope[SYM_USERS].table, (hashtab_key_t)name);
|
||||
if (scope_datum == NULL) {
|
||||
ERR(policy, "could not find scope datum for user %s", name);
|
||||
error = ENOENT;
|
||||
@ -746,7 +746,7 @@ static int union_multiply_declared_symbols(qpol_policy_t * policy) {
|
||||
{
|
||||
if (db->decl_val_to_struct[scope_datum->decl_ids[i] - 1]->enabled == 0)
|
||||
continue; /* block is disabled */
|
||||
user_datum_t *internal_datum = hashtab_search(db->decl_val_to_struct[scope_datum->decl_ids[i] -1 ]->symtab[SYM_USERS].table, (const hashtab_key_t)name);
|
||||
user_datum_t *internal_datum = hashtab_search(db->decl_val_to_struct[scope_datum->decl_ids[i] -1 ]->symtab[SYM_USERS].table, (hashtab_key_t)name);
|
||||
if (internal_datum == NULL) {
|
||||
continue; /* not declared here */
|
||||
}
|
||||
|
@ -1389,7 +1389,7 @@ static int define_typebounds_helper(char *bounds_id, char *type_id)
|
||||
return -1;
|
||||
}
|
||||
|
||||
bounds = hashtab_search(policydbp->p_types.table, bounds_id);
|
||||
bounds = hashtab_search(policydbp->p_types.table, (hashtab_key_t)bounds_id);
|
||||
if (!bounds || bounds->flavor == TYPE_ATTRIB) {
|
||||
yyerror2("hoge unknown type %s", bounds_id);
|
||||
return -1;
|
||||
@ -1400,7 +1400,7 @@ static int define_typebounds_helper(char *bounds_id, char *type_id)
|
||||
return -1;
|
||||
}
|
||||
|
||||
type = hashtab_search(policydbp->p_types.table, type_id);
|
||||
type = hashtab_search(policydbp->p_types.table, (hashtab_key_t)type_id);
|
||||
if (!type || type->flavor == TYPE_ATTRIB) {
|
||||
yyerror2("type %s is not declared", type_id);
|
||||
return -1;
|
||||
@ -1508,7 +1508,7 @@ int define_type(int alias)
|
||||
free(id);
|
||||
return -1;
|
||||
}
|
||||
attr = hashtab_search(policydbp->p_types.table, id);
|
||||
attr = hashtab_search(policydbp->p_types.table, (hashtab_key_t)id);
|
||||
if (!attr) {
|
||||
/* treat it as a fatal error */
|
||||
yyerror2("attribute %s is not declared", id);
|
||||
@ -1581,7 +1581,7 @@ static int set_types(type_set_t * set, char *id, int *add, char starallowed)
|
||||
free(id);
|
||||
return -1;
|
||||
}
|
||||
t = hashtab_search(policydbp->p_types.table, id);
|
||||
t = hashtab_search(policydbp->p_types.table, (hashtab_key_t)id);
|
||||
if (!t) {
|
||||
yyerror2("unknown type %s", id);
|
||||
free(id);
|
||||
@ -2494,7 +2494,7 @@ int define_role_trans(int class_specified)
|
||||
return -1;
|
||||
} else {
|
||||
cladatum = hashtab_search(policydbp->p_classes.table,
|
||||
"process");
|
||||
(hashtab_key_t)"process");
|
||||
if (!cladatum) {
|
||||
yyerror2("could not find process class for "
|
||||
"legacy role_transition statement");
|
||||
@ -4889,7 +4889,7 @@ int define_range_trans(int class_specified)
|
||||
goto out;
|
||||
} else {
|
||||
cladatum = hashtab_search(policydbp->p_classes.table,
|
||||
"process");
|
||||
(hashtab_key_t)"process");
|
||||
if (!cladatum) {
|
||||
yyerror2("could not find process class for "
|
||||
"legacy range_transition statement");
|
||||
|
@ -471,7 +471,7 @@ static int qpol_policy_add_object_r(qpol_policy_t * policy)
|
||||
|
||||
db = &policy->p->p;
|
||||
|
||||
hashtab_datum_t datum = hashtab_search(db->p_roles.table, (const hashtab_key_t)OBJECT_R);
|
||||
hashtab_datum_t datum = hashtab_search(db->p_roles.table, (hashtab_key_t)OBJECT_R);
|
||||
if (datum == NULL) {
|
||||
ERR(policy, "%s", OBJECT_R " not found in policy!");
|
||||
errno = EIO;
|
||||
|
@ -49,7 +49,7 @@ int qpol_policy_get_role_by_name(const qpol_policy_t * policy, const char *name,
|
||||
}
|
||||
|
||||
db = &policy->p->p;
|
||||
internal_datum = hashtab_search(db->p_roles.table, (const hashtab_key_t)name);
|
||||
internal_datum = hashtab_search(db->p_roles.table, (hashtab_key_t)name);
|
||||
if (internal_datum == NULL) {
|
||||
*datum = NULL;
|
||||
ERR(policy, "could not find datum for role %s", name);
|
||||
|
@ -49,7 +49,7 @@ int qpol_policy_get_type_by_name(const qpol_policy_t * policy, const char *name,
|
||||
}
|
||||
|
||||
db = &policy->p->p;
|
||||
internal_datum = hashtab_search(db->p_types.table, (const hashtab_key_t)name);
|
||||
internal_datum = hashtab_search(db->p_types.table, (hashtab_key_t)name);
|
||||
if (internal_datum == NULL) {
|
||||
*datum = NULL;
|
||||
ERR(policy, "could not find datum for type %s", name);
|
||||
|
@ -53,7 +53,7 @@ int qpol_policy_get_user_by_name(const qpol_policy_t * policy, const char *name,
|
||||
}
|
||||
|
||||
db = &policy->p->p;
|
||||
internal_datum = hashtab_search(db->p_users.table, (const hashtab_key_t)name);
|
||||
internal_datum = hashtab_search(db->p_users.table, (hashtab_key_t)name);
|
||||
if (internal_datum == NULL) {
|
||||
*datum = NULL;
|
||||
ERR(policy, "could not find datum for user %s", name);
|
||||
|
Loading…
Reference in New Issue
Block a user