add error checking to fail-out when failing to render gophermap section

Signed-off-by: kim (grufwub) <grufwub@gmail.com>
This commit is contained in:
kim (grufwub) 2020-05-14 19:15:51 +01:00
parent d16d7b6972
commit d9684e06c8
2 changed files with 16 additions and 5 deletions

View File

@ -36,6 +36,7 @@ func setupInitialCgiEnviron(path, charset string) []string {
func generateCgiEnvironment(responder *Responder) []string {
/* Get initial CgiEnv variables */
env := Config.CgiEnv
env = append(env, envKeyValue("SERVER_NAME", responder.Host.Name())) /* MUST be set to name of server host client is connecting to */
env = append(env, envKeyValue("SERVER_PORT", responder.Host.Port())) /* MUST be set to the server port that client is connecting to */
env = append(env, envKeyValue("REMOTE_ADDR", responder.Client.Ip())) /* Remote client addr, MUST be set */

View File

@ -75,6 +75,7 @@ func (gc *GophermapContents) Render(responder *Responder) *GophorError {
gophorErr = line.Render(responder)
if gophorErr != nil {
Config.SysLog.Error("", "Error executing gophermap contents: %s\n", gophorErr.Error())
return &GophorError{ InvalidGophermapErr, gophorErr }
}
}
@ -86,7 +87,11 @@ func (gc *GophermapContents) Load() *GophorError {
/* Load the gophermap into memory as gophermap sections */
var gophorErr *GophorError
gc.Sections, gophorErr = readGophermap(gc.Request)
return gophorErr
if gophorErr != nil {
return &GophorError{ InvalidGophermapErr, gophorErr }
} else {
return nil
}
}
func (gc *GophermapContents) Clear() {
@ -226,11 +231,15 @@ func readGophermap(request *Request) ([]GophermapSection, *GophorError) {
case TypeSubGophermap:
/* Parse new RequestPath and parameters */
subRequest, gophorErr := parseLineRequestString(request.Path, line[1:])
if gophorErr != nil || subRequest.Path.Relative() == "" || subRequest.Path.Relative() == request.Path.Relative() {
/* Either path parsing failed, or we've been supplied same gophermap, and recursion is
if gophorErr != nil {
/* Failed parsing line request string, set returnErr and request finish */
returnErr = gophorErr
return true
} else if subRequest.Path.Relative() == "" || subRequest.Path.Relative() == request.Path.Relative() {
/* Failed parsing line request string, or we've been supplied same gophermap, and recursion is
* recursion is recursion is bad kids! Set return error and request finish.
*/
returnErr = gophorErr
returnErr = &GophorError{ InvalidRequestErr, nil }
return true
}
@ -238,7 +247,8 @@ func readGophermap(request *Request) ([]GophermapSection, *GophorError) {
stat, err := os.Stat(subRequest.Path.Absolute())
if (err != nil) || (stat.Mode() & os.ModeDir != 0) {
/* File read error or is directory */
break
returnErr = &GophorError{ FileStatErr, err }
return true
}
/* Check if we've been supplied subgophermap or regular file */