Skip to content

Commit

Permalink
Fix invalid model header resulting in DoH failure
Browse files Browse the repository at this point in the history
Fixes #934
  • Loading branch information
rs committed Apr 29, 2024
1 parent 3bee47f commit e2d46ab
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 11 deletions.
3 changes: 2 additions & 1 deletion host/model_darwin.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package host

import (
"bytes"
"os/exec"
)

func Model() string {
if b, err := exec.Command("sysctl", "-n", "hw.model").Output(); err == nil && len(b) > 0 {
return "Apple " + string(b)
return "Apple " + string(bytes.TrimSpace(b))
}
return ""
}
7 changes: 5 additions & 2 deletions host/model_dragonfly.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package host

import "os/exec"
import (
"bytes"
"os/exec"
)

func Model() string {
if b, err := exec.Command("sysctl", "-n", "kern.version").Output(); err == nil && len(b) > 0 {
return string(b)
return string(bytes.TrimSpace(b))
}
return "DragonFly BSD"
}
7 changes: 5 additions & 2 deletions host/model_freebsd.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package host

import "os/exec"
import (
"bytes"
"os/exec"
)

func Model() string {
if b, err := exec.Command("sysctl", "-n", "kern.version").Output(); err == nil && len(b) > 0 {
return string(b)
return string(bytes.TrimSpace(b))
}
return "FreeBSD"
}
5 changes: 3 additions & 2 deletions host/model_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package host

import (
"bufio"
"bytes"
"os"
"os/exec"
"strings"
Expand All @@ -26,7 +27,7 @@ func Model() string {
func tryExec(cmds [][]string) string {
for _, cmd := range cmds {
if out, err := exec.Command(cmd[0], cmd[1:]...).Output(); err == nil && len(out) > 0 {
return string(out)
return string(bytes.TrimSpace(out))
}
}
return ""
Expand All @@ -41,7 +42,7 @@ func osName() string {
scanner := bufio.NewScanner(file)
for scanner.Scan() {
if strings.HasPrefix(scanner.Text(), "PRETTY_NAME=") {
return strings.Trim(scanner.Text()[12:], "\"")
return string(bytes.Trim(bytes.TrimSpace(scanner.Bytes()[12:]), "\""))
}
}
return ""
Expand Down
7 changes: 5 additions & 2 deletions host/model_netbsd.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package host

import "os/exec"
import (
"bytes"
"os/exec"
)

func Model() string {
if b, err := exec.Command("sysctl", "-n", "kern.version").Output(); err == nil && len(b) > 0 {
return string(b)
return string(bytes.TrimSpace(b))
}
return "NetBSD"
}
7 changes: 5 additions & 2 deletions host/model_openbsd.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package host

import "os/exec"
import (
"bytes"
"os/exec"
)

func Model() string {
if b, err := exec.Command("sysctl", "-n", "kern.version").Output(); err == nil && len(b) > 0 {
return string(b)
return string(bytes.TrimSpace(b))
}
return "OpenBSD"
}
1 change: 1 addition & 0 deletions resolver/doh.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func (r *DOH) resolve(ctx context.Context, q query.Query, buf []byte, rt http.Ro
req.Header.Set("X-Device-Ip", ci.IP)
}
if ci.Model != "" {
println(ci.Model)
req.Header.Set("X-Device-Model", ci.Model)
}
if ci.Name != "" {
Expand Down

0 comments on commit e2d46ab

Please sign in to comment.