Ticket #606 (closed defect: invalid)

Opened 2 years ago

Last modified 3 weeks ago

SSI #echo directive with custom #set variable didn't work

Reported by: matthew@cnfug.org Assigned to: jan
Priority: normal Milestone:
Component: mod_ssi Version: 1.4.11
Severity: normal Keywords: ssi echo set patch
Cc: Blocking: 679
Need Feedback: 0

Description

The following patch corret the #echo directive with custom #set variable, and #echo directive in recursion #include directive enviroment, the "recursion #include directive" code is based on marc@r4l.com's code, thanks marc.

With this patch, following SSI code willl work.

test.shtml

<!--#set var="doc_title" value="This is a test" -->
<!--#include virtual="header.shtml" -->

content of header.shtml

<html>
<head>
<title><!--#echo var="doc_title" --></title>
</head>
<body>
test
</body>
</html>
--- mod_ssi.c	Sun Apr  2 01:20:30 2006
+++ mod_ssi.c.modify	Sun Apr  2 01:21:05 2006
@@ -36,6 +36,9 @@
 #include <sys/filio.h>
 #endif
 
+/* determine if process finished */
+int h_finished = 0;
+
 /* init the plugin data */
 INIT_FUNC(mod_ssi_init) {
 	plugin_data *p;
@@ -57,7 +60,7 @@ FREE_FUNC(mod_ssi_free) {
 	UNUSED(srv);
 	
 	if (!p) return HANDLER_GO_ON;
-	
+
 	if (p->config_storage) {
 		size_t i;
 		for (i = 0; i < srv->config_context->used; i++) {
@@ -286,6 +289,37 @@ static int build_ssi_cgi_vars(server *sr
 	return 0;
 }
 
+URIHANDLER_FUNC(mod_ssi_physical_path) {
+	plugin_data *p = p_d;
+	size_t k;
+	
+	if (con->physical.path->used == 0) return HANDLER_GO_ON;
+
+	con->loops_per_request++;
+	
+	mod_ssi_patch_connection(srv, con, p);
+	
+	for (k = 0; k < p->conf.ssi_extension->used; k++) {
+		data_string *ds = (data_string *)p->conf.ssi_extension->data[k];
+		
+		if (ds->value->used == 0) continue;
+		
+		if (buffer_is_equal_right_len(con->physical.path, ds->value, ds->value->used - 1)) {
+			/* handle ssi-request */
+			
+			if (mod_ssi_handle_request(srv, con, p)) {
+				/* on error */
+				con->http_status = 500;
+			}
+			
+			return HANDLER_FINISHED;
+		}
+	}
+	
+	/* not found */
+	return HANDLER_GO_ON;
+}
+
 static int process_ssi_stmt(server *srv, connection *con, plugin_data *p, 
 			    const char **l, size_t n) {
 	size_t i, ssicmd = 0;
@@ -467,7 +501,11 @@ static int process_ssi_stmt(server *srv,
 			if (NULL != (ds = (data_string *)array_get_element(p->ssi_cgi_env, var_val))) {
 				buffer_copy_string_buffer(b, ds->value);
 			} else {
-				buffer_copy_string(b, "(none)");
+				if (NULL != (ds = (data_string *)array_get_element(p->ssi_vars, var_val))) {
+					buffer_copy_string_buffer(b, ds->value);
+				} else {
+					buffer_copy_string(b, "(none)");
+				}
 			}
 			
 			break;
@@ -481,6 +519,7 @@ static int process_ssi_stmt(server *srv,
 		const char * file_path = NULL, *virt_path = NULL;
 		struct stat st;
 		char *sl;
+		buffer *tmp;
 		
 		for (i = 2; i < n; i += 2) {
 			if (0 == strcmp(l[i], "file")) {
@@ -574,7 +613,26 @@ static int process_ssi_stmt(server *srv,
 				}
 				break;
 			case SSI_INCLUDE:
-				chunkqueue_append_file(con->write_queue, p->stat_fn, 0, st.st_size);
+                                /* do recursive SSI expansion */
+                                /* prevents infinite loop */
+                                if (con->loops_per_request > 25 || buffer_is_equal(con->physical.path, p->stat_fn)) {
+                                        buffer_copy_string(srv->tmp_buf, "<!-- your include directives create an infinite loop, aborting -->");
+                                        chunkqueue_append_buffer(con->write_queue, srv->tmp_buf);
+                                        break;
+                                }
+
+                                tmp = buffer_init();
+                                buffer_copy_string_buffer(tmp, con->physical.path); /* save path of current document */
+                                buffer_copy_string_buffer(con->physical.path, p->stat_fn); /* next sub-document to parse */
+                                if (mod_ssi_physical_path(srv, con, p) != HANDLER_FINISHED) {
+                                        /* the document was not processed, so write it as is */
+                                        chunkqueue_append_file(con->write_queue, con->physical.path, 0, st.st_size);
+				} else {
+					h_finished = 1;	
+				}
+                                buffer_copy_string_buffer(con->physical.path, tmp); /* restore saved path */
+                                buffer_free(tmp);
+				
 				break;
 			}
 		} else {
@@ -897,7 +955,11 @@ static int mod_ssi_handle_request(server
 	
 	/* get a stream to the file */
 	
-	array_reset(p->ssi_vars);
+	if (h_finished == 1)
+	{
+		array_reset(p->ssi_vars);
+		h_finished = 0;
+	}
 	array_reset(p->ssi_cgi_env);
 	buffer_copy_string(p->timefmt, "%a, %d %b %Y %H:%M:%S %Z");
 	p->sizefmt = 0;
@@ -1038,35 +1100,6 @@ static int mod_ssi_patch_connection(serv
 }
 #undef PATCH
 
-URIHANDLER_FUNC(mod_ssi_physical_path) {
-	plugin_data *p = p_d;
-	size_t k;
-	
-	if (con->physical.path->used == 0) return HANDLER_GO_ON;
-	
-	mod_ssi_patch_connection(srv, con, p);
-	
-	for (k = 0; k < p->conf.ssi_extension->used; k++) {
-		data_string *ds = (data_string *)p->conf.ssi_extension->data[k];
-		
-		if (ds->value->used == 0) continue;
-		
-		if (buffer_is_equal_right_len(con->physical.path, ds->value, ds->value->used - 1)) {
-			/* handle ssi-request */
-			
-			if (mod_ssi_handle_request(srv, con, p)) {
-				/* on error */
-				con->http_status = 500;
-			}
-			
-			return HANDLER_FINISHED;
-		}
-	}
-	
-	/* not found */
-	return HANDLER_GO_ON;
-}
-
 /* this function is called at dlopen() time and inits the callbacks */
 
 int mod_ssi_plugin_init(plugin *p) {
@@ -1082,3 +1115,4 @@ int mod_ssi_plugin_init(plugin *p) {
 	
 	return 0;
 }
+

Attachments

Change History

01/10/2008 10:16:17 AM changed by anonymous

  • priority changed from normal to high.
  • blocking changed.
  • pending set to 1.
  • severity changed from normal to major.

01/10/2008 10:16:33 AM changed by anonymous

  • pending deleted.

01/10/2008 10:20:33 AM changed by anonymous

  • priority changed from high to highest.
  • severity changed from major to critical.

03/07/2008 10:42:08 AM changed by Lfe

  • keywords changed from ssi #cho #set #include to ssi echo set patch.
  • priority changed from highest to normal.
  • blocking set to 679.
  • severity changed from critical to normal.

Have you tried this in a later version of lighttpd?

mod_ssi may be a bit broken (i've had semi-random issues as well) but this isn't critical. Generally, you'd want to move from ssi since it's blocking anyway.

04/25/2008 09:31:52 AM changed by stbuehler

  • status changed from new to closed.
  • resolution set to invalid.

No feedback, patch is ugly and ssi shouldn't be used anyway.


Add/Change #606 (SSI #echo directive with custom #set variable didn't work)




Change Properties
Action