1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * Copyright (c) 2021 FUJITSU LIMITED. All rights reserved. 4 * Author: Yang Xu <xuyang2018.jy@fujitsu.com> 5 */ 6 7 /*\ 8 * [Description] 9 * 10 * Basic mallinfo2() test. 11 * 12 * Test hblkhd member of struct mallinfo2 whether overflow when setting 2G size. 13 * 14 * Deprecated mallinfo() overflow in this case, that was the point for creating 15 * mallinfo2(). 16 */ 17 18 #include "mallinfo_common.h" 19 #include "tst_safe_macros.h" 20 21 #ifdef HAVE_MALLINFO2 22 test_mallinfo2(void)23void test_mallinfo2(void) 24 { 25 struct mallinfo2 info; 26 char *buf; 27 size_t size = 2UL * 1024UL * 1024UL * 1024UL; 28 29 buf = malloc(size); 30 31 if (!buf) 32 tst_brk(TCONF, "Current system can not malloc 2G space, skip it"); 33 34 info = mallinfo2(); 35 if (info.hblkhd < size) { 36 print_mallinfo2("Test malloc 2G", &info); 37 tst_res(TFAIL, "hblkhd member of struct mallinfo2 overflow?"); 38 } else { 39 tst_res(TPASS, "hblkhd member of struct mallinfo2 doesn't overflow"); 40 } 41 42 free(buf); 43 } 44 45 static struct tst_test test = { 46 .test_all = test_mallinfo2, 47 }; 48 49 #else 50 TST_TEST_TCONF("system doesn't implement non-POSIX mallinfo2()"); 51 #endif 52