Skip to content

Commit

Permalink
Code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
happyCoder92 committed Apr 10, 2019
1 parent 253cf21 commit d907da7
Show file tree
Hide file tree
Showing 27 changed files with 5,730 additions and 3,873 deletions.
4 changes: 2 additions & 2 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ parser.h parser.c: parser.y

# DO NOT DELETE THIS LINE -- make depend depends on it.

kafel.o: parser.h context.h includes.h policy.h expression.h syscall.h
kafel.o: codegen.h common.h lexer.h
kafel.o: codegen.h context.h includes.h policy.h expression.h syscall.h
kafel.o: common.h lexer.h parser.h
context.o: context.h includes.h policy.h expression.h syscall.h common.h
codegen.o: codegen.h context.h includes.h policy.h expression.h syscall.h
codegen.o: common.h range_rules.h
Expand Down
7 changes: 3 additions & 4 deletions src/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@
#include "codegen.h"

#include <limits.h>
#include <linux/audit.h>
#include <linux/seccomp.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>

#include <linux/audit.h>
#include <linux/seccomp.h>
#include <sys/queue.h>

#include "common.h"
Expand All @@ -51,7 +50,7 @@
#define SECCOMP_RET_KILL_PROCESS 0x80000000U
#endif
#ifndef SECCOMP_RET_USER_NOTIF
#define SECCOMP_RET_USER_NOTIF 0x7fc00000U
#define SECCOMP_RET_USER_NOTIF 0x7fc00000U
#endif

#define CURRENT_LOC (ctxt->buffer.len - 1)
Expand Down
3 changes: 1 addition & 2 deletions src/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "context.h"

#include <linux/audit.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
Expand All @@ -28,8 +29,6 @@
#include "common.h"
#include "kafel.h"

#include <linux/audit.h>

KAFEL_API kafel_ctxt_t kafel_ctxt_create(void) {
struct kafel_ctxt* ctxt = calloc(1, sizeof(*ctxt));
includes_ctxt_init(&ctxt->includes_ctxt);
Expand Down
22 changes: 10 additions & 12 deletions src/expression.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ void expr_eliminate_negation(struct expr_tree **expr, bool neg) {
ASSERT(expr != NULL);
ASSERT((*expr) != NULL);

int negations[EXPR_MAX + 1] =
{[EXPR_AND] = EXPR_OR, [EXPR_OR] = EXPR_AND, [EXPR_GE] = EXPR_LT,
[EXPR_GT] = EXPR_LE, [EXPR_LE] = EXPR_GT, [EXPR_LT] = EXPR_GE,
[EXPR_EQ] = EXPR_NEQ, [EXPR_NEQ] = EXPR_EQ, [EXPR_TRUE] = EXPR_FALSE,
[EXPR_FALSE] = EXPR_TRUE};
int negations[EXPR_MAX + 1] = {
[EXPR_AND] = EXPR_OR, [EXPR_OR] = EXPR_AND, [EXPR_GE] = EXPR_LT,
[EXPR_GT] = EXPR_LE, [EXPR_LE] = EXPR_GT, [EXPR_LT] = EXPR_GE,
[EXPR_EQ] = EXPR_NEQ, [EXPR_NEQ] = EXPR_EQ, [EXPR_TRUE] = EXPR_FALSE,
[EXPR_FALSE] = EXPR_TRUE};
switch ((*expr)->type) {
case EXPR_NOT: {
struct expr_tree *tmp = *expr;
Expand Down Expand Up @@ -107,13 +107,11 @@ static void expr_sort_operands(struct expr_tree *expr) {

if (expr->type != EXPR_AND && expr->type != EXPR_OR &&
expr->left->type < expr->right->type) {
int swapped[EXPR_MAX + 1] = {[EXPR_GE] = EXPR_LE,
[EXPR_GT] = EXPR_LT,
[EXPR_LE] = EXPR_GE,
[EXPR_LT] = EXPR_GT,
[EXPR_EQ] = EXPR_EQ,
[EXPR_NEQ] = EXPR_NEQ,
[EXPR_BIT_AND] = EXPR_BIT_AND};
int swapped[EXPR_MAX + 1] = {
[EXPR_GE] = EXPR_LE, [EXPR_GT] = EXPR_LT,
[EXPR_LE] = EXPR_GE, [EXPR_LT] = EXPR_GT,
[EXPR_EQ] = EXPR_EQ, [EXPR_NEQ] = EXPR_NEQ,
[EXPR_BIT_AND] = EXPR_BIT_AND};
expr->type = swapped[expr->type];
SWAP(expr->left, expr->right);
}
Expand Down
9 changes: 3 additions & 6 deletions src/includes.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ bool includes_stack_is_empty(struct includes_ctxt* ctxt) {
}

void includes_stack_pop(struct includes_ctxt* ctxt) {

ASSERT(!SLIST_EMPTY(&ctxt->stack));
struct included_file* file = SLIST_FIRST(&ctxt->stack);
fclose(file->fp);
Expand All @@ -93,18 +92,16 @@ static char* path_join(const char* first, const char* second) {
if (len <= flen || len <= slen) {
return NULL;
}
char* rv = malloc(len+1);
char* rv = malloc(len + 1);
ASSERT(rv != NULL);
memcpy(rv, first, flen);
rv[flen] = '/';
memcpy(rv+flen+1, second, slen);
memcpy(rv + flen + 1, second, slen);
rv[len] = '\0';
return rv;
}

int includes_depth(struct includes_ctxt* ctxt) {
return ctxt->depth;
}
int includes_depth(struct includes_ctxt* ctxt) { return ctxt->depth; }

struct included_file* includes_resolve(struct includes_ctxt* ctxt,
const char* filename) {
Expand Down
2 changes: 1 addition & 1 deletion src/includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#ifndef KAFEL_INCLUDES_H
#define KAFEL_INCLUDES_H

#include <stdio.h>
#include <stdbool.h>
#include <stdio.h>
#include <sys/queue.h>

struct included_file {
Expand Down
3 changes: 1 addition & 2 deletions src/kafel.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@

#include "kafel.h"

#include "parser.h"

#include "codegen.h"
#include "common.h"
#include "context.h"
#include "includes.h"
#include "lexer.h"
#include "parser.h"
#include "syscall.h"

// flex <2.5.36 does not declare yyset_column
Expand Down
1 change: 0 additions & 1 deletion src/policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#define KAFEL_POLICY_H

#include <stdint.h>

#include <sys/queue.h>

#include "expression.h"
Expand Down
3 changes: 2 additions & 1 deletion src/range_rules.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ void add_policy_rules(struct syscall_range_rules *rules,
TAILQ_FOREACH(filter, &entry->filters, filters) {
uint32_t syscall_nr = filter->syscall_nr;
struct syscall_range_rule rule = {
.first = syscall_nr, .last = syscall_nr,
.first = syscall_nr,
.last = syscall_nr,
};
TAILQ_INIT(&rule.expr_list);
if (filter->expr != NULL && filter->expr->type != EXPR_TRUE) {
Expand Down
1 change: 0 additions & 1 deletion src/range_rules.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <limits.h>
#include <stddef.h>
#include <stdint.h>

#include <sys/queue.h>

#include "policy.h"
Expand Down
3 changes: 1 addition & 2 deletions src/syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@

#include "syscall.h"

#include <linux/audit.h>
#include <stdlib.h>
#include <string.h>

#include <linux/audit.h>

#include "common.h"

// Fix for Linux <3.12
Expand Down
Loading

0 comments on commit d907da7

Please sign in to comment.