nwrap: Zero the result in case we return with an error
authorAndreas Schneider <asn@samba.org>
Thu, 19 Mar 2020 08:45:09 +0000 (09:45 +0100)
committerAndreas Schneider <asn@samba.org>
Thu, 19 Mar 2020 08:49:39 +0000 (09:49 +0100)
This fixes a crash bug in OpenLDAP libraries which do not check the
return value of gethostbyname_r().

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Alexander Bokovoy <ab@samba.org>
Reviewed-by: Samuel Cabrero <scabrero@suse.de>
src/nss_wrapper.c

index 6ece2668a99754377442232e10471326b1629d3e..5d3a01c5ce3f826d2b4a37d4ae95eea00f40fe9f 100644 (file)
@@ -3621,6 +3621,12 @@ static int nwrap_files_internal_gethostbyname(const char *name, int af,
        bool he_found = false;
        bool ok;
 
+       /*
+        * We need to make sure we have zeroed return pointer for consumers
+        * which don't check return values, e.g. OpenLDAP.
+        */
+       ZERO_STRUCTP(result);
+
        ok = nwrap_files_cache_reload(nwrap_he_global.cache);
        if (!ok) {
                NWRAP_LOG(NWRAP_LOG_ERROR, "error loading hosts file");