mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-02-23 02:51:26 +01:00
fix: more robust processor checks (#1656)
This ensures invalid architectures cannot have wsh installed. This includes validating the output of `uname -m` and PROCESSOR_ARCHITECTURE
This commit is contained in:
parent
a1f26ba455
commit
2590ad037d
@ -16,6 +16,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/wavetermdev/waveterm/pkg/panichandler"
|
||||
"github.com/wavetermdev/waveterm/pkg/util/utilfn"
|
||||
"golang.org/x/crypto/ssh"
|
||||
)
|
||||
|
||||
@ -145,7 +146,7 @@ func GetClientOs(client *ssh.Client) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
out, unixErr := session.Output("uname -s")
|
||||
out, unixErr := session.CombinedOutput("uname -s")
|
||||
if unixErr == nil {
|
||||
formatted := strings.ToLower(string(out))
|
||||
formatted = strings.TrimSpace(formatted)
|
||||
@ -184,14 +185,9 @@ func GetClientArch(client *ssh.Client) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
out, unixErr := session.Output("uname -m")
|
||||
out, unixErr := session.CombinedOutput("uname -m")
|
||||
if unixErr == nil {
|
||||
formatted := strings.ToLower(string(out))
|
||||
formatted = strings.TrimSpace(formatted)
|
||||
if formatted == "x86_64" {
|
||||
return "x64", nil
|
||||
}
|
||||
return formatted, nil
|
||||
return utilfn.FilterValidArch(string(out))
|
||||
}
|
||||
|
||||
session, err = client.NewSession()
|
||||
@ -199,10 +195,9 @@ func GetClientArch(client *ssh.Client) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
out, cmdErr := session.Output("echo %PROCESSOR_ARCHITECTURE%")
|
||||
if cmdErr == nil {
|
||||
formatted := strings.ToLower(string(out))
|
||||
return strings.TrimSpace(formatted), nil
|
||||
out, cmdErr := session.CombinedOutput("echo %PROCESSOR_ARCHITECTURE%")
|
||||
if cmdErr == nil && strings.TrimSpace(string(out)) != "%PROCESSOR_ARCHITECTURE%" {
|
||||
return utilfn.FilterValidArch(string(out))
|
||||
}
|
||||
|
||||
session, err = client.NewSession()
|
||||
@ -210,10 +205,9 @@ func GetClientArch(client *ssh.Client) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
out, psErr := session.Output("echo $env:PROCESSOR_ARCHITECTURE")
|
||||
if psErr == nil {
|
||||
formatted := strings.ToLower(string(out))
|
||||
return strings.TrimSpace(formatted), nil
|
||||
out, psErr := session.CombinedOutput("echo $env:PROCESSOR_ARCHITECTURE")
|
||||
if psErr == nil && strings.TrimSpace(string(out)) != "$env:PROCESSOR_ARCHITECTURE" {
|
||||
return utilfn.FilterValidArch(string(out))
|
||||
}
|
||||
return "", fmt.Errorf("unable to determine architecture: {unix: %s, cmd: %s, powershell: %s}", unixErr, cmdErr, psErr)
|
||||
}
|
||||
|
@ -964,3 +964,21 @@ func SafeDeref[T any](x *T) T {
|
||||
func Ptr[T any](x T) *T {
|
||||
return &x
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility function to convert know architecture patterns
|
||||
* to the patterns we use. It returns an error if the
|
||||
* provided name is unknown
|
||||
*/
|
||||
func FilterValidArch(arch string) (string, error) {
|
||||
formatted := strings.TrimSpace(strings.ToLower(arch))
|
||||
switch formatted {
|
||||
case "amd64":
|
||||
case "x86_64":
|
||||
case "x64":
|
||||
return "x64", nil
|
||||
case "arm64":
|
||||
return "arm64", nil
|
||||
}
|
||||
return "", fmt.Errorf("unknown architecture: %s", formatted)
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/wavetermdev/waveterm/pkg/panichandler"
|
||||
"github.com/wavetermdev/waveterm/pkg/util/utilfn"
|
||||
)
|
||||
|
||||
func DetectShell(ctx context.Context, client *Distro) (string, error) {
|
||||
@ -96,7 +97,7 @@ func hasBashInstalled(ctx context.Context, client *Distro) (bool, error) {
|
||||
|
||||
func GetClientOs(ctx context.Context, client *Distro) (string, error) {
|
||||
cmd := client.WslCommand(ctx, "uname -s")
|
||||
out, unixErr := cmd.Output()
|
||||
out, unixErr := cmd.CombinedOutput()
|
||||
if unixErr == nil {
|
||||
formatted := strings.ToLower(string(out))
|
||||
formatted = strings.TrimSpace(formatted)
|
||||
@ -125,26 +126,19 @@ func GetClientArch(ctx context.Context, client *Distro) (string, error) {
|
||||
cmd := client.WslCommand(ctx, "uname -m")
|
||||
out, unixErr := cmd.Output()
|
||||
if unixErr == nil {
|
||||
formatted := strings.ToLower(string(out))
|
||||
formatted = strings.TrimSpace(formatted)
|
||||
if formatted == "x86_64" {
|
||||
return "x64", nil
|
||||
}
|
||||
return formatted, nil
|
||||
return utilfn.FilterValidArch(string(out))
|
||||
}
|
||||
|
||||
cmd = client.WslCommand(ctx, "echo %PROCESSOR_ARCHITECTURE%")
|
||||
out, cmdErr := cmd.Output()
|
||||
out, cmdErr := cmd.CombinedOutput()
|
||||
if cmdErr == nil && strings.TrimSpace(string(out)) != "%PROCESSOR_ARCHITECTURE%" {
|
||||
formatted := strings.ToLower(string(out))
|
||||
return strings.TrimSpace(formatted), nil
|
||||
return utilfn.FilterValidArch(string(out))
|
||||
}
|
||||
|
||||
cmd = client.WslCommand(ctx, "echo $env:PROCESSOR_ARCHITECTURE")
|
||||
out, psErr := cmd.Output()
|
||||
out, psErr := cmd.CombinedOutput()
|
||||
if psErr == nil && strings.TrimSpace(string(out)) != "$env:PROCESSOR_ARCHITECTURE" {
|
||||
formatted := strings.ToLower(string(out))
|
||||
return strings.TrimSpace(formatted), nil
|
||||
return utilfn.FilterValidArch(string(out))
|
||||
}
|
||||
return "", fmt.Errorf("unable to determine architecture: {unix: %s, cmd: %s, powershell: %s}", unixErr, cmdErr, psErr)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user