From 69aeac1728a4148c8937d556a49c63b8467bc479 Mon Sep 17 00:00:00 2001 From: qmuntal Date: Thu, 20 Feb 2025 10:52:30 +0100 Subject: [PATCH] don't set caller information in CRYPTO_[malloc,free] --- openssl.go | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/openssl.go b/openssl.go index 0dad8e5..710ff1d 100644 --- a/openssl.go +++ b/openssl.go @@ -9,7 +9,6 @@ import ( "encoding/binary" "errors" "math/bits" - "runtime" "strconv" "strings" "sync" @@ -313,25 +312,6 @@ func newOpenSSLError(msg string) error { return errors.New(b.String()) } -var unknownFile = "\000" - -// caller reports file and line number information about function invocations on -// the calling goroutine's stack, in a form suitable for passing to C code. -// The argument skip is the number of stack frames to ascend, with 0 identifying -// the caller of caller. The return values report the file name and line number -// within the file of the corresponding call. The returned file is a C string -// with static storage duration. -func caller(skip int) (file *C.char, line C.int) { - _, f, l, ok := runtime.Caller(skip + 1) - if !ok { - f = unknownFile - } - // The underlying bytes of the file string are null-terminated rodata with - // static lifetimes, so can be safely passed to C without worrying about - // leaking memory or use-after-free. - return (*C.char)(noescape(unsafe.Pointer(unsafe.StringData(f)))), C.int(l) -} - // cryptoMalloc allocates n bytes of memory on the OpenSSL heap, which may be // different from the heap which C.malloc allocates on. The allocated object // must be freed using cryptoFree. cryptoMalloc is equivalent to the @@ -344,8 +324,7 @@ func caller(skip int) (file *C.char, line C.int) { // freed by OPENSSL_free / CRYPTO_free) need to be allocated on the OpenSSL // heap. func cryptoMalloc(n int) unsafe.Pointer { - file, line := caller(1) - p := C.go_openssl_CRYPTO_malloc(C.size_t(n), file, line) + p := C.go_openssl_CRYPTO_malloc(C.size_t(n), nil, 0) if p == nil { // Un-recover()-ably crash the program in the same manner as the // C.malloc() wrapper function. @@ -358,8 +337,7 @@ func cryptoMalloc(n int) unsafe.Pointer { // different from the heap which C.malloc allocates on. cryptoFree is equivalent // to the OPENSSL_free macro. func cryptoFree(p unsafe.Pointer) { - file, line := caller(1) - C.go_openssl_CRYPTO_free(p, file, line) + C.go_openssl_CRYPTO_free(p, nil, 0) } const wordBytes = bits.UintSize / 8