Skip to content
Snippets Groups Projects
Commit fa900dea authored by Stephan Bosch's avatar Stephan Bosch
Browse files

Include: added runtime check for circular include.

parent 59192a4e
No related branches found
No related tags found
No related merge requests found
...@@ -472,7 +472,8 @@ bool ext_include_execute_include ...@@ -472,7 +472,8 @@ bool ext_include_execute_include
ctx = ext_include_get_interpreter_context(renv->interp); ctx = ext_include_get_interpreter_context(renv->interp);
block_id = included->block_id; block_id = included->block_id;
sieve_runtime_trace(renv, "INCLUDE command (script: %s, id: %d block: %d) START::", sieve_runtime_trace(renv,
"INCLUDE command (script: %s, id: %d block: %d) START::",
sieve_script_name(included->script), include_id, block_id); sieve_script_name(included->script), include_id, block_id);
if ( ctx->parent == NULL ) { if ( ctx->parent == NULL ) {
...@@ -486,13 +487,15 @@ bool ext_include_execute_include ...@@ -486,13 +487,15 @@ bool ext_include_execute_include
/* We are the top-level interpreter instance */ /* We are the top-level interpreter instance */
/* Activate block for included script */ /* Activate block for included script */
if ( !sieve_binary_block_set_active(renv->sbin, block_id, &this_block_id) ) { if ( !sieve_binary_block_set_active(renv->sbin, block_id, &this_block_id) )
{
sieve_runtime_trace_error(renv, "invalid block id: %d", block_id); sieve_runtime_trace_error(renv, "invalid block id: %d", block_id);
result = SIEVE_EXEC_BIN_CORRUPT; result = SIEVE_EXEC_BIN_CORRUPT;
} }
if ( result > 0 ) { if ( result > 0 ) {
/* Create interpreter for top-level included script (first sub-interpreter) /* Create interpreter for top-level included script
* (first sub-interpreter)
*/ */
subinterp = sieve_interpreter_create(renv->sbin, ehandler); subinterp = sieve_interpreter_create(renv->sbin, ehandler);
...@@ -502,8 +505,8 @@ bool ext_include_execute_include ...@@ -502,8 +505,8 @@ bool ext_include_execute_include
/* Activate and start the top-level included script */ /* Activate and start the top-level included script */
result = ( sieve_interpreter_start result = ( sieve_interpreter_start
(subinterp, renv->msgdata, renv->scriptenv, renv->msgctx, renv->result, (subinterp, renv->msgdata, renv->scriptenv, renv->msgctx,
&interrupted) == 1 ); renv->result, &interrupted) == 1 );
} else } else
result = SIEVE_EXEC_BIN_CORRUPT; result = SIEVE_EXEC_BIN_CORRUPT;
} }
...@@ -542,16 +545,29 @@ bool ext_include_execute_include ...@@ -542,16 +545,29 @@ bool ext_include_execute_include
result = ( sieve_interpreter_continue(subinterp, &interrupted) == 1 ); result = ( sieve_interpreter_continue(subinterp, &interrupted) == 1 );
} else { } else {
if ( curctx->inc_block_id >= SBIN_SYSBLOCK_LAST ) { if ( curctx->inc_block_id >= SBIN_SYSBLOCK_LAST ) {
struct ext_include_interpreter_context *pctx;
/* Sub-include requested */ /* Sub-include requested */
/* FIXME: Check circular include during interpretation as well. /* Check circular include during interpretation as well.
* Let's not trust user-owned binaries. * Let's not trust binaries.
*/ */
pctx = curctx;
while ( result > 0 && pctx != NULL ) {
if ( curctx->inc_block_id == pctx->block_id ) {
sieve_runtime_trace_error(renv,
"circular include for block id: %d",
curctx->inc_block_id);
result = SIEVE_EXEC_BIN_CORRUPT;
}
pctx = pctx->parent;
}
/* Activate the sub-include's block */ /* Activate the sub-include's block */
if ( !sieve_binary_block_set_active if ( result > 0 && !sieve_binary_block_set_active
(renv->sbin, curctx->inc_block_id, NULL) ) { (renv->sbin, curctx->inc_block_id, NULL) ) {
sieve_runtime_trace_error(renv, "invalid block id: %d", curctx->inc_block_id); sieve_runtime_trace_error(renv, "invalid block id: %d",
curctx->inc_block_id);
result = SIEVE_EXEC_BIN_CORRUPT; result = SIEVE_EXEC_BIN_CORRUPT;
} }
...@@ -583,7 +599,8 @@ bool ext_include_execute_include ...@@ -583,7 +599,8 @@ bool ext_include_execute_include
} }
} }
} else } else
sieve_runtime_trace(renv, "INCLUDE command (block: %d) END ::", curctx->block_id); sieve_runtime_trace(renv, "INCLUDE command (block: %d) END ::",
curctx->block_id);
/* Free any sub-interpreters that might still be active */ /* Free any sub-interpreters that might still be active */
while ( curctx != NULL && curctx->parent != NULL ) { while ( curctx != NULL && curctx->parent != NULL ) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment

Consent

On this website, we use the web analytics service Matomo to analyze and review the use of our website. Through the collected statistics, we can improve our offerings and make them more appealing for you. Here, you can decide whether to allow us to process your data and set corresponding cookies for these purposes, in addition to technically necessary cookies. Further information on data protection—especially regarding "cookies" and "Matomo"—can be found in our privacy policy. You can withdraw your consent at any time.