[SCM] Samba Shared Repository - branch master updated

Andrew Bartlett abartlet at samba.org
Thu Mar 9 21:34:01 UTC 2023


The branch, master has been updated
       via  78635d55fb8 audit_logging: Use `json_int_t` instead of `int` for `json_add_int` value type
       via  35aa7db6414 audit_logging:tests: Add big_int test for `json_add_int`
       via  b3146763a45 lib:util: prefer mallinfo2() over mallinfo() if available
      from  f55a357c6b9 dsgetdcname: do not assume local system uses IPv4

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


- Log -----------------------------------------------------------------
commit 78635d55fb819d422d0c4c32bb63aab95f735e4b
Author: Li Yuxuan <liyuxuan.darfux at bytedance.com>
Date:   Thu Mar 9 11:11:28 2023 +0800

    audit_logging: Use `json_int_t` instead of `int` for `json_add_int` value type
    
    Functions like `add_lock_to_json` and `add_profile_item_to_json` pass
    some values to `json_add_int` with `intmax_t` types. This may cause
    arithmetic overflow when the value grows very fast, such as the
    read_bytes profiling data.
    Use `json_add_int` instead of `int` to avoid the overflow.
    
    RN: Make json output show intmax_t value properly
    
    Signed-off-by: Li Yuxuan <liyuxuan.darfux at bytedance.com>
    Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>
    
    Autobuild-User(master): Andrew Bartlett <abartlet at samba.org>
    Autobuild-Date(master): Thu Mar  9 21:33:43 UTC 2023 on atb-devel-224

commit 35aa7db641484b33ff55a7d8fe2d21c6b411f847
Author: Li Yuxuan <liyuxuan.darfux at bytedance.com>
Date:   Tue Mar 7 10:52:47 2023 +0800

    audit_logging:tests: Add big_int test for `json_add_int`
    
    Show that `json_add_int` can't handle value larger than int32 due to
    overflow.
    
    Add knownfail.
    
    Signed-off-by: Li Yuxuan <liyuxuan.darfux at bytedance.com>
    Reviewed-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit b3146763a45d3a52ae1f669ad1b37155f67a16e6
Author: Dmitry Antipov <dantipov at cloudlinux.com>
Date:   Tue Feb 7 18:09:15 2023 +0300

    lib:util: prefer mallinfo2() over mallinfo() if available
    
    Prefer mallinfo2() with 'size_t' fields over deprecated
    mallinfo() (with 'int' fields which may wrap around zero
    and so be inaccurate on a 64-bit system) and move relevant
    checks to lib/util/wscript_configure because mallinfo()
    is not used beyond 'samba-util'.
    
    Suggested-by: Andreas Schneider <asn at samba.org>
    Signed-off-by: Dmitry Antipov <dantipov at cloudlinux.com>
    Reviewed-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

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

Summary of changes:
 lib/audit_logging/audit_logging.c            | 14 +++++++-----
 lib/audit_logging/audit_logging.h            |  2 +-
 lib/audit_logging/tests/audit_logging_test.c | 11 +++++++++-
 lib/util/talloc_report_printf.c              | 33 ++++++++++++++++++++++++----
 lib/util/wscript_configure                   | 12 ++++++++++
 source3/wscript                              | 12 ----------
 6 files changed, 60 insertions(+), 24 deletions(-)


Changeset truncated at 500 lines:

diff --git a/lib/audit_logging/audit_logging.c b/lib/audit_logging/audit_logging.c
index 43acf9512c9..3ab14b2a187 100644
--- a/lib/audit_logging/audit_logging.c
+++ b/lib/audit_logging/audit_logging.c
@@ -385,31 +385,33 @@ bool json_is_invalid(const struct json_object *object)
  *        -1 the operation failed
  *
  */
-int json_add_int(struct json_object *object, const char *name, const int value)
+int json_add_int(struct json_object *object, const char *name, const json_int_t value)
 {
 	int ret = 0;
 	json_t *integer = NULL;
 
 	if (json_is_invalid(object)) {
-		DBG_ERR("Unable to add int [%s] value [%d], "
+		DBG_ERR("Unable to add int [%s] value [%jd], "
 			"target object is invalid\n",
 			name,
-			value);
+			(intmax_t)value);
 		return JSON_ERROR;
 	}
 
 	integer = json_integer(value);
 	if (integer == NULL) {
-		DBG_ERR("Unable to create integer value [%s] value [%d]\n",
+		DBG_ERR("Unable to create integer value [%s] value [%jd]\n",
 			name,
-			value);
+			(intmax_t)value);
 		return JSON_ERROR;
 	}
 
 	ret = json_object_set_new(object->root, name, integer);
 	if (ret != 0) {
 		json_decref(integer);
-		DBG_ERR("Unable to add int [%s] value [%d]\n", name, value);
+		DBG_ERR("Unable to add int [%s] value [%jd]\n",
+			name,
+			(intmax_t)value);
 	}
 	return ret;
 }
diff --git a/lib/audit_logging/audit_logging.h b/lib/audit_logging/audit_logging.h
index 49576ece68d..eb7c103944d 100644
--- a/lib/audit_logging/audit_logging.h
+++ b/lib/audit_logging/audit_logging.h
@@ -58,7 +58,7 @@ _WARN_UNUSED_RESULT_ bool json_is_invalid(const struct json_object *object);
 
 _WARN_UNUSED_RESULT_ int json_add_int(struct json_object *object,
 				      const char *name,
-				      const int value);
+				      const json_int_t value);
 _WARN_UNUSED_RESULT_ int json_add_bool(struct json_object *object,
 				       const char *name,
 				       const bool value);
diff --git a/lib/audit_logging/tests/audit_logging_test.c b/lib/audit_logging/tests/audit_logging_test.c
index 1f871c2e5f4..d393b986cf0 100644
--- a/lib/audit_logging/tests/audit_logging_test.c
+++ b/lib/audit_logging/tests/audit_logging_test.c
@@ -63,8 +63,10 @@ static void test_json_add_int(_UNUSED_ void **state)
 {
 	struct json_object object;
 	struct json_t *value = NULL;
+	json_int_t m;
 	double n;
 	int rc = 0;
+	intmax_t big_int = ((intmax_t)1)<<33;
 
 	object = json_new_object();
 	rc = json_add_int(&object, "positive_one", 1);
@@ -73,8 +75,10 @@ static void test_json_add_int(_UNUSED_ void **state)
 	assert_int_equal(0, rc);
 	rc = json_add_int(&object, "negative_one", -1);
 	assert_int_equal(0, rc);
+	rc = json_add_int(&object, "big_int", big_int);
+	assert_int_equal(0, rc);
 
-	assert_int_equal(3, json_object_size(object.root));
+	assert_int_equal(4, json_object_size(object.root));
 
 	value = json_object_get(object.root, "positive_one");
 	assert_true(json_is_integer(value));
@@ -91,6 +95,11 @@ static void test_json_add_int(_UNUSED_ void **state)
 	n = json_number_value(value);
 	assert_true(n == -1.0);
 
+	value = json_object_get(object.root, "big_int");
+	assert_true(json_is_integer(value));
+	m = json_integer_value(value);
+	assert_int_equal(m, big_int);
+
 	object.valid = false;
 	rc = json_add_int(&object, "should fail 1", 0xf1);
 	assert_int_equal(JSON_ERROR, rc);
diff --git a/lib/util/talloc_report_printf.c b/lib/util/talloc_report_printf.c
index cdf75b64913..3011c62536e 100644
--- a/lib/util/talloc_report_printf.c
+++ b/lib/util/talloc_report_printf.c
@@ -76,12 +76,37 @@ static void talloc_report_printf_helper(
 void talloc_full_report_printf(TALLOC_CTX *root, FILE *f)
 {
 	talloc_report_depth_cb(root, 0, -1, talloc_report_printf_helper, f);
+#if defined(HAVE_MALLINFO2)
+	{
+		struct mallinfo2 mi2 = mallinfo2();
 
-#ifdef HAVE_MALLINFO
+		fprintf(f,
+			"mallinfo:\n"
+			"    arena: %zu\n"
+			"    ordblks: %zu\n"
+			"    smblks: %zu\n"
+			"    hblks: %zu\n"
+			"    hblkhd: %zu\n"
+			"    usmblks: %zu\n"
+			"    fsmblks: %zu\n"
+			"    uordblks: %zu\n"
+			"    fordblks: %zu\n"
+			"    keepcost: %zu\n",
+			mi2.arena,
+			mi2.ordblks,
+			mi2.smblks,
+			mi2.hblks,
+			mi2.hblkhd,
+			mi2.usmblks,
+			mi2.fsmblks,
+			mi2.uordblks,
+			mi2.fordblks,
+			mi2.keepcost);
+	}
+#elif defined(HAVE_MALLINFO)
 	{
-		struct mallinfo mi;
+		struct mallinfo mi = mallinfo();
 
-		mi = mallinfo();
 		fprintf(f,
 			"mallinfo:\n"
 			"    arena: %d\n"
@@ -105,5 +130,5 @@ void talloc_full_report_printf(TALLOC_CTX *root, FILE *f)
 			mi.fordblks,
 			mi.keepcost);
 	}
-#endif /* HAVE_MALLINFO */
+#endif /* HAVE_MALLINFO2 or HAVE_MALLINFO */
 }
diff --git a/lib/util/wscript_configure b/lib/util/wscript_configure
index fbaeb095dd4..27206e0e85a 100644
--- a/lib/util/wscript_configure
+++ b/lib/util/wscript_configure
@@ -122,6 +122,18 @@ conf.CHECK_CODE('struct statvfs buf; buf.f_flags = 0',
                 local_include=False,
                 execute=False)
 
+# Check for mallinfo2() first and fallback to mallinfo() if not found
+body = '''mi.arena + mi.ordblks + mi.smblks + mi.hblks + mi.hblkhd +
+    mi.usmblks + mi.fsmblks +  mi.uordblks + mi.fordblks + mi.keepcost'''
+if not conf.CHECK_CODE('''struct mallinfo2 mi = mallinfo2(); return %s;'''
+                       % body, 'HAVE_MALLINFO2',
+                       msg="Checking for mallinfo2()",
+                       headers='malloc.h'):
+    conf.CHECK_CODE('''struct mallinfo mi = mallinfo(); return %s;'''
+                    % body, 'HAVE_MALLINFO',
+                    msg="Checking for mallinfo()",
+                    headers='malloc.h')
+
 #
 # systemd removed the libsystemd-daemon and libsystemd-journal libraries. In newer
 # versions it is only libsystemd. As waf pkg-config handling does not provide
diff --git a/source3/wscript b/source3/wscript
index 58c7e2aecaf..ebaa29c779b 100644
--- a/source3/wscript
+++ b/source3/wscript
@@ -1649,18 +1649,6 @@ int main(void) {
                     define='HAVE_UNSHARE_CLONE_FS',
                     msg='for Linux unshare(CLONE_FS)')
 
-    # Check for mallinfo
-    conf.CHECK_CODE('''
-    struct mallinfo mi;
-    int tmp;
-
-    mi = mallinfo();
-    tmp = mi.arena + mi.ordblks + mi.smblks + mi.hblks +
-          mi.hblkhd + mi.usmblks + mi.fsmblks +  mi.uordblks +
-          mi.fordblks + mi.keepcost;
-    return tmp;
-    ''', 'HAVE_MALLINFO', msg="Checking for mallinfo()", headers='malloc.h')
-
     #
     # cluster support (CTDB)
     #


-- 
Samba Shared Repository



More information about the samba-cvs mailing list