xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/realpath/realpath01.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (C) 2018 Petr Vorel <[email protected]>
4  * Copyright (C) 2018 Michael Moese <[email protected]>
5  *
6  * cve-2018-1000001 realpath buffer underflow
7  * Based on the reproducer posted upstream so other copyrights may apply.
8  * Author: Dmitry V. Levin <[email protected]>
9  * LTP conversion from glibc source: Petr Vorel <[email protected]>
10  */
11 
12 #include "tst_test.h"
13 
14 #include <errno.h>
15 #include <stdlib.h>
16 
17 #define CHROOT_DIR "cve-2018-1000001"
18 
setup(void)19 static void setup(void)
20 {
21 	SAFE_MKDIR(CHROOT_DIR, 0755);
22 	SAFE_CHROOT(CHROOT_DIR);
23 }
24 
run(void)25 static void run(void)
26 {
27 	TST_EXP_FAIL_PTR_NULL(realpath(".", NULL), ENOENT);
28 }
29 
30 static struct tst_test test = {
31 	.test_all = run,
32 	.setup = setup,
33 	.needs_root = 1,
34 	.needs_tmpdir = 1,
35 	.tags = (const struct tst_tag[]) {
36 		{"CVE", "2018-1000001"},
37 		{}
38 	}
39 };
40