From beaa33a2ea44bd8eb762b6d326f2f7462c6ff445 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 6 May 2020 12:36:00 -0700 Subject: [PATCH] s3: RPC: Don't crash on trying to talloc_free(-1) if smb_iconv_open_ex() fails. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Assign output from smb_iconv_open_ex() to a temporary handle. Only assign to mds_ctx->[handles] if correctly opened otherwise we end up trying to call smb_iconv_close(-1). MacOSX Catalina triggers this. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14372 Signed-off-by: Jeremy Allison Reviewed-by: Ralph Boehme Autobuild-User(master): Ralph Böhme Autobuild-Date(master): Thu May 7 18:03:16 UTC 2020 on sn-devel-184 (cherry picked from commit 14df5d20a8ec00bf8627732284f427f6463177e3) --- source3/rpc_server/mdssvc/mdssvc.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/source3/rpc_server/mdssvc/mdssvc.c b/source3/rpc_server/mdssvc/mdssvc.c index fce3335d602..d6edc1c1686 100644 --- a/source3/rpc_server/mdssvc/mdssvc.c +++ b/source3/rpc_server/mdssvc/mdssvc.c @@ -1528,6 +1528,7 @@ struct mds_ctx *mds_init_ctx(TALLOC_CTX *mem_ctx, struct mds_ctx *mds_ctx; int backend; bool ok; + smb_iconv_t iconv_hnd = (smb_iconv_t)-1; mds_ctx = talloc_zero(mem_ctx, struct mds_ctx); if (mds_ctx == NULL) { @@ -1566,21 +1567,23 @@ struct mds_ctx *mds_init_ctx(TALLOC_CTX *mem_ctx, goto error; } - mds_ctx->ic_nfc_to_nfd = smb_iconv_open_ex(mds_ctx, + iconv_hnd = smb_iconv_open_ex(mds_ctx, "UTF8-NFD", "UTF8-NFC", false); - if (mds_ctx->ic_nfc_to_nfd == (smb_iconv_t)-1) { + if (iconv_hnd == (smb_iconv_t)-1) { goto error; } + mds_ctx->ic_nfc_to_nfd = iconv_hnd; - mds_ctx->ic_nfd_to_nfc = smb_iconv_open_ex(mds_ctx, + iconv_hnd = smb_iconv_open_ex(mds_ctx, "UTF8-NFC", "UTF8-NFD", false); - if (mds_ctx->ic_nfd_to_nfc == (smb_iconv_t)-1) { + if (iconv_hnd == (smb_iconv_t)-1) { goto error; } + mds_ctx->ic_nfd_to_nfc = iconv_hnd; mds_ctx->sharename = talloc_strdup(mds_ctx, sharename); if (mds_ctx->sharename == NULL) { -- 2.20.1