-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
cmd/cgo: Buffer overflow trying to use C.malloc #69098
Comments
You're violating quite a few Not sure why
You can do this for pointer-free types. You cannot do it for types containing pointers (which includes interfaces). A better strategy is to use the new |
I figured all that, but yeah, malloc itself failkng is weird. |
It calls libc's malloc, yes. |
First call. |
It looks like C.malloc finally reached the code below victim = av->top;
size = chunksize (victim);
if (__glibc_unlikely (size > av->system_mem))
malloc_printerr ("malloc(): corrupted top size"); |
We can't do anything here without a complete, standalone, example that demonstrates the problem. |
I actually can't.
Which seems to be poorly documented, and also I'm still getting that fault address error. func ResponseIntoRaw(raw *http.Response) C.Response {
pinner := new(runtime.Pinner)
pinner.Pin(raw)
return C.Response{(unsafe.Pointer)(raw)}
}
func ResponseWriterIntoRaw(raw http.ResponseWriter) C.ResponseWriter {
pinner := new(runtime.Pinner)
pinner.Pin(raw)
return C.ResponseWriter{(unsafe.Pointer)(&raw)}
} |
As the I suggest that you bring your actual problem to a forum. You will get better and faster answers there than you will on the issue tracker. See https://go.dev/wiki/Questions. Thanks. |
Go version
go version go1.22.6 linux/amd64
Output of
go env
in your module/workspace:What did you do?
Tried to copy the contents of a Golang pointer into a C struct that has a C.void in it.
What did you see happen?
Before I could even see my code fail in any other way, I saw C.malloc throwing an error that implies a buffer overflow, even though it's 16 bytes.
This only happens 50% of the time, the other 50% I see
unexpected fault address 0x0
which is an error I was getting before I was told that you need to use malloc to pass Go types to C.What did you expect to see?
I honestly would be amazed if I didn't encounter another memory bug after this but I at least expected malloc to be able to function and not complain about a buffer overflow.
The text was updated successfully, but these errors were encountered: