Ticket #536: mod_ssi.c.2.diff

File mod_ssi.c.2.diff, 2.7 kB (added by marc@…, 19 months ago)

same as previous, with ssi.max_recursion default value set to 1

  • mod_ssi.c

     
    9898 
    9999        config_values_t cv[] = { 
    100100                { "ssi.extension",              NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION },       /* 0 */ 
     101                { "ssi.max_recursion",          NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION },       /* 0 */ 
    101102                { NULL,                         NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET } 
    102103        }; 
    103104 
     
    110111 
    111112                s = calloc(1, sizeof(plugin_config)); 
    112113                s->ssi_extension  = array_init(); 
     114                s->ssi_max_recursion  = 1; 
    113115 
    114116                cv[0].destination = s->ssi_extension; 
     117                cv[1].destination = s->ssi_max_recursion; 
    115118 
    116119                p->config_storage[i] = s; 
    117120 
     
    577580                                } 
    578581                                break; 
    579582                        case SSI_INCLUDE: 
    580                                 chunkqueue_append_file(con->send, p->stat_fn, 0, st.st_size); 
     583                                // do recursive SSI expansion 
     584 
     585                                // prevents infinite loop 
     586                                if (buffer_is_equal(con->physical.path, p->stat_fn)) { 
     587                                        buffer_copy_string(srv->tmp_buf, "<!-- your include directives create an infinite loop; aborting -->"); 
     588                                        chunkqueue_append_buffer(con->write_queue, srv->tmp_buf); 
     589                                        break; 
     590                                } 
     591 
     592                                // only allow predefined recursion depth 
     593                                if (con->loops_per_request > p->conf.ssi_max_recursion) { 
     594                                        buffer_copy_string(srv->tmp_buf, "<!-- your include directives recurse deeper than pre-defined max_recursion; aborting -->"); 
     595                                        chunkqueue_append_buffer(con->write_queue, srv->tmp_buf); 
     596                                        break; 
     597                                } 
     598 
     599                                tmp = buffer_init(); 
     600                                buffer_copy_string_buffer(tmp, con->physical.path); // save path of current document 
     601                                buffer_copy_string_buffer(con->physical.path, p->stat_fn); // next sub-document to parse 
     602                                if (mod_ssi_physical_path(srv,con,p) != HANDLER_FINISHED) { 
     603                                        // the document was not processed, so write it as is 
     604                                        chunkqueue_append_file(con->send, con->physical.path, 0, st.st_size); 
     605                                } 
     606                                buffer_copy_string_buffer(con->physical.path, tmp); // restore saved path 
     607                                buffer_free(tmp); 
    581608                                break; 
    582609                        } 
    583610                } else { 
     
    10171044        plugin_config *s = p->config_storage[0]; 
    10181045 
    10191046        PATCH_OPTION(ssi_extension); 
     1047        PATCH_OPTION(ssi_max_recursion); 
    10201048 
    10211049        /* skip the first, the global context */ 
    10221050        for (i = 1; i < srv->config_context->used; i++) { 
     
    10331061                        if (buffer_is_equal_string(du->key, CONST_STR_LEN("ssi.extension"))) { 
    10341062                                PATCH_OPTION(ssi_extension); 
    10351063                        } 
     1064                        if (buffer_is_equal_string(du->key, CONST_STR_LEN("ssi.max_recursion"))) { 
     1065                                PATCH_OPTION(ssi_max_recursion); 
     1066                        } 
    10361067                } 
    10371068        } 
    10381069 
     
    10451076 
    10461077        if (con->physical.path->used == 0) return HANDLER_GO_ON; 
    10471078 
     1079        con->loops_per_request++; 
     1080 
    10481081        mod_ssi_patch_connection(srv, con, p); 
    10491082 
    10501083        for (k = 0; k < p->conf.ssi_extension->used; k++) {