mirror of
https://tildegit.org/solderpunk/molly-brown.git
synced 2025-04-13 09:29:46 +00:00
Be a lot more careful in parsing CGI response header. Closes #42.
This commit is contained in:
parent
308b8fe128
commit
0f833ba57b
1 changed files with 18 additions and 4 deletions
22
dynamic.go
22
dynamic.go
|
@ -80,9 +80,22 @@ func handleCGI(config SysConfig, path string, cgiPath string, URL *url.URL, logE
|
|||
logEntry.Status = 42
|
||||
return
|
||||
}
|
||||
header, _, _ := bufio.NewReader(strings.NewReader(string(response))).ReadLine()
|
||||
status, err := strconv.Atoi(strings.Fields(string(header))[0])
|
||||
if err != nil {
|
||||
header, _, err := bufio.NewReader(strings.NewReader(string(response))).ReadLine()
|
||||
if err != nil || len(header) == 0 {
|
||||
log.Println("Unable to parse first line of output from CGI process " + path + " as valid Gemini response header. Line was: " + string(header))
|
||||
conn.Write([]byte("42 CGI error!\r\n"))
|
||||
logEntry.Status = 42
|
||||
return
|
||||
}
|
||||
header_fields := strings.Fields(string(header))
|
||||
if len(header_fields) == 0 {
|
||||
log.Println("Unable to parse first line of output from CGI process " + path + " as valid Gemini response header. Line was: " + string(header))
|
||||
conn.Write([]byte("42 CGI error!\r\n"))
|
||||
logEntry.Status = 42
|
||||
return
|
||||
}
|
||||
status, err := strconv.Atoi(header_fields[0])
|
||||
if err != nil || status < 10 || status > 70 {
|
||||
log.Println("Unable to parse first line of output from CGI process " + path + " as valid Gemini response header. Line was: " + string(header))
|
||||
conn.Write([]byte("42 CGI error!\r\n"))
|
||||
logEntry.Status = 42
|
||||
|
@ -144,8 +157,9 @@ func handleSCGI(URL *url.URL, scgiPath string, scgiSocket string, config SysConf
|
|||
first = false
|
||||
lines := strings.SplitN(string(buffer), "\r\n", 2)
|
||||
status, err := strconv.Atoi(strings.Fields(lines[0])[0])
|
||||
if err != nil {
|
||||
if err != nil || status < 10 || status > 70 {
|
||||
conn.Write([]byte("42 CGI error!\r\n"))
|
||||
log.Println("Unable to parse first line of output from SCGI socket " + scgiSocket + " as valid Gemini response header. Line was: " + lines[0])
|
||||
logEntry.Status = 42
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue