Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetPolicyDocumentOutput panics instead of returning error #1872

Closed
ghostsquad opened this issue Mar 22, 2022 · 6 comments 路 Fixed by pulumi/pulumi#9274
Closed

GetPolicyDocumentOutput panics instead of returning error #1872

ghostsquad opened this issue Mar 22, 2022 · 6 comments 路 Fixed by pulumi/pulumi#9274
Assignees
Labels
kind/bug Some behavior is incorrect or out of spec resolution/fixed This issue was fixed
Milestone

Comments

@ghostsquad
Copy link

ghostsquad commented Mar 22, 2022

Hello!

  • Vote on this issue by adding a 馃憤 reaction
  • To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already)

Issue details

This is a problematic line:

(expanded below)

func GetPolicyDocumentOutput(ctx *pulumi.Context, args GetPolicyDocumentOutputArgs, opts ...pulumi.InvokeOption) GetPolicyDocumentResultOutput {
	return pulumi.ToOutputWithContext(context.Background(), args).
		ApplyT(func(v interface{}) (GetPolicyDocumentResult, error) {
			args := v.(GetPolicyDocumentArgs)
			r, err := GetPolicyDocument(ctx, &args, opts...)
			return *r, err
		}).(GetPolicyDocumentResultOutput)
}

if GetPolicyDocument returns nil, <error here>, then *r will result in a panic

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1726ecf]

Steps to reproduce

_ = iam.GetPolicyDocumentOutput(ctx, iam.GetPolicyDocumentOutputArgs{
	Statements: iam.GetPolicyDocumentStatementArray{
		iam.GetPolicyDocumentStatementArgs{
			Actions: pulumi.StringArray{
				pulumi.String("sts:AssumeRoleWithWebIdentity"),
			},
			Conditions: iam.GetPolicyDocumentStatementConditionArray{
				iam.GetPolicyDocumentStatementConditionArgs{
					Test: pulumi.String("StringLike"),
					Values: pulumi.StringArray{
						pulumi.Sprintf("repo:%s/%s:*", "mytestorg", "mytestrepo"),
					},
					Variable: pulumi.String("token.actions.githubusercontent.com:sub"),
				},
			},
			Principals: iam.GetPolicyDocumentStatementPrincipalArray{
				iam.GetPolicyDocumentStatementPrincipalArgs{
					Identifiers: pulumi.StringArray{
						pulumi.String("arn:aws:iam::12345678:oidc-provider/token.actions.githubusercontent.com"),
					},
					Type: pulumi.String("Federated"),
				},
			},
		},
	},
})
    panic: runtime error: invalid memory address or nil pointer dereference
    [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x17240af]
    goroutine 23 [running]:
    github.com/pulumi/pulumi-aws/sdk/v4/go/aws/iam.GetPolicyDocumentOutput.func1({0x18fe240?, 0xc0005a4380})
    	/Users/wmcnamee/.asdf/installs/golang/1.18/packages/pkg/mod/github.com/pulumi/pulumi-aws/sdk/v4@v4.38.1/go/aws/iam/getPolicyDocument.go:356 +0x18f
    reflect.Value.call({0x181b940?, 0xc000580480?, 0x100ea45?}, {0x197129f, 0x4}, {0xc00050e018, 0x1, 0xc0005b8240?})
    	/Users/wmcnamee/.asdf/installs/golang/1.18/go/src/reflect/value.go:556 +0x845

Note that the line numbers don't match up with the source code (in this repo), but here's a screenshot from the vendored code:

image

Expected: to get a human readable error
Actual: panic and nil pointer exception

@ghostsquad ghostsquad added the kind/bug Some behavior is incorrect or out of spec label Mar 22, 2022
ghostsquad added a commit to ghostsquad/pulumi-aws that referenced this issue Mar 22, 2022
@ghostsquad
Copy link
Author

ghostsquad commented Mar 22, 2022

after figuring out how to attach a debugger, I can further confirm this is exactly the problem.

image

Notice that r is nil

@guineveresaenger
Copy link
Contributor

Paging @t0yv0 to verify that this was fixed in pulumi/pulumi v3.25.1?

@t0yv0
Copy link
Member

t0yv0 commented Mar 23, 2022

@t0yv0 t0yv0 self-assigned this Mar 23, 2022
@t0yv0 t0yv0 added this to the 0.71 milestone Mar 23, 2022
@guineveresaenger
Copy link
Contributor

@ghostsquad Thank you again for noticing and reporting!

We verified it's still an issue and are working on a fix. The issue is in pulumi/pulumi codegen, which is how these files get created, and once we ship that fix, on the next release of this provider this issue should be resolved.

guineveresaenger added a commit to pulumi/pulumi that referenced this issue Mar 23, 2022
Fixes pulumi/pulumi-aws#1872.

This should result in the following sample output in the Go SDK:

```
func GetPolicyDocumentOutput(ctx *pulumi.Context, args GetPolicyDocumentOutputArgs, opts ...pulumi.InvokeOption) GetPolicyDocumentResultOutput {
	return pulumi.ToOutputWithContext(context.Background(), args).
		ApplyT(func(v interface{}) (GetPolicyDocumentResult, error) {
			args := v.(GetPolicyDocumentArgs)
			r, err := GetPolicyDocument(ctx, &args, opts...)
			if err != nil {
				return nil, err
			}
			if r == nil {
				return nil, fmt.Errorf("expected either result or error to be nil, not both")
			}
			return *r, err
		}).(GetPolicyDocumentResultOutput)
}
```
@guineveresaenger guineveresaenger modified the milestones: 0.71, 0.70 Mar 23, 2022
guineveresaenger added a commit to pulumi/pulumi that referenced this issue Mar 24, 2022
Fixes pulumi/pulumi-aws#1872.

This should result in the following sample output in the Go SDK:

```
func GetPolicyDocumentOutput(ctx *pulumi.Context, args GetPolicyDocumentOutputArgs, opts ...pulumi.InvokeOption) GetPolicyDocumentResultOutput {
	return pulumi.ToOutputWithContext(context.Background(), args).
		ApplyT(func(v interface{}) (GetPolicyDocumentResult, error) {
			args := v.(GetPolicyDocumentArgs)
			r, err := GetPolicyDocument(ctx, &args, opts...)
			if err != nil {
				return nil, err
			}
			if r == nil {
				return nil, fmt.Errorf("expected either result or error to be nil, not both")
			}
			return *r, err
		}).(GetPolicyDocumentResultOutput)
}
```
guineveresaenger added a commit to pulumi/pulumi that referenced this issue Mar 24, 2022
* [codegen/go] Update Go SDK function output to check for errors

Fixes pulumi/pulumi-aws#1872.

This should result in the following sample output in the Go SDK:

```
func GetPolicyDocumentOutput(ctx *pulumi.Context, args GetPolicyDocumentOutputArgs, opts ...pulumi.InvokeOption) GetPolicyDocumentResultOutput {
	return pulumi.ToOutputWithContext(context.Background(), args).
		ApplyT(func(v interface{}) (GetPolicyDocumentResult, error) {
			args := v.(GetPolicyDocumentArgs)
			r, err := GetPolicyDocument(ctx, &args, opts...)
			if r != nil {
				s = *r
			}
			return s, err
		}).(GetPolicyDocumentResultOutput)
}
```

* Alternate fix to safeguard dereferencing nil

* Accept codegen changes in the test suite

Co-authored-by: Guinevere Saenger <guinevere@pulumi.com>
guineveresaenger added a commit to pulumi/pulumi that referenced this issue Mar 25, 2022
* [codegen/go] Update Go SDK function output to check for errors

Fixes pulumi/pulumi-aws#1872.

This should result in the following sample output in the Go SDK:

```
func GetPolicyDocumentOutput(ctx *pulumi.Context, args GetPolicyDocumentOutputArgs, opts ...pulumi.InvokeOption) GetPolicyDocumentResultOutput {
	return pulumi.ToOutputWithContext(context.Background(), args).
		ApplyT(func(v interface{}) (GetPolicyDocumentResult, error) {
			args := v.(GetPolicyDocumentArgs)
			r, err := GetPolicyDocument(ctx, &args, opts...)
			if err != nil {
				return nil, err
			}
			if r == nil {
				return nil, fmt.Errorf("expected either result or error to be nil, not both")
			}
			return *r, err
		}).(GetPolicyDocumentResultOutput)
}
```

* Fix generated code panic on *nil (#9284)

* [codegen/go] Update Go SDK function output to check for errors

Fixes pulumi/pulumi-aws#1872.

This should result in the following sample output in the Go SDK:

```
func GetPolicyDocumentOutput(ctx *pulumi.Context, args GetPolicyDocumentOutputArgs, opts ...pulumi.InvokeOption) GetPolicyDocumentResultOutput {
	return pulumi.ToOutputWithContext(context.Background(), args).
		ApplyT(func(v interface{}) (GetPolicyDocumentResult, error) {
			args := v.(GetPolicyDocumentArgs)
			r, err := GetPolicyDocument(ctx, &args, opts...)
			if r != nil {
				s = *r
			}
			return s, err
		}).(GetPolicyDocumentResultOutput)
}
```

* Alternate fix to safeguard dereferencing nil

* Accept codegen changes in the test suite

Co-authored-by: Guinevere Saenger <guinevere@pulumi.com>

* Update CHANGELOG_PENDING.md

Co-authored-by: Anton Tayanovskyy <anton@pulumi.com>
@pulumi-bot pulumi-bot added the resolution/fixed This issue was fixed label Mar 25, 2022
@ghostsquad
Copy link
Author

I'm running pulumi cli 3.37.2, and it appears this is still an issue. Do you know what's going on?

@t0yv0
Copy link
Member

t0yv0 commented Aug 8, 2022

https://github.com/pulumi/pulumi-aws/blob/master/sdk/go/aws/iam/getPolicyDocument.go#L215 the fix seems to be applied on master. Mind letting us know which version of the pulumi-aws Go SDK you are using so we can repro? 馃檱

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Some behavior is incorrect or out of spec resolution/fixed This issue was fixed
Projects
None yet
4 participants