summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Moore <pmoore@redhat.com>2013-04-19 15:29:50 -0400
committerPaul Moore <pmoore@redhat.com>2013-04-19 15:29:50 -0400
commitb29fcac12735967f594223389cd06e41d3d07b48 (patch)
treeb0902bc1a157d1265ba06fd3501428209c4b82ba
parent3bcbcd0389f6e7ee7fba0a3fee4c30e21c3625f0 (diff)
downloadlibseccomp-b29fcac12735967f594223389cd06e41d3d07b48.tar.gz
all: convert some booleans from ints to bools
Make it more obvious that these variables are booleans. Signed-off-by: Paul Moore <pmoore@redhat.com>
-rw-r--r--src/api.c3
-rw-r--r--src/arch-x86.c5
-rw-r--r--src/arch-x86.h7
-rw-r--r--src/arch.c7
-rw-r--r--src/arch.h6
-rw-r--r--src/db.c64
-rw-r--r--src/db.h13
-rw-r--r--src/gen_bpf.c29
-rw-r--r--src/gen_pfc.c2
9 files changed, 69 insertions, 67 deletions
diff --git a/src/api.c b/src/api.c
index d524c26..06e8e01 100644
--- a/src/api.c
+++ b/src/api.c
@@ -26,6 +26,7 @@
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
+#include <stdbool.h>
#include <sys/prctl.h>
#include <seccomp.h>
@@ -364,7 +365,7 @@ syscall_priority_failure:
*
*/
static int _seccomp_rule_add(struct db_filter_col *col,
- unsigned int strict, uint32_t action, int syscall,
+ bool strict, uint32_t action, int syscall,
unsigned int arg_cnt,
const struct scmp_arg_cmp *arg_array)
{
diff --git a/src/arch-x86.c b/src/arch-x86.c
index 42c0bb1..66e72dc 100644
--- a/src/arch-x86.c
+++ b/src/arch-x86.c
@@ -51,8 +51,7 @@ const struct arch_def arch_def_x86 = {
* failure.
*
*/
-int x86_syscall_rewrite(const struct arch_def *arch, unsigned int strict,
- int *syscall)
+int x86_syscall_rewrite(const struct arch_def *arch, bool strict, int *syscall)
{
if ((*syscall) <= -100 && (*syscall) >= -117)
*syscall = __x86_NR_socketcall;
@@ -79,7 +78,7 @@ int x86_syscall_rewrite(const struct arch_def *arch, unsigned int strict,
* fail. Returns zero on success, negative values on failure.
*
*/
-int x86_filter_rewrite(const struct arch_def *arch, unsigned int strict,
+int x86_filter_rewrite(const struct arch_def *arch, bool strict,
int *syscall, struct db_api_arg *chain)
{
unsigned int iter;
diff --git a/src/arch-x86.h b/src/arch-x86.h
index 2383f76..a399559 100644
--- a/src/arch-x86.h
+++ b/src/arch-x86.h
@@ -22,6 +22,8 @@
#ifndef _ARCH_X86_H
#define _ARCH_X86_H
+#include <stdbool.h>
+
#include "arch.h"
#include "db.h"
#include "system.h"
@@ -33,10 +35,9 @@ extern const struct arch_def arch_def_x86;
int x86_syscall_resolve_name(const char *name);
const char *x86_syscall_resolve_num(int num);
-int x86_syscall_rewrite(const struct arch_def *arch, unsigned int strict,
- int *syscall);
+int x86_syscall_rewrite(const struct arch_def *arch, bool strict, int *syscall);
-int x86_filter_rewrite(const struct arch_def *arch, unsigned int strict,
+int x86_filter_rewrite(const struct arch_def *arch, bool strict,
int *syscall, struct db_api_arg *chain);
#endif
diff --git a/src/arch.c b/src/arch.c
index 994b4fb..47a539d 100644
--- a/src/arch.c
+++ b/src/arch.c
@@ -25,6 +25,7 @@
#include <string.h>
#include <asm/bitsperlong.h>
#include <linux/audit.h>
+#include <stdbool.h>
#include <seccomp.h>
@@ -252,8 +253,7 @@ int arch_syscall_translate(const struct arch_def *arch, int *syscall)
* failure.
*
*/
-int arch_syscall_rewrite(const struct arch_def *arch, unsigned int strict,
- int *syscall)
+int arch_syscall_rewrite(const struct arch_def *arch, bool strict, int *syscall)
{
int sys = *syscall;
@@ -295,8 +295,7 @@ int arch_syscall_rewrite(const struct arch_def *arch, unsigned int strict,
*
*/
int arch_filter_rewrite(const struct arch_def *arch,
- unsigned int strict,
- int *syscall, struct db_api_arg *chain)
+ bool strict, int *syscall, struct db_api_arg *chain)
{
int sys = *syscall;
diff --git a/src/arch.h b/src/arch.h
index 061c2cc..5c4249f 100644
--- a/src/arch.h
+++ b/src/arch.h
@@ -24,6 +24,7 @@
#include <inttypes.h>
#include <stddef.h>
+#include <stdbool.h>
#include <seccomp.h>
@@ -96,11 +97,10 @@ int arch_syscall_resolve_name(const struct arch_def *arch, const char *name);
const char *arch_syscall_resolve_num(const struct arch_def *arch, int num);
int arch_syscall_translate(const struct arch_def *arch, int *syscall);
-int arch_syscall_rewrite(const struct arch_def *arch, unsigned int strict,
+int arch_syscall_rewrite(const struct arch_def *arch, bool strict,
int *syscall);
int arch_filter_rewrite(const struct arch_def *arch,
- unsigned int strict,
- int *syscall, struct db_api_arg *chain);
+ bool strict, int *syscall, struct db_api_arg *chain);
#endif
diff --git a/src/db.c b/src/db.c
index 7346a57..29d94c8 100644
--- a/src/db.c
+++ b/src/db.c
@@ -195,12 +195,12 @@ static int _db_tree_act_check(struct db_arg_chain_tree *tree, uint32_t action)
static int _db_tree_sub_prune(struct db_arg_chain_tree **tree_head,
struct db_arg_chain_tree *tree_start,
struct db_arg_chain_tree *new,
- unsigned int *remove_flg)
+ bool *remove_flg)
{
int rc = 0;
struct db_arg_chain_tree *c_iter = tree_start;
- *remove_flg = 0;
+ *remove_flg = false;
if (new == NULL || c_iter == NULL)
return 0;
@@ -212,7 +212,7 @@ static int _db_tree_sub_prune(struct db_arg_chain_tree **tree_head,
if (new->act_t_flg) {
rc += _db_tree_remove(tree_head, c_iter->nxt_t);
c_iter->act_t = new->act_t;
- c_iter->act_t_flg = 1;
+ c_iter->act_t_flg = true;
} else if (new->nxt_t != NULL)
rc += _db_tree_sub_prune(tree_head,
c_iter->nxt_t,
@@ -221,7 +221,7 @@ static int _db_tree_sub_prune(struct db_arg_chain_tree **tree_head,
if (new->act_f_flg) {
rc += _db_tree_remove(tree_head, c_iter->nxt_f);
c_iter->act_f = new->act_f;
- c_iter->act_f_flg = 1;
+ c_iter->act_f_flg = true;
} else if (new->nxt_f != NULL)
rc += _db_tree_sub_prune(tree_head,
c_iter->nxt_f,
@@ -245,7 +245,7 @@ static int _db_tree_sub_prune(struct db_arg_chain_tree **tree_head,
sub_prune_return:
if (rc > 0)
- *remove_flg = 1;
+ *remove_flg = true;
return rc;
}
@@ -679,7 +679,7 @@ int db_syscall_priority(struct db_filter *db,
memset(s_new, 0, sizeof(*s_new));
s_new->num = syscall;
s_new->priority = sys_pri;
- s_new->valid = 0;
+ s_new->valid = false;
/* add it before s_iter */
if (s_prev != NULL) {
@@ -731,14 +731,14 @@ static struct db_sys_list *_db_rule_gen_64(const struct arch_def *arch,
struct db_sys_list *s_new;
struct db_arg_chain_tree *c_iter_hi = NULL, *c_iter_lo = NULL;
struct db_arg_chain_tree *c_prev_hi = NULL, *c_prev_lo = NULL;
- unsigned int tf_flag;
+ bool tf_flag;
s_new = malloc(sizeof(*s_new));
if (s_new == NULL)
return NULL;
memset(s_new, 0, sizeof(*s_new));
s_new->num = syscall;
- s_new->valid = 1;
+ s_new->valid = true;
/* run through the argument chain */
chain_len_max = arch_arg_count_max(arch);
for (iter = 0; iter < chain_len_max; iter++) {
@@ -781,27 +781,27 @@ static struct db_sys_list *_db_rule_gen_64(const struct arch_def *arch,
case SCMP_CMP_GT:
c_iter_hi->op = SCMP_CMP_GE;
c_iter_lo->op = SCMP_CMP_GT;
- tf_flag = 1;
+ tf_flag = true;
break;
case SCMP_CMP_NE:
c_iter_hi->op = SCMP_CMP_EQ;
c_iter_lo->op = SCMP_CMP_EQ;
- tf_flag = 0;
+ tf_flag = false;
break;
case SCMP_CMP_LT:
c_iter_hi->op = SCMP_CMP_GE;
c_iter_lo->op = SCMP_CMP_GE;
- tf_flag = 0;
+ tf_flag = false;
break;
case SCMP_CMP_LE:
c_iter_hi->op = SCMP_CMP_GE;
c_iter_lo->op = SCMP_CMP_GT;
- tf_flag = 0;
+ tf_flag = false;
break;
default:
c_iter_hi->op = chain[iter].op;
c_iter_lo->op = chain[iter].op;
- tf_flag = 1;
+ tf_flag = true;
}
c_iter_hi->mask = D64_HI(chain[iter].mask);
c_iter_lo->mask = D64_LO(chain[iter].mask);
@@ -821,12 +821,12 @@ static struct db_sys_list *_db_rule_gen_64(const struct arch_def *arch,
if (c_iter_lo != NULL) {
/* set the leaf node */
if (!tf_flag) {
- c_iter_lo->act_f_flg = 1;
+ c_iter_lo->act_f_flg = true;
c_iter_lo->act_f = action;
- c_iter_hi->act_f_flg = 1;
+ c_iter_hi->act_f_flg = true;
c_iter_hi->act_f = action;
} else {
- c_iter_lo->act_t_flg = 1;
+ c_iter_lo->act_t_flg = true;
c_iter_lo->act_t = action;
}
} else
@@ -861,14 +861,14 @@ static struct db_sys_list *_db_rule_gen_32(const struct arch_def *arch,
int chain_len_max;
struct db_sys_list *s_new;
struct db_arg_chain_tree *c_iter = NULL, *c_prev = NULL;
- unsigned int tf_flag;
+ bool tf_flag;
s_new = malloc(sizeof(*s_new));
if (s_new == NULL)
return NULL;
memset(s_new, 0, sizeof(*s_new));
s_new->num = syscall;
- s_new->valid = 1;
+ s_new->valid = true;
/* run through the argument chain */
chain_len_max = arch_arg_count_max(arch);
for (iter = 0; iter < chain_len_max; iter++) {
@@ -900,18 +900,18 @@ static struct db_sys_list *_db_rule_gen_32(const struct arch_def *arch,
switch (c_iter->op) {
case SCMP_CMP_NE:
c_iter->op = SCMP_CMP_EQ;
- tf_flag = 0;
+ tf_flag = false;
break;
case SCMP_CMP_LT:
c_iter->op = SCMP_CMP_GE;
- tf_flag = 0;
+ tf_flag = false;
break;
case SCMP_CMP_LE:
c_iter->op = SCMP_CMP_GT;
- tf_flag = 0;
+ tf_flag = false;
break;
default:
- tf_flag = 1;
+ tf_flag = true;
}
/* fixup the mask/datum */
@@ -922,10 +922,10 @@ static struct db_sys_list *_db_rule_gen_32(const struct arch_def *arch,
if (c_iter != NULL) {
/* set the leaf node */
if (tf_flag) {
- c_iter->act_t_flg = 1;
+ c_iter->act_t_flg = true;
c_iter->act_t = action;
} else {
- c_iter->act_f_flg = 1;
+ c_iter->act_f_flg = true;
c_iter->act_f = action;
}
} else
@@ -961,7 +961,7 @@ int db_rule_add(struct db_filter *db, uint32_t action, unsigned int syscall,
struct db_sys_list *s_new, *s_iter, *s_prev = NULL;
struct db_arg_chain_tree *c_iter = NULL, *c_prev = NULL;
struct db_arg_chain_tree *ec_iter, *ec_iter_b;
- unsigned int rm_flag = 0;
+ bool rm_flag = false;
unsigned int new_chain_cnt = 0;
unsigned int n_cnt;
@@ -1009,7 +1009,7 @@ add_reset:
}
return 0;
} else if (s_iter->chains == NULL) {
- if (rm_flag || s_iter->valid == 0) {
+ if (rm_flag || !s_iter->valid) {
/* we are here because our previous pass cleared the
* entire syscall chain when searching for a subtree
* match or the existing syscall entry is a phantom,
@@ -1017,9 +1017,9 @@ add_reset:
s_iter->chains = s_new->chains;
s_iter->action = s_new->action;
s_iter->node_cnt = s_new->node_cnt;
- if (s_iter->valid == 1)
+ if (s_iter->valid)
s_iter->priority = s_new->priority;
- s_iter->valid = 1;
+ s_iter->valid = true;
free(s_new);
rc = 0;
goto add_priority_update;
@@ -1076,14 +1076,14 @@ add_reset:
if (ec_iter->act_t != action)
goto add_free_exist;
} else if (c_iter->act_t_flg) {
- ec_iter->act_t_flg = 1;
+ ec_iter->act_t_flg = true;
ec_iter->act_t = action;
}
if (c_iter->act_f_flg && ec_iter->act_f_flg) {
if (ec_iter->act_f != action)
goto add_free_exist;
} else if (c_iter->act_f_flg) {
- ec_iter->act_f_flg = 1;
+ ec_iter->act_f_flg = true;
ec_iter->act_f = action;
}
if (ec_iter->act_t_flg == ec_iter->act_f_flg &&
@@ -1103,7 +1103,7 @@ add_reset:
goto add_free;
n_cnt = _db_tree_free(ec_iter->nxt_t);
ec_iter->nxt_t = NULL;
- ec_iter->act_t_flg = 1;
+ ec_iter->act_t_flg = true;
ec_iter->act_t = action;
} else {
rc = _db_tree_act_check(ec_iter->nxt_f,
@@ -1112,7 +1112,7 @@ add_reset:
goto add_free;
n_cnt = _db_tree_free(ec_iter->nxt_f);
ec_iter->nxt_f = NULL;
- ec_iter->act_f_flg = 1;
+ ec_iter->act_f_flg = true;
ec_iter->act_f = action;
}
s_iter->node_cnt -= n_cnt;
diff --git a/src/db.h b/src/db.h
index 97c8758..39dfa3b 100644
--- a/src/db.h
+++ b/src/db.h
@@ -22,7 +22,8 @@
#ifndef _FILTER_DB_H
#define _FILTER_DB_H
-#include "inttypes.h"
+#include <inttypes.h>
+#include <stdbool.h>
#include <seccomp.h>
@@ -31,7 +32,7 @@
/* XXX - need to provide doxygen comments for the types here */
struct db_api_arg {
- unsigned int valid;
+ bool valid;
unsigned int arg;
unsigned int op;
@@ -52,9 +53,9 @@ struct db_arg_chain_tree {
uint32_t datum;
/* actions */
- unsigned int act_t_flg;
+ bool act_t_flg;
uint32_t act_t;
- unsigned int act_f_flg;
+ bool act_f_flg;
uint32_t act_f;
/* list of nodes on this level */
@@ -80,7 +81,7 @@ struct db_arg_chain_tree {
(((x)->arg == (y)->arg) && (((x)->op > (y)->op) || \
(((x)->mask & (y)->mask) != (y)->mask))))
#define db_chain_leaf(x) \
- (((x)->act_t_flg != 0) || ((x)->act_f_flg != 0))
+ (((x)->act_t_flg) || ((x)->act_f_flg))
#define db_chain_eq_result(x,y) \
((((x)->nxt_t != NULL && (y)->nxt_t != NULL) || \
((x)->nxt_t == NULL && (y)->nxt_t == NULL)) && \
@@ -96,7 +97,7 @@ struct db_arg_chain_tree {
struct db_sys_list {
/* native syscall number */
unsigned int num;
- unsigned int valid;
+ bool valid;
/* priority - higher is better */
unsigned int priority;
diff --git a/src/gen_bpf.c b/src/gen_bpf.c
index 164e87b..d16b331 100644
--- a/src/gen_bpf.c
+++ b/src/gen_bpf.c
@@ -24,6 +24,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <stdbool.h>
#include <seccomp.h>
@@ -102,9 +103,9 @@ struct bpf_blk {
const struct db_arg_chain_tree *node;
/* status flags */
- unsigned int flag_hash; /* added to the hash table */
- unsigned int flag_dup; /* duplicate block and in use */
- unsigned int flag_unique; /* ->blks is unique to this block */
+ bool flag_hash; /* added to the hash table */
+ bool flag_dup; /* duplicate block and in use */
+ bool flag_unique; /* ->blks is unique to this block */
/* used during block assembly */
struct acc_state acc_state;
@@ -271,7 +272,7 @@ static struct bpf_blk *_blk_append(struct bpf_state *state,
if (blk == NULL)
return NULL;
memset(blk, 0, sizeof(*blk));
- blk->flag_unique = 1;
+ blk->flag_unique = true;
}
if ((blk->blk_cnt + 1) > blk->blk_alloc) {
blk->blk_alloc += AINC_BLK;
@@ -445,7 +446,7 @@ static int _hsh_add(struct bpf_state *state, struct bpf_blk **blk_p,
/* generate the hash */
h_val = jhash(blk->blks, _BLK_MSZE(blk), 0);
blk->hash = h_val;
- blk->flag_hash = 1;
+ blk->flag_hash = true;
blk->node = NULL;
h_new->blk = blk;
h_new->found = (found ? 1 : 0);
@@ -470,7 +471,7 @@ static int _hsh_add(struct bpf_state *state, struct bpf_blk **blk_p,
/* in some cases we want to return the
* duplicate block */
if (found) {
- blk->flag_dup = 1;
+ blk->flag_dup = true;
return 0;
}
@@ -481,7 +482,7 @@ static int _hsh_add(struct bpf_state *state, struct bpf_blk **blk_p,
/* try to save some memory */
free(blk->blks);
blk->blks = h_iter->blk->blks;
- blk->flag_unique = 0;
+ blk->flag_unique = false;
*blk_p = h_iter->blk;
return 0;
@@ -489,7 +490,7 @@ static int _hsh_add(struct bpf_state *state, struct bpf_blk **blk_p,
/* hash collision */
if ((h_val >> 32) == 0xffffffff) {
/* overflow */
- blk->flag_hash = 0;
+ blk->flag_hash = false;
blk->hash = 0;
return -EFAULT;
}
@@ -1000,7 +1001,7 @@ chain_failure:
static struct bpf_blk *_gen_bpf_syscall(struct bpf_state *state,
const struct db_sys_list *sys,
uint64_t nxt_hash,
- int acc_reset)
+ bool acc_reset)
{
int rc;
struct bpf_instr instr;
@@ -1069,7 +1070,7 @@ static struct bpf_blk *_gen_bpf_arch(struct bpf_state *state,
{
int rc;
unsigned int blk_cnt = 0;
- unsigned int acc_reset;
+ bool acc_reset;
struct bpf_instr instr;
struct db_sys_list *s_head = NULL, *s_tail = NULL, *s_iter, *s_iter_b;
struct bpf_blk *b_head = NULL, *b_tail = NULL, *b_iter, *b_new;
@@ -1142,20 +1143,20 @@ static struct bpf_blk *_gen_bpf_arch(struct bpf_state *state,
if ((db->arch->token == SCMP_ARCH_X86_64 ||
db->arch->token == SCMP_ARCH_X32) && (db_secondary == NULL))
- acc_reset = 0;
+ acc_reset = false;
else
- acc_reset = 1;
+ acc_reset = true;
/* create the syscall filters and add them to block list group */
for (s_iter = s_tail; s_iter != NULL; s_iter = s_iter->pri_prv) {
- if (s_iter->valid == 0)
+ if (!s_iter->valid)
continue;
/* build the syscall filter */
b_new = _gen_bpf_syscall(state, s_iter,
(b_head == NULL ?
state->def_hsh : b_head->hash),
- (s_iter == s_head ? acc_reset : 0));
+ (s_iter == s_head ? acc_reset:false));
if (b_new == NULL)
goto arch_failure;
diff --git a/src/gen_pfc.c b/src/gen_pfc.c
index 9da9a0c..75c96d6 100644
--- a/src/gen_pfc.c
+++ b/src/gen_pfc.c
@@ -270,7 +270,7 @@ static int _gen_pfc_arch(const struct db_filter_col *col,
fprintf(fds, "if ($arch == %u)\n", db->arch->token_bpf);
p_iter = p_head;
while (p_iter != NULL) {
- if (p_iter->sys->valid == 0)
+ if (!p_iter->sys->valid)
continue;
_gen_pfc_syscall(db->arch, p_iter->sys, fds);
p_iter = p_iter->next;