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

Endless execution caused by MakeFunc. #19

Open
grumpyNeko opened this issue Aug 6, 2023 · 0 comments
Open

Endless execution caused by MakeFunc. #19

grumpyNeko opened this issue Aug 6, 2023 · 0 comments

Comments

@grumpyNeko
Copy link

win10, amd64, go1.20.2

  1. define println0
  2. patch(stand, println0)
  3. patch(println0, redirector)
  4. call stand, expect it to jump to redirector

However, if redirector is defined by reflect.MakeFunc, step 4 seems to cause endless execution.

func println0() {
	println(0)
}

// -gcflags='all=-N -l'
func Test_bad(t *testing.T) {
	stand := reflect.MakeFunc(reflect.ValueOf(println0).Type(), nil)
	_, err := mpatch.PatchMethodByReflectValue(stand, println0) 
	if err != nil {
		panic(err.Error())
	}
	stand.Call(nil) // 0

	_, err = mpatch.PatchMethodByReflectValue(reflect.ValueOf(println0), reflect.MakeFunc(reflect.ValueOf(println0).Type(), func(args []reflect.Value) (results []reflect.Value) {
		println("redirector")
		return nil
	}))
	if err != nil {
		panic(err.Error())
	}
	stand.Call(nil) // endless 
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant