roehling / postsrsd

Postfix Sender Rewriting Scheme daemon
319 stars 38 forks source link

milter null pointer dereference with IPv6 SMTP clients #153

Closed rhansen closed 11 months ago

rhansen commented 11 months ago

This line is segfaulting due to null pointer dereference (priv is NULL):

https://github.com/roehling/postsrsd/blob/1bf5c369a791f6bdfd28944597f9b7e870954133/src/milter.c#L173

This seems to happen when the SMTP client connects over IPv6. The following is logged just before the segfault occurs:

postsrsd[30415]: PostSRSd: connect[-1219257536]: unknown family 54

If I define NETINET6 and rebuild then the segfault and the "unknown family" log message go away:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index af5ff69..16a16d8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -263,7 +263,7 @@ if(WITH_MILTER)
                 "${libmilter_SOURCE_DIR}/worker.c"
             )
             target_compile_definitions(
-                milter PRIVATE NOT_SENDMAIL=1 sm_snprintf=snprintf
+                milter PRIVATE NOT_SENDMAIL=1 sm_snprintf=snprintf NETINET6
             )
             target_include_directories(
                 milter

(BTW, thank you very much for fixing #152!)

roehling commented 11 months ago

Defining NETINET6 gives me a compile error because RES_USE_INET6 is undefined. As it turns out, that definition for the resolver is deprecated and has been removed since glibc 2.30. However, I can avoid the segfault by more carefully checking for NULL pointers in the milter callbacks.