@@ -687,6 +687,7 @@ lstat02_64 lstat02_64
mallinfo01 mallinfo01
mallinfo02 mallinfo02
+mallinfo03 mallinfo03
mallopt01 mallopt01
@@ -1,2 +1,3 @@
/mallinfo01
/mallinfo02
+/mallinfo03
new file mode 100644
@@ -0,0 +1,50 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
+ */
+
+/*\
+ * [DESCRIPTION]
+ *
+ * Basic mallinfo() test. Test the member of struct mallinfo
+ * whether overflow when setting 2G size. mallinfo() is deprecated
+ * since the type used for the fields is too small. We should use
+ * mallinfo2() and it was added since glibc 2.33.
+\*/
+
+#include "mallinfo_common.h"
+#include "tst_safe_macros.h"
+
+#ifdef HAVE_MALLINFO
+
+void test_mallinfo(void)
+{
+ struct mallinfo info;
+ char *buf;
+ size_t size = 2UL * 1024UL * 1024UL * 1024UL;
+
+ buf = malloc(size);
+ if (!buf) {
+ tst_res(TCONF, "Current system can not malloc 2G space, skip it");
+ return;
+ }
+ info = mallinfo();
+ if (info.hblkhd < 0) {
+ print_mallinfo("Test malloc 2G", &info);
+ tst_res(TPASS, "The member of struct mallinfo overflow, we should use mallinfo2");
+ } else {
+ /*We will never get here*/
+ tst_res(TFAIL, "The member of struct mallinfo doesn't overflow");
+ }
+
+ free(buf);
+}
+
+static struct tst_test test = {
+ .test_all = test_mallinfo,
+};
+
+#else
+TST_TEST_TCONF("system doesn't implement non-POSIX mallinfo()");
+#endif
Since these members of mallinfo struct use int type, it will overflow when allocating 2G size. mallinfo() is deprecated and we should use mallinfo2() in the future. Signed-off-by: Yang Xu <xuyang2018.jy@cn.fujitsu.com> --- runtest/syscalls | 1 + testcases/kernel/syscalls/mallinfo/.gitignore | 1 + .../kernel/syscalls/mallinfo/mallinfo03.c | 50 +++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 testcases/kernel/syscalls/mallinfo/mallinfo03.c