Project

General

Profile

mod_ssi-recursion-1.5.0svn2299.patch

Patch for this against 1.5.0-svn r2299. -- gw.lighttpd - Anonymous, 2008-08-31 19:32

View differences:

src/mod_ssi.c 2008-08-31 20:17:02.000000000 +0200
37 37
#include <sys/filio.h>
38 38
#endif
39 39

  
40
#define DEFAULT_MAX_SSI_RECURSION	25
41

  
42
URIHANDLER_FUNC(mod_ssi_physical_path);
43

  
40 44
/* init the plugin data */
41 45
INIT_FUNC(mod_ssi_init) {
42 46
	plugin_data *p;
......
98 102

  
99 103
	config_values_t cv[] = {
100 104
		{ "ssi.extension",              NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION },       /* 0 */
105
		{ "ssi.max_recursion",          NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION },       /* 1 */
101 106
		{ NULL,                         NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
102 107
	};
103 108

  
......
110 115

  
111 116
		s = calloc(1, sizeof(plugin_config));
112 117
		s->ssi_extension  = array_init();
118
		s->ssi_max_recursion  = DEFAULT_MAX_SSI_RECURSION;
113 119

  
114 120
		cv[0].destination = s->ssi_extension;
121
		cv[1].destination = &(s->ssi_max_recursion);
115 122

  
116 123
		p->config_storage[i] = s;
117 124

  
......
549 556
		}
550 557

  
551 558
		if (0 == stat(p->stat_fn->ptr, &st)) {
559
			buffer *tmp = NULL;
552 560
			time_t t = st.st_mtime;
553 561

  
554 562
			switch (ssicmd) {
......
577 585
				}
578 586
				break;
579 587
			case SSI_INCLUDE:
580
				chunkqueue_append_file(con->send, p->stat_fn, 0, st.st_size);
588
				if (file_path) {
589
					/* don't process if #include file="..." is used */
590
					chunkqueue_append_file(con->send, p->stat_fn, 0, st.st_size);
591
				} else {
592
					/* do recursive SSI expansion */
593
					b = chunkqueue_get_append_buffer(con->send);
594

  
595
					/* prevents infinite loop */
596
					if (buffer_is_equal(con->physical.path, p->stat_fn)) {
597
						buffer_copy_string(b, "<!-- your include directives create an infinite loop; aborting -->");
598
						break;
599
					}
600

  
601
					/* only allow predefined recursion depth */
602
					if (con->loops_per_request > p->conf.ssi_max_recursion) {
603
						buffer_copy_string(b, "<!-- your include directives recurse deeper than pre-defined max_recursion; aborting -->");
604
						break;
605
					}
606

  
607
					tmp = buffer_init();
608
					/* save path of current document */
609
					buffer_copy_string_buffer(tmp, con->physical.path);
610
					/* next sub-document to parse */
611
					buffer_copy_string_buffer(con->physical.path, p->stat_fn);
612
					if (mod_ssi_physical_path(srv,con,p) != HANDLER_FINISHED) {
613
						/* the document was not processed, so write it as is */
614
						chunkqueue_append_file(con->send, con->physical.path, 0, st.st_size);
615
					}
616
					/* restore saved path */
617
					buffer_copy_string_buffer(con->physical.path, tmp);
618
					buffer_free(tmp);
619
				}
581 620
				break;
582 621
			}
583 622
		} else {
......
1015 1054
	plugin_config *s = p->config_storage[0];
1016 1055

  
1017 1056
	PATCH_OPTION(ssi_extension);
1057
	PATCH_OPTION(ssi_max_recursion);
1018 1058

  
1019 1059
	/* skip the first, the global context */
1020 1060
	for (i = 1; i < srv->config_context->used; i++) {
......
1030 1070

  
1031 1071
			if (buffer_is_equal_string(du->key, CONST_STR_LEN("ssi.extension"))) {
1032 1072
				PATCH_OPTION(ssi_extension);
1073
			} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("ssi.max_recursion"))) {
1074
				PATCH_OPTION(ssi_max_recursion);
1033 1075
			}
1034 1076
		}
1035 1077
	}
......
1043 1085

  
1044 1086
	if (con->physical.path->used == 0) return HANDLER_GO_ON;
1045 1087

  
1088
	con->loops_per_request++;
1089

  
1046 1090
	mod_ssi_patch_connection(srv, con, p);
1047 1091

  
1048 1092
	for (k = 0; k < p->conf.ssi_extension->used; k++) {
1049
-- src/mod_ssi.h.orig	2008-08-31 20:16:58.000000000 +0200
1093
++ src/mod_ssi.h	2008-08-31 20:17:02.000000000 +0200
......
15 15

  
16 16
typedef struct {
17 17
	array *ssi_extension;
18
	unsigned short ssi_max_recursion;
18 19
} plugin_config;
19 20

  
20 21
typedef struct {