Skip to content

Commit 5e4ca0f

Browse files
authored
don't set caller information in CRYPTO_[malloc,free] (#250)
1 parent 05515e5 commit 5e4ca0f

File tree

1 file changed

+2
-24
lines changed

1 file changed

+2
-24
lines changed

openssl.go

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"encoding/binary"
1010
"errors"
1111
"math/bits"
12-
"runtime"
1312
"strconv"
1413
"strings"
1514
"sync"
@@ -304,25 +303,6 @@ func newOpenSSLError(msg string) error {
304303
return errors.New(b.String())
305304
}
306305

307-
var unknownFile = "<go code>\000"
308-
309-
// caller reports file and line number information about function invocations on
310-
// the calling goroutine's stack, in a form suitable for passing to C code.
311-
// The argument skip is the number of stack frames to ascend, with 0 identifying
312-
// the caller of caller. The return values report the file name and line number
313-
// within the file of the corresponding call. The returned file is a C string
314-
// with static storage duration.
315-
func caller(skip int) (file *C.char, line C.int) {
316-
_, f, l, ok := runtime.Caller(skip + 1)
317-
if !ok {
318-
f = unknownFile
319-
}
320-
// The underlying bytes of the file string are null-terminated rodata with
321-
// static lifetimes, so can be safely passed to C without worrying about
322-
// leaking memory or use-after-free.
323-
return (*C.char)(noescape(unsafe.Pointer(unsafe.StringData(f)))), C.int(l)
324-
}
325-
326306
// cryptoMalloc allocates n bytes of memory on the OpenSSL heap, which may be
327307
// different from the heap which C.malloc allocates on. The allocated object
328308
// must be freed using cryptoFree. cryptoMalloc is equivalent to the
@@ -335,8 +315,7 @@ func caller(skip int) (file *C.char, line C.int) {
335315
// freed by OPENSSL_free / CRYPTO_free) need to be allocated on the OpenSSL
336316
// heap.
337317
func cryptoMalloc(n int) unsafe.Pointer {
338-
file, line := caller(1)
339-
p := C.go_openssl_CRYPTO_malloc(C.size_t(n), file, line)
318+
p := C.go_openssl_CRYPTO_malloc(C.size_t(n), nil, 0)
340319
if p == nil {
341320
// Un-recover()-ably crash the program in the same manner as the
342321
// C.malloc() wrapper function.
@@ -349,8 +328,7 @@ func cryptoMalloc(n int) unsafe.Pointer {
349328
// different from the heap which C.malloc allocates on. cryptoFree is equivalent
350329
// to the OPENSSL_free macro.
351330
func cryptoFree(p unsafe.Pointer) {
352-
file, line := caller(1)
353-
C.go_openssl_CRYPTO_free(p, file, line)
331+
C.go_openssl_CRYPTO_free(p, nil, 0)
354332
}
355333

356334
const wordBytes = bits.UintSize / 8

0 commit comments

Comments
 (0)