commit f1569079ca898d54e52a26b0bd1b5cc869310608 Author: David Fifield david@bamsoftware.com Date: Wed Jan 18 22:24:54 2017 -0800
Bug 21261: forbid duplicate method names in TOR_PT_SERVER_BINDADDR. --- pt.go | 7 +++++++ pt_test.go | 12 ++++++++++++ 2 files changed, 19 insertions(+)
diff --git a/pt.go b/pt.go index 20917a4..8cd5ff9 100644 --- a/pt.go +++ b/pt.go @@ -556,6 +556,7 @@ func getServerBindaddrs() ([]Bindaddr, error) { if err != nil { return nil, err } + seenMethods := make(map[string]bool) for _, spec := range strings.Split(serverBindaddr, ",") { var bindaddr Bindaddr
@@ -564,6 +565,12 @@ func getServerBindaddrs() ([]Bindaddr, error) { return nil, envError(fmt.Sprintf("TOR_PT_SERVER_BINDADDR: %q: doesn't contain "-"", spec)) } bindaddr.MethodName = parts[0] + // Check for duplicate method names: "Applications MUST NOT set + // more than one <address>:<port> pair per PT name." + if seenMethods[bindaddr.MethodName] { + return nil, envError(fmt.Sprintf("TOR_PT_SERVER_BINDADDR: %q: duplicate method name %q", spec, bindaddr.MethodName)) + } + seenMethods[bindaddr.MethodName] = true addr, err := resolveAddr(parts[1]) if err != nil { return nil, envError(fmt.Sprintf("TOR_PT_SERVER_BINDADDR: %q: %s", spec, err.Error())) diff --git a/pt_test.go b/pt_test.go index 0d641fe..fb9e61f 100644 --- a/pt_test.go +++ b/pt_test.go @@ -302,6 +302,18 @@ func TestGetServerBindaddrs(t *testing.T) { `alpha,beta`, "", }, + // duplicates in TOR_PT_SERVER_BINDADDR + // https://bugs.torproject.org/21261 + { + `alpha-0.0.0.0:1234,alpha-[::]:1234`, + `alpha`, + "", + }, + { + `alpha-0.0.0.0:1234,alpha-0.0.0.0:1234`, + `alpha`, + "", + }, } goodTests := [...]struct { ptServerBindaddr string
tor-commits@lists.torproject.org