Pierre-Hugues Husson | c0ca67e | 2018-03-22 20:31:17 +0100 | [diff] [blame] | 1 | From c334f823d0eccac2656ceceb707367680cca32f2 Mon Sep 17 00:00:00 2001 |
| 2 | From: Pierre-Hugues Husson <phh@phh.me> |
| 3 | Date: Sat, 3 Mar 2018 19:02:29 +0100 |
| 4 | Subject: [PATCH 5/5] Delete identical genfscon-s |
| 5 | |
| 6 | Change-Id: I9775187b9da3568390ab66ebd59cb774b1283ad1 |
| 7 | --- |
| 8 | libsepol/cil/src/cil_post.c | 11 +++++++++++ |
| 9 | 1 file changed, 11 insertions(+) |
| 10 | |
| 11 | diff --git a/libsepol/cil/src/cil_post.c b/libsepol/cil/src/cil_post.c |
| 12 | index a30de0e1..605847d1 100644 |
| 13 | --- a/libsepol/cil/src/cil_post.c |
| 14 | +++ b/libsepol/cil/src/cil_post.c |
| 15 | @@ -53,6 +53,16 @@ |
| 16 | static int __cil_expr_to_bitmap(struct cil_list *expr, ebitmap_t *out, int max, struct cil_db *db); |
| 17 | static int __cil_expr_list_to_bitmap(struct cil_list *expr_list, ebitmap_t *out, int max, struct cil_db *db); |
| 18 | |
| 19 | +static int compact(void* array, int count, int len, int (*compar)(const void *, const void *)) { |
| 20 | + char *a = (char*)array; |
| 21 | + int j = 0; |
| 22 | + for(int i=1; i<count; i++) { |
| 23 | + if(compar(a+i*len, a+j*len) != 0) j++; |
| 24 | + if(i != j) memcpy(a+j*len, a+i*len, len); |
| 25 | + } |
| 26 | + return j; |
| 27 | +} |
| 28 | + |
| 29 | static int cil_verify_is_list(struct cil_list *list, enum cil_flavor flavor) |
| 30 | { |
| 31 | struct cil_list_item *curr; |
| 32 | @@ -1977,6 +1987,7 @@ static int cil_post_db(struct cil_db *db) |
| 33 | |
| 34 | qsort(db->netifcon->array, db->netifcon->count, sizeof(db->netifcon->array), cil_post_netifcon_compare); |
| 35 | qsort(db->genfscon->array, db->genfscon->count, sizeof(db->genfscon->array), cil_post_genfscon_compare); |
| 36 | + db->genfscon->count = compact(db->genfscon->array, db->genfscon->count, sizeof(db->genfscon->array), cil_post_genfscon_compare); |
| 37 | qsort(db->portcon->array, db->portcon->count, sizeof(db->portcon->array), cil_post_portcon_compare); |
| 38 | qsort(db->nodecon->array, db->nodecon->count, sizeof(db->nodecon->array), cil_post_nodecon_compare); |
| 39 | qsort(db->fsuse->array, db->fsuse->count, sizeof(db->fsuse->array), cil_post_fsuse_compare); |
| 40 | -- |
| 41 | 2.15.1 |
| 42 | |