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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yaegi v0.14.3 stops to works with gorilla/sessions #1484

Closed
wiltonsr opened this issue Oct 31, 2022 · 4 comments
Closed

yaegi v0.14.3 stops to works with gorilla/sessions #1484

wiltonsr opened this issue Oct 31, 2022 · 4 comments
Labels
area/core bug Something isn't working

Comments

@wiltonsr
Copy link

The following program sample.go triggers an unexpected result

// sessions.go
package main

import (
	"fmt"
	"net/http"

	"github.com/gorilla/sessions"
)

var (
	// key must be 16, 24 or 32 bytes long (AES-128, AES-192 or AES-256)
	key   = []byte("super-secret-key")
	store = sessions.NewCookieStore(key)
)

func secret(w http.ResponseWriter, r *http.Request) {
	session, _ := store.Get(r, "ldapauth")

	// Check if user is authenticated
	if auth, ok := session.Values["authenticated"].(bool); !ok || !auth {
		http.Error(w, "Forbidden", http.StatusForbidden)
		return
	}

	// Print secret message
	fmt.Fprintln(w, "The cake is a lie!")
}

func login(w http.ResponseWriter, r *http.Request) {
	session, _ := store.Get(r, "ldapauth")
	fmt.Println(session.IsNew)

	// Authentication goes here
	// ...

	// Set user as authenticated
	session.Values["authenticated"] = true
	session.Save(r, w)
}

func logout(w http.ResponseWriter, r *http.Request) {
	session, _ := store.Get(r, "ldapauth")

	// Revoke users authentication
	session.Values["authenticated"] = false
	session.Save(r, w)
}

func main() {
	http.HandleFunc("/secret", secret)
	http.HandleFunc("/login", login)
	http.HandleFunc("/logout", logout)

	http.ListenAndServe(":8080", nil)
}

Expected result

# The server starts to listens

Got

main.go:51:2: panic
run: reflect: Call using *interp.node as type func(http.ResponseWriter, *http.Request)
goroutine 1 [running]:
runtime/debug.Stack()
	/opt/hostedtoolcache/go/1.19.2/x64/src/runtime/debug/stack.go:24 +0x65
github.com/traefik/yaegi/interp.(*Interpreter).Execute.func1()
	/home/runner/work/yaegi/yaegi/interp/program.go:141 +0x94
panic({0xd85dc0, 0xc0004c53f0})
	/opt/hostedtoolcache/go/1.19.2/x64/src/runtime/panic.go:884 +0x212
github.com/traefik/yaegi/interp.runCfg.func1()
	/home/runner/work/yaegi/yaegi/interp/run.go:192 +0x148
panic({0xd85dc0, 0xc0004c53f0})
	/opt/hostedtoolcache/go/1.19.2/x64/src/runtime/panic.go:884 +0x212
reflect.Value.call({0xd99ba0?, 0xf14d90?, 0x41227f?}, {0xeab0c6, 0x4}, {0xc0008a7170, 0x2, 0xc0005932b0?})
	/opt/hostedtoolcache/go/1.19.2/x64/src/reflect/value.go:440 +0x1abf
reflect.Value.Call({0xd99ba0?, 0xf14d90?, 0x4571b2?}, {0xc0008a7170?, 0xea8ee0?, 0xc00053ee70?})
	/opt/hostedtoolcache/go/1.19.2/x64/src/reflect/value.go:368 +0xbc
github.com/traefik/yaegi/interp.callBin.func2({0xd99ba0?, 0xf14d90?, 0x405514?}, {0xc0008a7170?, 0xc00056d8c0?, 0xeb9417?})
	/home/runner/work/yaegi/yaegi/interp/run.go:1483 +0x28
github.com/traefik/yaegi/interp.callBin.func11(0xc00053ee70)
	/home/runner/work/yaegi/yaegi/interp/run.go:1658 +0x15f
github.com/traefik/yaegi/interp.runCfg(0xc00040f0e0, 0xc00053ee70, 0x2?, 0x2?)
	/home/runner/work/yaegi/yaegi/interp/run.go:200 +0x29d
github.com/traefik/yaegi/interp.(*Interpreter).run(0xc0000ef440, 0xc00040e6c0, 0xc0000d4630?)
	/home/runner/work/yaegi/yaegi/interp/run.go:119 +0x38e
github.com/traefik/yaegi/interp.(*Interpreter).Execute(0xc0000ef440, 0xc0008a5ef0)
	/home/runner/work/yaegi/yaegi/interp/program.go:167 +0x24b
github.com/traefik/yaegi/interp.(*Interpreter).eval(0xc0000ef440, {0xc0003faf00?, 0x49b?}, {0x7ffe24bb87d7?, 0xc0003fa500?}, 0x9b?)
	/home/runner/work/yaegi/yaegi/interp/interp.go:561 +0x5c
github.com/traefik/yaegi/interp.(*Interpreter).EvalPath(0xc0000ef440, {0x7ffe24bb87d7, 0x7})
	/home/runner/work/yaegi/yaegi/interp/interp.go:510 +0xab
main.runFile(0x7ffe24bb87d7?, {0x7ffe24bb87d7, 0x7}, 0x0)
	/home/runner/work/yaegi/yaegi/cmd/yaegi/run.go:153 +0xee
main.run({0xc0000361a0?, 0x1, 0x1})
	/home/runner/work/yaegi/yaegi/cmd/yaegi/run.go:116 +0xbec
main.main()
	/home/runner/work/yaegi/yaegi/cmd/yaegi/yaegi.go:133 +0xcf

Yaegi Version

0.14.3

Additional Notes

Works as expected in 0.14.2.

@wiltonsr
Copy link
Author

Hello, @mvertes

Any news about this issue?

@mvertes
Copy link
Member

mvertes commented Feb 28, 2023

This is working in v0.15.0

@mvertes mvertes closed this as completed Feb 28, 2023
@wiltonsr wiltonsr changed the title yaegi v0.14.3 stops to works with gorrila/sessions yaegi v0.14.3 stops to works with gorilla/sessions Feb 28, 2023
@wiltonsr
Copy link
Author

wiltonsr commented Feb 28, 2023

Hello @mvertes,

Thanks for the fixes.

gorilla/sessions is working now, but go-ldap stopped to works again.

There's a fix for that in issue #1275. But with v0.15.0 I'm getting the error:

<nil>
LDAP Request: (Universal, Constructed, Sequence and Sequence of) Len=47 "<nil>"
 MessageID: (Universal, Primitive, Integer) Len=1 "1"
 Bind Request: (Application, Constructed, 0x00) Len=42 "<nil>"
  Version: (Universal, Primitive, Integer) Len=1 "3"
  User Name: (Universal, Primitive, Octet String) Len=27 "uid=tesla,dc=example,dc=com"
  Password: (Context, Primitive, 0x00) Len=8 "password"
2023/02/28 11:44:46 flags&startTLS = 0
2023/02/28 11:44:46 1: returning
2023/02/28 11:44:46 1: waiting for response
2023/02/28 11:44:46 Sending message 1
2023/02/28 11:44:47 Receiving message 1
2023/02/28 11:44:47 1: got response %!p(interp.valueInterface={0xc001372f00 {0xc000591580 0xc0005ba3c8 406}})
LDAP Response: (Universal, Constructed, Sequence and Sequence of) Len=12 "<nil>"
 Message ID: (Universal, Primitive, Integer) Len=1 "1"
 Bind Response: (Application, Constructed, 0x01) Len=7 "<nil>"
  Result Code (Success): (Universal, Primitive, Enumerated) Len=1 "0"
  Matched DN (): (Universal, Primitive, Octet String) Len=0 ""
  Success: (Universal, Primitive, Octet String) Len=0 ""
2023/02/28 11:44:47 Finished message 1
/home/wilton/go/src/github.com/wiltonsr/yaegi-test/vendor/github.com/go-ldap/ldap/v3/conn.go:264:2: panic
run: reflect: Call using bool as type string
goroutine 1 [running]:
runtime/debug.Stack()
	/opt/hostedtoolcache/go/1.20.0/x64/src/runtime/debug/stack.go:24 +0x65
github.com/traefik/yaegi/interp.(*Interpreter).Execute.func1()
	/home/runner/work/yaegi/yaegi/interp/program.go:146 +0x94
panic({0xda72c0, 0xc000e91cb0})
	/opt/hostedtoolcache/go/1.20.0/x64/src/runtime/panic.go:884 +0x213
github.com/traefik/yaegi/interp.runCfg.func1()
	/home/runner/work/yaegi/yaegi/interp/run.go:205 +0x1a5
panic({0xda72c0, 0xc000e91cb0})
	/opt/hostedtoolcache/go/1.20.0/x64/src/runtime/panic.go:884 +0x213
reflect.Value.call({0xdbb560?, 0xc0008c94d0?, 0xdbb560?}, {0xed11c4, 0x4}, {0xc0008c9500, 0x2, 0x30?})
	/opt/hostedtoolcache/go/1.20.0/x64/src/reflect/value.go:442 +0x1a9f
reflect.Value.Call({0xdbb560?, 0xc0008c94d0?, 0x456512?}, {0xc0008c9500?, 0xecefa0?, 0x1?})
	/opt/hostedtoolcache/go/1.20.0/x64/src/reflect/value.go:370 +0xbc
github.com/traefik/yaegi/interp.call.func9.2({0xc0008c9500?, 0xc0008c94d0?, 0x5?})
	/home/runner/work/yaegi/yaegi/interp/run.go:1301 +0x3c
github.com/traefik/yaegi/interp.call.func9(0xc001456790)
	/home/runner/work/yaegi/yaegi/interp/run.go:1326 +0x1265
github.com/traefik/yaegi/interp.runCfg(0xc000f09e00, 0xc001456790, 0x0?, 0xc001419a80?)
	/home/runner/work/yaegi/yaegi/interp/run.go:213 +0x29d
github.com/traefik/yaegi/interp.genFunctionWrapper.func1.1({0x15eff40, 0x0, 0x0?})
	/home/runner/work/yaegi/yaegi/interp/run.go:1015 +0x825
reflect.Value.call({0xd9de80?, 0xc0008bd2f0?, 0x13?}, {0xed11c4, 0x4}, {0xc0013ad200, 0x0, 0xdd12a0?})
	/opt/hostedtoolcache/go/1.20.0/x64/src/reflect/value.go:586 +0xb07
reflect.Value.Call({0xd9de80?, 0xc0008bd2f0?, 0xc0008bd3e0?}, {0xc0013ad200?, 0xc0011dad10?, 0xc00053f8c8?})
	/opt/hostedtoolcache/go/1.20.0/x64/src/reflect/value.go:370 +0xbc
github.com/traefik/yaegi/interp.runCfg.func1()
	/home/runner/work/yaegi/yaegi/interp/run.go:190 +0xd7
github.com/traefik/yaegi/interp.runCfg(0xc00037d680, 0xc0011dad10, 0x4?, 0x0?)
	/home/runner/work/yaegi/yaegi/interp/run.go:215 +0x2f1
github.com/traefik/yaegi/interp.(*Interpreter).run(0xc0000f9680, 0xc00037c8c0, 0xc0000dc580?)
	/home/runner/work/yaegi/yaegi/interp/run.go:119 +0x40a
github.com/traefik/yaegi/interp.(*Interpreter).Execute(0xc0000f9680, 0xc0008b9b30)
	/home/runner/work/yaegi/yaegi/interp/program.go:172 +0x246
github.com/traefik/yaegi/interp.(*Interpreter).eval(0xc0000f9680, {0xc0000ee5a0?, 0x10e?}, {0x7fff6d1e60f9?, 0x200?}, 0x60?)
	/home/runner/work/yaegi/yaegi/interp/interp.go:564 +0x5c
github.com/traefik/yaegi/interp.(*Interpreter).EvalPath(0xc0000f9680, {0x7fff6d1e60f9, 0x7})
	/home/runner/work/yaegi/yaegi/interp/interp.go:513 +0xab
main.runFile(0x7fff6d1e60f9?, {0x7fff6d1e60f9, 0x7}, 0x0)
	/home/runner/work/yaegi/yaegi/cmd/yaegi/run.go:153 +0xee
main.run({0xc000036050?, 0x1, 0x1})
	/home/runner/work/yaegi/yaegi/cmd/yaegi/run.go:116 +0xb9a
main.main()
	/home/runner/work/yaegi/yaegi/cmd/yaegi/yaegi.go:144 +0x2cb

I used the same example from another issue.

would you rather I open another issue?

@mvertes
Copy link
Member

mvertes commented Feb 28, 2023

Thanks. I confirm that #1275 is broken again with v0.15.0. But I just tested with #1516 and it is ok to me. It's very likely that we merge #1516 soon and make a new release.

I'm reopening #1275 in the mean time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/core bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants