Project

General

Profile

lighttpd_ssi.patch

Updated last patch for 1.4.29 - eworm, 2011-12-08 22:05

View differences:

lighttpd-1.4.29/src/mod_ssi.c 2011-12-08 16:40:16.447013507 +0100
36 36
# include <sys/filio.h>
37 37
#endif
38 38

  
39
#define DEFAULT_MAX_SSI_RECURSION	25
40

  
41
URIHANDLER_FUNC(mod_ssi_physical_path);
42

  
39 43
#include "etag.h"
40 44
#include "version.h"
41 45

  
......
103 107
	config_values_t cv[] = {
104 108
		{ "ssi.extension",              NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION },       /* 0 */
105 109
		{ "ssi.content-type",           NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },      /* 1 */
110
		{ "ssi.max_recursion",          NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION },       /* 2 */
106 111
		{ NULL,                         NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
107 112
	};
108 113

  
......
116 121
		s = calloc(1, sizeof(plugin_config));
117 122
		s->ssi_extension  = array_init();
118 123
		s->content_type = buffer_init();
124
		s->ssi_max_recursion  = DEFAULT_MAX_SSI_RECURSION;
119 125

  
120 126
		cv[0].destination = s->ssi_extension;
121 127
		cv[1].destination = s->content_type;
128
		cv[2].destination = &(s->ssi_max_recursion);
122 129

  
123 130
		p->config_storage[i] = s;
124 131

  
......
617 624
				}
618 625
				break;
619 626
			case SSI_INCLUDE:
620
				chunkqueue_append_file(con->write_queue, p->stat_fn, 0, st.st_size);
627
				if (file_path) {
628
					/* don't process if #include file="..." is used */
629
					chunkqueue_append_file(con->write_queue, p->stat_fn, 0, st.st_size);
630
				} else {
631
					buffer *tmp = NULL;
632
					/* do recursive SSI expansion */
633

  
634
					b = chunkqueue_get_append_buffer(con->write_queue);
635

  
636
					/* prevents simple infinite loop */
637
					if (buffer_is_equal(con->physical.path, p->stat_fn)) {
638
						buffer_copy_string(b, "(error: include directives create an infinite loop)");
639
						break;
640
					}
641

  
642
					/* only allow predefined recursion depth */
643
					if (con->loops_per_request > p->conf.ssi_max_recursion) {
644
						buffer_copy_string(b, "(error: include directives recurse deeper than pre-defined max_recursion)");
645
						break;
646
					}
647

  
648
					tmp = buffer_init();
649
					/* save path of current document */
650
					buffer_copy_string_buffer(tmp, con->physical.path);
651
					/* next sub-document to parse */
652
					buffer_copy_string_buffer(con->physical.path, p->stat_fn);
653
					if (mod_ssi_physical_path(srv,con,p) != HANDLER_FINISHED) {
654
						/* the document was not processed, so write it as is */
655
						chunkqueue_append_file(con->write_queue, con->physical.path, 0, st.st_size);
656
					}
657
					/* restore saved path */
658
					buffer_copy_string_buffer(con->physical.path, tmp);
659
					buffer_free(tmp);
660
				}
621 661

  
622 662
				/* Keep the newest mtime of included files */
623 663
				if (st.st_mtime > include_file_last_mtime)
......
963 1003
	int ovec[N * 3];
964 1004
#endif
965 1005

  
966
	/* get a stream to the file */
1006
	/* for nested requests increase recursion depth */
1007
	con->loops_per_request++;
967 1008

  
968
	array_reset(p->ssi_vars);
969
	array_reset(p->ssi_cgi_env);
970
	buffer_copy_string_len(p->timefmt, CONST_STR_LEN("%a, %d %b %Y %H:%M:%S %Z"));
971
	p->sizefmt = 0;
972
	build_ssi_cgi_vars(srv, con, p);
1009
	/* initialize values only if in the first level of recursion */
1010
	if(con->loops_per_request <= 1) {
1011
		array_reset(p->ssi_vars);
1012
		array_reset(p->ssi_cgi_env);
1013
		buffer_copy_string_len(p->timefmt, CONST_STR_LEN("%a, %d %b %Y %H:%M:%S %Z"));
1014
		p->sizefmt = 0;
1015
		build_ssi_cgi_vars(srv, con, p);
1016
	}
973 1017
	p->if_is_false = 0;
974 1018

  
975 1019
	/* Reset the modified time of included files */
......
1105 1149
	/* reset physical.path */
1106 1150
	buffer_reset(con->physical.path);
1107 1151

  
1152
	/* for nested requests decrease recursion depth afterwards */
1153
	con->loops_per_request--;
1154

  
1108 1155
	return 0;
1109 1156
}
1110 1157

  
......
1116 1163

  
1117 1164
	PATCH(ssi_extension);
1118 1165
	PATCH(content_type);
1166
	PATCH(ssi_max_recursion);
1119 1167

  
1120 1168
	/* skip the first, the global context */
1121 1169
	for (i = 1; i < srv->config_context->used; i++) {
......
1133 1181
				PATCH(ssi_extension);
1134 1182
			} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("ssi.content-type"))) {
1135 1183
				PATCH(content_type);
1184
			} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("ssi.max_recursion"))) {
1185
				PATCH(ssi_max_recursion);
1136 1186
			}
1137 1187
		}
1138 1188
	}
lighttpd-1.4.29/src/mod_ssi.h 2011-12-08 16:40:42.269709467 +0100
16 16
typedef struct {
17 17
	array *ssi_extension;
18 18
	buffer *content_type;
19
	unsigned short ssi_max_recursion;
19 20
} plugin_config;
20 21

  
21 22
typedef struct {