[SCM] Samba Shared Repository - branch master updated

Andreas Schneider asn at samba.org
Tue Apr 18 13:44:03 UTC 2017


The branch, master has been updated
       via  76b351e s3:smbd: Fix incorrect use of sys_getgroups()
       via  60af864 s3:lib: Fix incorrect logic in sys_broken_getgroups()
       via  600f878 lib: debug: Avoid negative array access.
       via  bf8f7a3 lib:charset: Remove use of talloc_autofree_context() for global_iconv_handle
       via  35b2371 lib:charset: Make global_iconv_handle private
       via  2a4d07b lib: param: Remove the last external use of global_iconv_handle by calling the utility function reinit_iconv_handle().
       via  766e9ff lib: param: Use utility functions to get rid of two more uses of global_iconv_handle.
       via  6086b0e s3:param: Use new utility function to hide use of global_iconv_handle
       via  b4e4042 s3:lib:charcnv: Remove use of global global_iconv_handle
       via  c28e2c9 lib:charset: Add utility functions reinit_iconv_handle() and free_iconv_handle(void)
       via  3afbdb7 lib: Remove smb_iconv_handle_reinit_lp()
      from  05d83cc vfs_acl_xattr: avoid needlessly supplying a large buffer to getxattr()

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 76b351e907f67cc7d4af4e7d800c7a3aa1269ee8
Author: Jeremy Allison <jra at samba.org>
Date:   Mon Apr 17 14:30:54 2017 -0700

    s3:smbd: Fix incorrect use of sys_getgroups()
    
    Second arg must be NULL when first arg is 0 (it is in all other places).
    
    Bug report and patch from Hanno Böck <hanno at hboeck.de>
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12747
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    
    Autobuild-User(master): Andreas Schneider <asn at cryptomilk.org>
    Autobuild-Date(master): Tue Apr 18 15:43:02 CEST 2017 on sn-devel-144

commit 60af864f751706c48b8af448700bf06e33e45946
Author: Jeremy Allison <jra at samba.org>
Date:   Mon Apr 17 14:30:04 2017 -0700

    s3:lib: Fix incorrect logic in sys_broken_getgroups()
    
    If setlen == 0 then the second argument must be ignored.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12747
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit 600f8787e3b605c9f3e8f724c726e63157ee9efc
Author: Jeremy Allison <jra at samba.org>
Date:   Mon Apr 17 14:09:24 2017 -0700

    lib: debug: Avoid negative array access.
    
    Report and patch from Hanno Böck <hanno at hboeck.de>.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12746
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Martin Schwenke <martin at meltin.net>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit bf8f7a36bfbe5c2018dbd9a317c8791c56b4114e
Author: Jeremy Allison <jra at samba.org>
Date:   Tue Apr 11 16:06:08 2017 -0700

    lib:charset: Remove use of talloc_autofree_context() for global_iconv_handle
    
    All other callers use NULL here anyway, so there's no
    need to use a special context for get_iconv_handle().
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit 35b23711e8f59efffa4ae56b3005f0f0fdda2e5e
Author: Jeremy Allison <jra at samba.org>
Date:   Tue Apr 11 16:05:02 2017 -0700

    lib:charset: Make global_iconv_handle private
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit 2a4d07b999df2343c694a2b373d3b506bd3d5682
Author: Jeremy Allison <jra at samba.org>
Date:   Tue Apr 11 15:57:28 2017 -0700

    lib: param: Remove the last external use of global_iconv_handle by calling the utility function reinit_iconv_handle().
    
    Add an error check.
    
    This *looks* like a logic change, but it is not.
    
    The only change is the addition of the error return check.
    
    The reason is that the changed function, reload_charcnv(),
    is the *only* function that sets lp_ctx->iconv_handle. And
    it does so just before setting global_iconv_handle = lp_ctx->iconv_handle.
    
    Calling the utility function reinit_iconv_handle()
    instead merely sets global_iconv_handle first, then
    assigns it (as the return) to lp_ctx->iconv_handle.
    
    So all this is doing is reversing the order of
    setting global_iconv_handle and lp_ctx->iconv_handle
    to the same thing.
    
    Even the removal of the lines:
    
    -       struct smb_iconv_handle *old_ic = lp_ctx->iconv_handle
    -       if (old_ic == NULL) {
    -               old_ic = global_iconv_handle;
    
    has no effect, as remember that lp_ctx->iconv_handle
    is only ever set to the same value as global_iconv_handle,
    and once this function has been run once, lp_ctx->iconv_handle != NULL.
    
    This allows us finally to make global_iconv_handle private
    to the C source file that defines it.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit 766e9ff05e0689b0c0284e33e044a363ed4a4709
Author: Jeremy Allison <jra at samba.org>
Date:   Tue Apr 11 15:51:17 2017 -0700

    lib: param: Use utility functions to get rid of two more uses of global_iconv_handle.
    
    Add error return checking.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit 6086b0e5a2ca03ba3a3c16cae2a0fe79605f5a6a
Author: Jeremy Allison <jra at samba.org>
Date:   Tue Apr 11 15:47:17 2017 -0700

    s3:param: Use new utility function to hide use of global_iconv_handle
    
    Add error return check.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit b4e4042b37f94d3c0e2eb4767abda52189f807b4
Author: Jeremy Allison <jra at samba.org>
Date:   Tue Apr 11 15:44:08 2017 -0700

    s3:lib:charcnv: Remove use of global global_iconv_handle
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit c28e2c937a6223c49221315384c01074a00161eb
Author: Jeremy Allison <jra at samba.org>
Date:   Tue Apr 11 15:42:39 2017 -0700

    lib:charset: Add utility functions reinit_iconv_handle() and free_iconv_handle(void)
    
    Not yet used. Will enable us to make global_iconv_handle private.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>

commit 3afbdb7a0e5c5e4bacc40f80ad0e8981b0af4b88
Author: Jeremy Allison <jra at samba.org>
Date:   Tue Apr 11 15:31:17 2017 -0700

    lib: Remove smb_iconv_handle_reinit_lp()
    
    It's merely a wrapper for smb_iconv_handle_reinit(),
    only used in one place and smb_iconv_handle_reinit()
    is already called from lib/param/loadparm.c.
    
    Removing this will make it easier to make global_iconv_handle
    private state to lib/util/charset/codepoints.c later.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 lib/param/loadparm.c          | 34 +++++++++++++++++++++-------------
 lib/param/param.h             |  4 ----
 lib/param/util.c              | 11 -----------
 lib/util/charset/charset.h    |  6 +++++-
 lib/util/charset/codepoints.c | 32 ++++++++++++++++++++++++++++----
 lib/util/debug.c              |  2 +-
 source3/lib/charcnv.c         |  2 +-
 source3/lib/system.c          | 12 +++++++-----
 source3/param/loadparm.c      | 11 ++++++++---
 source3/smbd/sec_ctx.c        |  3 +--
 10 files changed, 72 insertions(+), 45 deletions(-)


Changeset truncated at 500 lines:

diff --git a/lib/param/loadparm.c b/lib/param/loadparm.c
index 4d21d88..d7287ab 100644
--- a/lib/param/loadparm.c
+++ b/lib/param/loadparm.c
@@ -1265,10 +1265,14 @@ bool handle_charset(struct loadparm_context *lp_ctx, struct loadparm_service *se
 {
 	if (lp_ctx->s3_fns) {
 		if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
-			global_iconv_handle = smb_iconv_handle_reinit(NULL,
-							lpcfg_dos_charset(lp_ctx),
-							lpcfg_unix_charset(lp_ctx),
-							true, global_iconv_handle);
+			struct smb_iconv_handle *ret = NULL;
+
+			ret = reinit_iconv_handle(NULL,
+						  lpcfg_dos_charset(lp_ctx),
+						  lpcfg_unix_charset(lp_ctx));
+			if (ret == NULL) {
+				smb_panic("reinit_iconv_handle failed");
+			}
 		}
 
 	}
@@ -1303,16 +1307,19 @@ bool handle_dos_charset(struct loadparm_context *lp_ctx, struct loadparm_service
 		}
 
 		if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
+			struct smb_iconv_handle *ret = NULL;
 			if (is_utf8) {
 				DEBUG(0,("ERROR: invalid DOS charset: 'dos charset' must not "
 					"be UTF8, using (default value) %s instead.\n",
 					DEFAULT_DOS_CHARSET));
 				pszParmValue = DEFAULT_DOS_CHARSET;
 			}
-			global_iconv_handle = smb_iconv_handle_reinit(NULL,
-							lpcfg_dos_charset(lp_ctx),
-							lpcfg_unix_charset(lp_ctx),
-							true, global_iconv_handle);
+			ret = reinit_iconv_handle(NULL,
+						lpcfg_dos_charset(lp_ctx),
+						lpcfg_unix_charset(lp_ctx));
+			if (ret == NULL) {
+				smb_panic("reinit_iconv_handle failed");
+			}
 		}
 	}
 
@@ -3349,16 +3356,17 @@ struct smb_iconv_handle *lpcfg_iconv_handle(struct loadparm_context *lp_ctx)
 
 _PUBLIC_ void reload_charcnv(struct loadparm_context *lp_ctx)
 {
-	struct smb_iconv_handle *old_ic = lp_ctx->iconv_handle;
 	if (!lp_ctx->global) {
 		return;
 	}
 
-	if (old_ic == NULL) {
-		old_ic = global_iconv_handle;
+	lp_ctx->iconv_handle =
+		reinit_iconv_handle(lp_ctx,
+				    lpcfg_dos_charset(lp_ctx),
+				    lpcfg_unix_charset(lp_ctx));
+	if (lp_ctx->iconv_handle == NULL) {
+		smb_panic("reinit_iconv_handle failed");
 	}
-	lp_ctx->iconv_handle = smb_iconv_handle_reinit_lp(lp_ctx, lp_ctx, old_ic);
-	global_iconv_handle = lp_ctx->iconv_handle;
 }
 
 _PUBLIC_ char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx)
diff --git a/lib/param/param.h b/lib/param/param.h
index e123e67..a6dbafa 100644
--- a/lib/param/param.h
+++ b/lib/param/param.h
@@ -301,10 +301,6 @@ char *smbd_tmp_path(TALLOC_CTX *mem_ctx,
 
 const char *lpcfg_imessaging_path(TALLOC_CTX *mem_ctx,
 				       struct loadparm_context *lp_ctx);
-struct smb_iconv_handle *smb_iconv_handle_reinit_lp(TALLOC_CTX *mem_ctx,
-							      struct loadparm_context *lp_ctx,
-							      struct smb_iconv_handle *old_ic);
-
 const char *lpcfg_sam_name(struct loadparm_context *lp_ctx);
 const char *lpcfg_sam_dnsname(struct loadparm_context *lp_ctx);
 
diff --git a/lib/param/util.c b/lib/param/util.c
index 233981a..52796562 100644
--- a/lib/param/util.c
+++ b/lib/param/util.c
@@ -248,17 +248,6 @@ const char *lpcfg_imessaging_path(TALLOC_CTX *mem_ctx,
 	return smbd_tmp_path(mem_ctx, lp_ctx, "msg");
 }
 
-struct smb_iconv_handle *smb_iconv_handle_reinit_lp(TALLOC_CTX *mem_ctx,
-							      struct loadparm_context *lp_ctx,
-							      struct smb_iconv_handle *old_ic)
-{
-	return smb_iconv_handle_reinit(mem_ctx, lpcfg_dos_charset(lp_ctx),
-				       lpcfg_unix_charset(lp_ctx),
-				       true,
-				       old_ic);
-}
-
-
 const char *lpcfg_sam_name(struct loadparm_context *lp_ctx)
 {
 	switch (lpcfg_server_role(lp_ctx)) {
diff --git a/lib/util/charset/charset.h b/lib/util/charset/charset.h
index ca7a437..ff466c3 100644
--- a/lib/util/charset/charset.h
+++ b/lib/util/charset/charset.h
@@ -164,12 +164,16 @@ bool convert_string_error(charset_t from, charset_t to,
 			  void *dest, size_t destlen,
 			  size_t *converted_size);
 
-extern struct smb_iconv_handle *global_iconv_handle;
 struct smb_iconv_handle *get_iconv_handle(void);
 struct smb_iconv_handle *get_iconv_testing_handle(TALLOC_CTX *mem_ctx, 
 						  const char *dos_charset, 
 						  const char *unix_charset,
 						  bool use_builtin_handlers);
+struct smb_iconv_handle *reinit_iconv_handle(TALLOC_CTX *mem_ctx,
+				const char *dos_charset,
+				const char *unix_charset);
+void free_iconv_handle(void);
+
 smb_iconv_t get_conv_handle(struct smb_iconv_handle *ic,
 			    charset_t from, charset_t to);
 const char *charset_name(struct smb_iconv_handle *ic, charset_t ch);
diff --git a/lib/util/charset/codepoints.c b/lib/util/charset/codepoints.c
index cfb0b27..3f380b9 100644
--- a/lib/util/charset/codepoints.c
+++ b/lib/util/charset/codepoints.c
@@ -16502,13 +16502,19 @@ struct smb_iconv_handle {
 	smb_iconv_t conv_handles[NUM_CHARSETS][NUM_CHARSETS];
 };
 
-struct smb_iconv_handle *global_iconv_handle = NULL;
+static struct smb_iconv_handle *global_iconv_handle = NULL;
 
 struct smb_iconv_handle *get_iconv_handle(void)
 {
-	if (global_iconv_handle == NULL)
-		global_iconv_handle = smb_iconv_handle_reinit(talloc_autofree_context(),
-							      "ASCII", "UTF-8", true, NULL);
+	if (global_iconv_handle == NULL) {
+		global_iconv_handle =
+			smb_iconv_handle_reinit(NULL,
+						"ASCII",
+						"UTF-8",
+						true,
+						NULL);
+	}
+
 	return global_iconv_handle;
 }
 
@@ -16521,6 +16527,24 @@ struct smb_iconv_handle *get_iconv_testing_handle(TALLOC_CTX *mem_ctx,
 				       dos_charset, unix_charset, use_builtin_handlers, NULL);
 }
 
+struct smb_iconv_handle *reinit_iconv_handle(TALLOC_CTX *mem_ctx,
+				const char *dos_charset,
+				const char *unix_charset)
+{
+	global_iconv_handle =
+		smb_iconv_handle_reinit(mem_ctx,
+					dos_charset,
+					unix_charset,
+					true,
+					global_iconv_handle);
+	return global_iconv_handle;
+}
+
+void free_iconv_handle(void)
+{
+	TALLOC_FREE(global_iconv_handle);
+}
+
 /**
  * Return the name of a charset to give to iconv().
  **/
diff --git a/lib/util/debug.c b/lib/util/debug.c
index f48daf6..5abca41 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -488,7 +488,7 @@ static void debug_backends_log(const char *msg, int msg_level)
 	 * a buffer without the newline character.
 	 */
 	len = MIN(strlen(msg), FORMAT_BUFR_SIZE - 1);
-	if (msg[len - 1] == '\n') {
+	if ((len > 0) && (msg[len - 1] == '\n')) {
 		len--;
 	}
 
diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c
index 66a98f9..5ec070c 100644
--- a/source3/lib/charcnv.c
+++ b/source3/lib/charcnv.c
@@ -27,7 +27,7 @@
  **/
 void gfree_charcnv(void)
 {
-	TALLOC_FREE(global_iconv_handle);
+	free_iconv_handle();
 }
 
 /**
diff --git a/source3/lib/system.c b/source3/lib/system.c
index 3d3eeed..99462b6 100644
--- a/source3/lib/system.c
+++ b/source3/lib/system.c
@@ -790,12 +790,11 @@ int groups_max(void)
 
 static int sys_broken_getgroups(int setlen, gid_t *gidset)
 {
-	GID_T gid;
 	GID_T *group_list;
 	int i, ngroups;
 
 	if(setlen == 0) {
-		return getgroups(setlen, &gid);
+		return getgroups(0, NULL);
 	}
 
 	/*
@@ -808,9 +807,6 @@ static int sys_broken_getgroups(int setlen, gid_t *gidset)
 		return -1;
 	} 
 
-	if (setlen == 0)
-		setlen = groups_max();
-
 	if((group_list = SMB_MALLOC_ARRAY(GID_T, setlen)) == NULL) {
 		DEBUG(0,("sys_getgroups: Malloc fail.\n"));
 		return -1;
@@ -823,6 +819,12 @@ static int sys_broken_getgroups(int setlen, gid_t *gidset)
 		return -1;
 	}
 
+	/*
+	 * We're safe here as if ngroups > setlen then
+	 * getgroups *must* return EINVAL.
+	 * pubs.opengroup.org/onlinepubs/009695399/functions/getgroups.html
+	 */
+
 	for(i = 0; i < ngroups; i++)
 		gidset[i] = (gid_t)group_list[i];
 
diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c
index b543a6f..3c597ec 100644
--- a/source3/param/loadparm.c
+++ b/source3/param/loadparm.c
@@ -2368,9 +2368,14 @@ bool lp_file_list_changed(void)
  **/
 static void init_iconv(void)
 {
-	global_iconv_handle = smb_iconv_handle_reinit(NULL, lp_dos_charset(),
-						      lp_unix_charset(),
-						      true, global_iconv_handle);
+	struct smb_iconv_handle *ret = NULL;
+
+	ret = reinit_iconv_handle(NULL,
+				  lp_dos_charset(),
+				  lp_unix_charset());
+	if (ret == NULL) {
+		smb_panic("reinit_iconv_handle failed");
+	}
 }
 
 /***************************************************************************
diff --git a/source3/smbd/sec_ctx.c b/source3/smbd/sec_ctx.c
index 33d987f..5e0710e 100644
--- a/source3/smbd/sec_ctx.c
+++ b/source3/smbd/sec_ctx.c
@@ -139,7 +139,6 @@ static void gain_root(void)
 static int get_current_groups(gid_t gid, uint32_t *p_ngroups, gid_t **p_groups)
 {
 	int i;
-	gid_t grp;
 	int ngroups;
 	gid_t *groups = NULL;
 
@@ -153,7 +152,7 @@ static int get_current_groups(gid_t gid, uint32_t *p_ngroups, gid_t **p_groups)
 	set_effective_gid(gid);
 	samba_setgid(gid);
 
-	ngroups = sys_getgroups(0,&grp);
+	ngroups = sys_getgroups(0, NULL);
 	if (ngroups <= 0) {
 		goto fail;
 	}


-- 
Samba Shared Repository



More information about the samba-cvs mailing list