From 39a4baf02e93bb0093390fa3eea2e77afac510b6 Mon Sep 17 00:00:00 2001 From: "Dolf Schimmel (Freeaqingme)" Date: Tue, 24 Nov 2015 17:38:59 +0100 Subject: [PATCH] Recover from errors in Go_xxfi_connect() There appears to be a race condition in libmilter in which hostaddr is set to nil before or while calling the connect callback if the client aborts its connection during that window. --- gomilter.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/gomilter.go b/gomilter.go index 891bd36..47a9e32 100644 --- a/gomilter.go +++ b/gomilter.go @@ -200,7 +200,14 @@ func GobDecode(buf []byte, data interface{}) error { // They are only called if they get registered but need to be defined anyway //export Go_xxfi_connect -func Go_xxfi_connect(ctx *C.SMFICTX, hostname *C.char, hostaddr *C._SOCK_ADDR) C.sfsistat { +func Go_xxfi_connect(ctx *C.SMFICTX, hostname *C.char, hostaddr *C._SOCK_ADDR) (sfsistat C.sfsistat) { + defer func(sfsistat *C.sfsistat) { + if r := recover(); r != nil { + LoggerPrintf("Panic caught in Go_xxfi_connect(): %s", r) + *sfsistat = 75 // tempfail + } + }(&sfsistat) + ctxptr := ctx2int(ctx) var ip net.IP