1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * Copyright (C) 2018 Petr Vorel <pvorel@suse.cz> 4 * Copyright (C) 2018 Michael Moese <mmoese@suse.de> 5 * 6 * Based on the reproducer posted upstream so other copyrights may apply. 7 * Author: Dmitry V. Levin <ldv@altlinux.org> 8 * LTP conversion from glibc source: Petr Vorel <pvorel@suse.cz> 9 */ 10 11 /*\ 12 * [Description] 13 * 14 * CVE-2018-1000001 realpath buffer underflow. 15 * 16 * Based on glibc test io/tst-getcwd-abspath.c: 17 * https://sourceware.org/git/?p=glibc.git;a=commit;h=52a713fdd0a30e1bd79818e2e3c4ab44ddca1a94. 18 */ 19 20 #include "tst_test.h" 21 22 #include <errno.h> 23 #include <stdlib.h> 24 25 #define CHROOT_DIR "cve-2018-1000001" 26 setup(void)27static void setup(void) 28 { 29 SAFE_MKDIR(CHROOT_DIR, 0755); 30 SAFE_CHROOT(CHROOT_DIR); 31 } 32 run(void)33static void run(void) 34 { 35 TST_EXP_FAIL_PTR_NULL(realpath(".", NULL), ENOENT); 36 } 37 38 static struct tst_test test = { 39 .test_all = run, 40 .setup = setup, 41 .needs_root = 1, 42 .needs_tmpdir = 1, 43 .tags = (const struct tst_tag[]) { 44 {"CVE", "2018-1000001"}, 45 {} 46 } 47 }; 48