1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) International Business Machines Corp., 2001
4 * 07/2001 Ported by Wayne Boyer
5 * Copyright (c) 2022 SUSE LLC Avinesh Kumar <[email protected]>
6 */
7
8 /*\
9 * [Description]
10 *
11 * Verify that rename(2) fails with ENAMETOOLONG, when
12 * oldpath or newpath is too long.
13 */
14
15 #include <stdio.h>
16 #include "tst_test.h"
17
18 #define MNT_POINT "mntpoint"
19 #define TEMP_FILE "tmpfile"
20
21 /* Path longer than PATH_MAX: fails the syscall right away (getname() fails) */
22 static char long_path[PATH_MAX + 1] = {[0 ... PATH_MAX] = 'a'};
23 /*
24 * Path fitting in PATH_MAX, but with an excessively long file name: rejected
25 * by the underlying filesystem
26 */
27 static char long_name[PATH_MAX] = {[0 ... PATH_MAX - 2] = 'a', [PATH_MAX - 1] = '\0'};
28
setup(void)29 static void setup(void)
30 {
31 SAFE_CHDIR(MNT_POINT);
32 SAFE_TOUCH(TEMP_FILE, 0700, NULL);
33 }
34
run(void)35 static void run(void)
36 {
37 TST_EXP_FAIL(rename(TEMP_FILE, long_path),
38 ENAMETOOLONG);
39 TST_EXP_FAIL(rename(TEMP_FILE, long_name),
40 ENAMETOOLONG);
41 }
42
43 static struct tst_test test = {
44 .setup = setup,
45 .test_all = run,
46 .needs_root = 1,
47 .mount_device = 1,
48 .mntpoint = MNT_POINT,
49 .all_filesystems = 1
50 };
51