Handle invalid UTF-8 characters before RPC calls (#4816)

Several users reported cases where error messages would
cause a panic if they contained accented characters. I wasn't
able to reproduce this failure locally, but tracked down the
panic to logging gRPC calls. The Message field is typed as
a string, which requires all of the characters to be valid UTF-8.

This change runs each log string through the strings.ToValidUTF8
function, which will replace any invalid characters with the
"unknown" character. This should prevent the the logger from
panicking.
This commit is contained in:
Levi Blackstone 2020-06-17 13:30:59 -06:00 committed by GitHub
parent 5530836325
commit 19a113de7a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 6 deletions

View file

@ -9,8 +9,11 @@ CHANGELOG
- Set default config namespace for Get/Try/Require methods in Go SDK.
[#4802](https://github.com/pulumi/pulumi/pull/4802)
- Handle invalid UTF-8 characters before RPC calls
[#4816](https://github.com/pulumi/pulumi/pull/4816)
- Improve typing for Go SDK secret config values
[#4800](https://github.com/pulumi/pulumi/pull/4800)
[#4800](https://github.com/pulumi/pulumi/pull/4800)
- Fix panic on `pulumi up` prompt after preview when filtering and hitting arrow keys.
[#4808](https://github.com/pulumi/pulumi/pull/4808)

View file

@ -15,14 +15,15 @@
package provider
import (
"golang.org/x/net/context"
"google.golang.org/grpc"
"strings"
"github.com/pulumi/pulumi/sdk/v2/go/common/diag"
"github.com/pulumi/pulumi/sdk/v2/go/common/resource"
"github.com/pulumi/pulumi/sdk/v2/go/common/util/contract"
"github.com/pulumi/pulumi/sdk/v2/go/common/util/rpcutil"
lumirpc "github.com/pulumi/pulumi/sdk/v2/proto/go"
"golang.org/x/net/context"
"google.golang.org/grpc"
)
// HostClient is a client interface into the host's engine RPC interface.
@ -71,7 +72,7 @@ func (host *HostClient) log(
}
_, err := host.client.Log(context, &lumirpc.LogRequest{
Severity: rpcsev,
Message: msg,
Message: strings.ToValidUTF8(msg, "<22>"),
Urn: string(urn),
Ephemeral: ephemeral,
})

View file

@ -454,7 +454,7 @@ func (w *logWriter) Write(p []byte) (n int, err error) {
func (w *logWriter) LogToUser(val string) (int, error) {
if w.logToUser {
_, err := w.engineClient.Log(w.ctx, &pulumirpc.LogRequest{
Message: val,
Message: strings.ToValidUTF8(val, "<22>"),
Urn: "",
Ephemeral: true,
StreamId: w.streamID,

View file

@ -17,6 +17,8 @@
package pulumi
import (
"strings"
pulumirpc "github.com/pulumi/pulumi/sdk/v2/proto/go"
"golang.org/x/net/context"
)
@ -90,7 +92,7 @@ func _log(ctx context.Context, engine pulumirpc.EngineClient, severity pulumirpc
logRequest := &pulumirpc.LogRequest{
Severity: severity,
Message: message,
Message: strings.ToValidUTF8(message, "<22>"),
Urn: urn,
StreamId: args.StreamID,
Ephemeral: args.Ephemeral,