libsepol: cil_resolve_ast: add in a CIL_SRC_INFO for the copied data
PATCH 1/1 libsepol: cil_resolve_ast: add in a CIL_SRC_INFO for the copied data
Ownership of the data copied in from an in statement currently resolves up to the parent block. This is because when looking up a corrosponding path with cil_tree_get_cil_path(), the chain is walked up until a valid match is found from cil_tree_get_next_path(). However, as the content that is inserted into the block does not originate from the same file as the file where the block is instantiated, insert a CIL_SRC_INFO node so that for said content it is a src_info node with the original file attached that is matched.
--- libsepol/cil/src/cil_resolve_ast.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
libsepol/cil/src/cil_resolve_ast.c +23 -0
@@ -2375,6 +2375,8 @@ int cil_resolve_in(struct cil_tree_node *current, struct cil_db *db)struct cil_in *in = current->data;struct cil_symtab_datum *block_datum =NULL ;struct cil_tree_node *block_node =NULL ; +struct cil_tree_node *src_node =NULL ; +struct cil_src_info *info =NULL ;int rc =SEPOL_ERR ; rc =cil_resolve_name (current, in->block_str,CIL_SYM_BLOCKS , db, &block_datum);
@@ -2395,6 +2397,27 @@ int cil_resolve_in(struct cil_tree_node *current, struct cil_db *db) } } +char *path =cil_tree_get_cil_path (current); +if (path !=NULL ) { +cil_src_info_init (&info); + info->kind =CIL_KEY_SRC_CIL ; + info->path = path; + +cil_tree_node_init (&src_node); + src_node->parent = block_node; + src_node->flavor =CIL_SRC_INFO ; + src_node->data = info; + +if (block_node->cl_head ==NULL ) { + block_node->cl_head = src_node; + }else { + block_node->cl_tail->next = src_node; + } + block_node->cl_tail = src_node; + + block_node = src_node; + } + rc =cil_copy_ast (db, current, block_node);if (rc !=SEPOL_OK ) {cil_tree_log (current,CIL_ERR ,"Failed to copy in-statement" );
Signature · 1 line
2.54.0
Quoted 11 lines · Rahul Sandhu
Ownership of the data copied in from an in statement currently resolves up to the parent block. This is because when looking up a corrosponding path with
cil_tree_get_cil_path(), the chain is walked up until a valid match is found fromcil_tree_get_next_path(). However, as the content that is inserted into the block does not originate from the same file as the file where the block is instantiated, insert aCIL_SRC_INFOnode so that for said content it is asrc_infonode with the original file attached that is matched.Signed-off-by Rahul Sandhu <[email protected]>
Unsurprisingly, the patch did not apply cleanly after the giant reformatting, but it was simple enough to make it work. I will handle the merge for this patch.
At any rate:
Quoted 48 lines
--- libsepol/cil/src/cil_resolve_ast.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)libsepol/cil/src/cil_resolve_ast.c +23
-1@@ -2375,6 +2375,8 @@ int cil_resolve_in(struct cil_tree_node *current, struct cil_db *db)struct cil_in *in = current->data;struct cil_symtab_datum *block_datum =NULL ;struct cil_tree_node *block_node =NULL ; +struct cil_tree_node *src_node =NULL ; +struct cil_src_info *info =NULL ;int rc =SEPOL_ERR ; rc =cil_resolve_name (current, in->block_str,CIL_SYM_BLOCKS , db, &block_datum);@@ -2395,6 +2397,27 @@ int cil_resolve_in(struct cil_tree_node *current, struct cil_db *db) } } +char *path =cil_tree_get_cil_path (current); +if (path !=NULL ) { +cil_src_info_init (&info); + info->kind =CIL_KEY_SRC_CIL ; + info->path = path; + +cil_tree_node_init (&src_node); + src_node->parent = block_node; + src_node->flavor =CIL_SRC_INFO ; + src_node->data = info; + +if (block_node->cl_head ==NULL ) { + block_node->cl_head = src_node; + }else { + block_node->cl_tail->next = src_node; + } + block_node->cl_tail = src_node; + + block_node = src_node; + } + rc =cil_copy_ast (db, current, block_node);if (rc !=SEPOL_OK ) {cil_tree_log (current,CIL_ERR ,"Failed to copy in-statement" ); --2.54.0
Quoted 12 lines · James Carter
Quoted 10 lines · Rahul Sandhu
Ownership of the data copied in from an in statement currently resolves up to the parent block. This is because when looking up a corrosponding path with
cil_tree_get_cil_path(), the chain is walked up until a valid match is found fromcil_tree_get_next_path(). However, as the content that is inserted into the block does not originate from the same file as the file where the block is instantiated, insert aCIL_SRC_INFOnode so that for said content it is asrc_infonode with the original file attached that is matched.
Quoted 9 lines
Quoted 1 line
Signed-off-by Rahul Sandhu <[email protected]>Unsurprisingly, the patch did not apply cleanly after the giant reformatting, but it was simple enough to make it work. I will handle the merge for this patch.
At any rate:Acked-by James Carter <[email protected]>
And it has been merged.
Thanks,
Jim
Quoted 48 lines
Quoted 48 lines
--- libsepol/cil/src/cil_resolve_ast.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)libsepol/cil/src/cil_resolve_ast.c +23
-1@@ -2375,6 +2375,8 @@ int cil_resolve_in(struct cil_tree_node *current, struct cil_db *db)struct cil_in *in = current->data;struct cil_symtab_datum *block_datum =NULL ;struct cil_tree_node *block_node =NULL ; +struct cil_tree_node *src_node =NULL ; +struct cil_src_info *info =NULL ;int rc =SEPOL_ERR ; rc =cil_resolve_name (current, in->block_str,CIL_SYM_BLOCKS , db, &block_datum);@@ -2395,6 +2397,27 @@ int cil_resolve_in(struct cil_tree_node *current, struct cil_db *db) } } +char *path =cil_tree_get_cil_path (current); +if (path !=NULL ) { +cil_src_info_init (&info); + info->kind =CIL_KEY_SRC_CIL ; + info->path = path; + +cil_tree_node_init (&src_node); + src_node->parent = block_node; + src_node->flavor =CIL_SRC_INFO ; + src_node->data = info; + +if (block_node->cl_head ==NULL ) { + block_node->cl_head = src_node; + }else { + block_node->cl_tail->next = src_node; + } + block_node->cl_tail = src_node; + + block_node = src_node; + } + rc =cil_copy_ast (db, current, block_node);if (rc !=SEPOL_OK ) {cil_tree_log (current,CIL_ERR ,"Failed to copy in-statement" ); --2.54.0