Ticket #536: mod_ssi_recursion-1.4.15.2.patch

File mod_ssi_recursion-1.4.15.2.patch, 4.0 kB (added by dustin@…, 17 months ago)

recursive SSI for 1.4.15 (minus whitespace garbage from previous patch)

  • src/mod_ssi.c

    # HG changeset patch
    # User Dustin Sallings <dustin@spy.net>
    # Date 1178911716 25200
    # Node ID b4b4bbfe6d25fc2420e81b6a92376876f89cf511
    # Parent  ea8607208d0e0278392e07debbb31bbbadb48cb3
    imported patch mod_ssi_recursion
    
    diff -r ea8607208d0e -r b4b4bbfe6d25 src/mod_ssi.c
    a b  
    3636#include <sys/filio.h> 
    3737#endif 
    3838 
     39#define DEFAULT_MAX_SSI_RECURSION 25 
     40 
    3941/* init the plugin data */ 
    4042INIT_FUNC(mod_ssi_init) { 
    4143        plugin_data *p; 
     
    9496#endif 
    9597 
    9698        config_values_t cv[] = { 
    97                 { "ssi.extension",              NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION },       /* 0 */ 
    98                 { NULL,                         NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET } 
     99                { "ssi.extension",                              NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION },               /* 0 */ 
     100                { "ssi.max_recursion",                  NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION },               /* 1 */ 
     101                { NULL,                                                 NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET } 
    99102        }; 
    100103 
    101104        if (!p) return HANDLER_ERROR; 
     
    107110 
    108111                s = calloc(1, sizeof(plugin_config)); 
    109112                s->ssi_extension  = array_init(); 
     113                s->ssi_max_recursion  = DEFAULT_MAX_SSI_RECURSION; 
    110114 
    111115                cv[0].destination = s->ssi_extension; 
     116                cv[1].destination = &(s->ssi_max_recursion); 
    112117 
    113118                p->config_storage[i] = s; 
    114119 
     
    546551                } 
    547552 
    548553                if (0 == stat(p->stat_fn->ptr, &st)) { 
     554                        buffer *tmp = NULL; 
    549555                        time_t t = st.st_mtime; 
    550556 
    551557                        switch (ssicmd) { 
     
    574580                                } 
    575581                                break; 
    576582                        case SSI_INCLUDE: 
    577                                 chunkqueue_append_file(con->write_queue, 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                                /* save path of current document */ 
     601                                buffer_copy_string_buffer(tmp, con->physical.path); 
     602                                /* next sub-document to parse */ 
     603                                buffer_copy_string_buffer(con->physical.path, p->stat_fn); 
     604                                if (mod_ssi_physical_path(srv,con,p) != HANDLER_FINISHED) { 
     605                                        /* the document was not processed, so write it as is */ 
     606                                        chunkqueue_append_file(con->write_queue, con->physical.path, 0, st.st_size); 
     607                                } 
     608                                /* restore saved path */ 
     609                                buffer_copy_string_buffer(con->physical.path, tmp); 
     610                                buffer_free(tmp); 
    578611                                break; 
    579612                        } 
    580613                } else { 
     
    10231056        plugin_config *s = p->config_storage[0]; 
    10241057 
    10251058        PATCH(ssi_extension); 
     1059        PATCH(ssi_max_recursion); 
    10261060 
    10271061        /* skip the first, the global context */ 
    10281062        for (i = 1; i < srv->config_context->used; i++) { 
     
    10391073                        if (buffer_is_equal_string(du->key, CONST_STR_LEN("ssi.extension"))) { 
    10401074                                PATCH(ssi_extension); 
    10411075                        } 
     1076                        if (buffer_is_equal_string(du->key, CONST_STR_LEN("ssi.max_recursion"))) { 
     1077                                PATCH(ssi_max_recursion); 
     1078                        } 
    10421079                } 
    10431080        } 
    10441081 
     
    10511088        size_t k; 
    10521089 
    10531090        if (con->physical.path->used == 0) return HANDLER_GO_ON; 
     1091 
     1092        con->loops_per_request++; 
    10541093 
    10551094        mod_ssi_patch_connection(srv, con, p); 
    10561095 
  • src/mod_ssi.h

    diff -r ea8607208d0e -r b4b4bbfe6d25 src/mod_ssi.h
    a b  
    1515 
    1616typedef struct { 
    1717        array *ssi_extension; 
     18        unsigned short ssi_max_recursion; 
    1819} plugin_config; 
    1920 
    2021typedef struct {