This commit is contained in:
Viktor Liu
2025-07-02 21:32:39 +02:00
parent 0d5408baec
commit 5970591d24
8 changed files with 59 additions and 189 deletions
+7 -2
View File
@@ -4,6 +4,7 @@ package winpty
import (
"context"
"errors"
"fmt"
"io"
"strings"
@@ -16,6 +17,10 @@ import (
"golang.org/x/sys/windows"
)
var (
ErrEmptyEnvironment = errors.New("empty environment")
)
const (
extendedStartupInfoPresent = 0x00080000
createUnicodeEnvironment = 0x00000400
@@ -277,7 +282,7 @@ func createConPtyProcess(commandLine string, userToken windows.Handle, userEnv [
// convertEnvironmentToUTF16 converts environment variables to Windows UTF16 format.
func convertEnvironmentToUTF16(userEnv []string) (*uint16, error) {
if len(userEnv) == 0 {
return nil, nil
return nil, ErrEmptyEnvironment
}
var envUTF16 []uint16
@@ -297,7 +302,7 @@ func convertEnvironmentToUTF16(userEnv []string) (*uint16, error) {
if len(envUTF16) > 0 {
return &envUTF16[0], nil
}
return nil, nil
return nil, ErrEmptyEnvironment
}
// duplicateToPrimaryToken converts an impersonation token to a primary token.
+4 -1
View File
@@ -5,6 +5,7 @@ package winpty
import (
"testing"
log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/sys/windows"
@@ -280,7 +281,9 @@ func BenchmarkConPtyCreation(b *testing.B) {
}
// Clean up
procClosePseudoConsole.Call(uintptr(hPty))
if ret, _, err := procClosePseudoConsole.Call(uintptr(hPty)); ret == 0 {
log.Debugf("ClosePseudoConsole failed: %v", err)
}
closeHandles(inputRead, inputWrite, outputRead, outputWrite)
}
}