Project

General

Profile

mod_ssi.c.2.diff

same as previous, with ssi.max_recursion default value set to 1 -- marc - Anonymous, 2007-02-28 17:29

View differences:

mod_ssi.c (working copy)
98 98

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

  
......
110 111

  
111 112
		s = calloc(1, sizeof(plugin_config));
112 113
		s->ssi_extension  = array_init();
114
		s->ssi_max_recursion  = 1;
113 115

  
114 116
		cv[0].destination = s->ssi_extension;
117
		cv[1].destination = s->ssi_max_recursion;
115 118

  
116 119
		p->config_storage[i] = s;
117 120

  
......
577 580
				}
578 581
				break;
579 582
			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);
581 608
				break;
582 609
			}
583 610
		} else {
......
1017 1044
	plugin_config *s = p->config_storage[0];
1018 1045

  
1019 1046
	PATCH_OPTION(ssi_extension);
1047
	PATCH_OPTION(ssi_max_recursion);
1020 1048

  
1021 1049
	/* skip the first, the global context */
1022 1050
	for (i = 1; i < srv->config_context->used; i++) {
......
1033 1061
			if (buffer_is_equal_string(du->key, CONST_STR_LEN("ssi.extension"))) {
1034 1062
				PATCH_OPTION(ssi_extension);
1035 1063
			}
1064
			if (buffer_is_equal_string(du->key, CONST_STR_LEN("ssi.max_recursion"))) {
1065
				PATCH_OPTION(ssi_max_recursion);
1066
			}
1036 1067
		}
1037 1068
	}
1038 1069

  
......
1045 1076

  
1046 1077
	if (con->physical.path->used == 0) return HANDLER_GO_ON;
1047 1078

  
1079
	con->loops_per_request++;
1080

  
1048 1081
	mod_ssi_patch_connection(srv, con, p);
1049 1082

  
1050 1083
	for (k = 0; k < p->conf.ssi_extension->used; k++) {