[mapserver-commits] r8826 - branches/branch-5-2/mapserver
svn at osgeo.org
svn at osgeo.org
Wed Mar 25 23:09:48 EDT 2009
Author: sdlime
Date: 2009-03-25 23:09:48 -0400 (Wed, 25 Mar 2009)
New Revision: 8826
Modified:
branches/branch-5-2/mapserver/maptemplate.c
Log:
Switched to a general validation funtion for templates.
Modified: branches/branch-5-2/mapserver/maptemplate.c
===================================================================
--- branches/branch-5-2/mapserver/maptemplate.c 2009-03-26 01:13:02 UTC (rev 8825)
+++ branches/branch-5-2/mapserver/maptemplate.c 2009-03-26 03:09:48 UTC (rev 8826)
@@ -41,6 +41,20 @@
static char *processLine(mapservObj *mapserv, char *instr, FILE *stream, int mode);
+static int isValidTemplate(FILE *stream, const char *filename)
+{
+ char buffer[MS_BUFFER_LENGTH];
+
+ if(fgets(buffer, MS_BUFFER_LENGTH, stream) != NULL) {
+ if(!msCaseFindSubstring(buffer, MS_TEMPLATE_MAGIC_STRING)) {
+ msSetError(MS_WEBERR, "Missing magic string, %s doesn't look like a MapServer template.", "isValidTemplate()", filename);
+ return MS_FALSE;
+ }
+ }
+
+ return MS_TRUE;
+}
+
/*
* Redirect to (only use in CGI)
*
@@ -1064,16 +1078,9 @@
return MS_FAILURE;
}
- /* examine 1st line, must contain a magic string to continue */
- if(fgets(buffer, MS_BUFFER_LENGTH, includeStream) != NULL) {
- if(!msCaseFindSubstring(buffer, MS_TEMPLATE_MAGIC_STRING)) {
- fclose(includeStream);
- msSetError(MS_WEBERR, "Missing magic string, this doesn't look like a MapServer template.", "processIncludeTag()");
- return MS_FAILURE;
- }
- } else { /* empty template, just return */
+ if(isValidTemplate(includeStream, src) != MS_TRUE) {
fclose(includeStream);
- return MS_SUCCESS;
+ return MS_FAILURE;
}
while(fgets(buffer, MS_BUFFER_LENGTH, includeStream) != NULL)
@@ -2874,6 +2881,11 @@
return(NULL);
}
+ if(isValidTemplate(stream, join->header) != MS_TRUE) {
+ fclose(stream);
+ return NULL;
+ }
+
/* echo file to the output buffer, no substitutions */
while(fgets(line, MS_BUFFER_LENGTH, stream) != NULL) outbuf = msStringConcatenate(outbuf, line);
@@ -2884,7 +2896,12 @@
msSetError(MS_IOERR, "Error while opening join template file %s.", "processOneToManyJoin()", join->template);
return(NULL);
}
-
+
+ if(isValidTemplate(stream, join->template) != MS_TRUE) {
+ fclose(stream);
+ return NULL;
+ }
+
records = MS_TRUE;
}
@@ -2899,6 +2916,7 @@
}
rewind(stream);
+ fgets(line, MS_BUFFER_LENGTH, stream); /* skip the first line since it's the magic string */
} /* next record */
if(records==MS_TRUE && join->footer) {
@@ -2907,6 +2925,11 @@
return(NULL);
}
+ if(isValidTemplate(stream, join->footer) != MS_TRUE) {
+ fclose(stream);
+ return NULL;
+ }
+
/* echo file to the output buffer, no substitutions */
while(fgets(line, MS_BUFFER_LENGTH, stream) != NULL) outbuf = msStringConcatenate(outbuf, line);
@@ -3442,16 +3465,9 @@
return MS_FAILURE;
}
- /* examine 1st line, must contain a magic string to continue */
- if(fgets(line, MS_BUFFER_LENGTH, stream) != NULL) {
- if(!msCaseFindSubstring(line, MS_TEMPLATE_MAGIC_STRING)) {
- fclose(stream);
- msSetError(MS_WEBERR, "Missing magic string, this doesn't look like a MapServer template.", "msReturnPage()");
- return MS_FAILURE;
- }
- } else { /* file is empty, technically not a error */
+ if(isValidTemplate(stream, html) != MS_TRUE) {
fclose(stream);
- return MS_SUCCESS;
+ return MS_FAILURE;
}
if(papszBuffer) {
More information about the mapserver-commits
mailing list