Mercurial > vim
annotate src/testdir/test_rename.vim @ 34105:c4ad4778946c v9.1.0017
patch 9.1.0017: [security]: use-after-free in eval1_emsg()
Commit: https://github.com/vim/vim/commit/28d71b566a29ceea3a2d05bcee9264ed5d630d42
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Fri Jan 12 17:21:55 2024 +0100
patch 9.1.0017: [security]: use-after-free in eval1_emsg()
Problem: use-after-free in eval1_emsg() when an empty
line follows a lambda (by @yu3s)
Solution: only set evalarg->eval_using_cmdline = FALSE when
the *arg pointer is not null
fixes: #13833
closes: #13841
Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Fri, 12 Jan 2024 17:30:06 +0100 |
parents | de319bf98a39 |
children |
rev | line source |
---|---|
15961
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1 " Test rename() |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2 |
18277
f6dcf7eabd26
patch 8.1.2133: some tests fail when run as root
Bram Moolenaar <Bram@vim.org>
parents:
17982
diff
changeset
|
3 source shared.vim |
f6dcf7eabd26
patch 8.1.2133: some tests fail when run as root
Bram Moolenaar <Bram@vim.org>
parents:
17982
diff
changeset
|
4 |
15961
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5 func Test_rename_file_to_file() |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6 call writefile(['foo'], 'Xrename1') |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
8 call assert_equal(0, rename('Xrename1', 'Xrename2')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
9 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
10 call assert_equal('', glob('Xrename1')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
11 call assert_equal(['foo'], readfile('Xrename2')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
12 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
13 " When the destination file already exists, it should be overwritten. |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
14 call writefile(['foo'], 'Xrename1') |
30669
de319bf98a39
patch 9.0.0669: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents:
22087
diff
changeset
|
15 call writefile(['bar'], 'Xrename2', 'D') |
15961
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
16 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
17 call assert_equal(0, rename('Xrename1', 'Xrename2')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
18 call assert_equal('', glob('Xrename1')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
19 call assert_equal(['foo'], readfile('Xrename2')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
20 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
21 call delete('Xrename2') |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
22 endfunc |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
23 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
24 func Test_rename_file_ignore_case() |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
25 " With 'fileignorecase', renaming file will go through a temp file |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
26 " when the source and destination file only differ by case. |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
27 set fileignorecase |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
28 call writefile(['foo'], 'Xrename') |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
29 |
17982
2029737e6a22
patch 8.1.1987: more functions can be used as methods
Bram Moolenaar <Bram@vim.org>
parents:
15961
diff
changeset
|
30 call assert_equal(0, 'Xrename'->rename('XRENAME')) |
15961
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
31 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
32 call assert_equal(['foo'], readfile('XRENAME')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
33 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
34 set fileignorecase& |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
35 call delete('XRENAME') |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
36 endfunc |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
37 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
38 func Test_rename_same_file() |
30669
de319bf98a39
patch 9.0.0669: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents:
22087
diff
changeset
|
39 call writefile(['foo'], 'Xrename', 'D') |
15961
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
40 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
41 " When the source and destination are the same file, nothing |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
42 " should be done. The source file should not be deleted. |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
43 call assert_equal(0, rename('Xrename', 'Xrename')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
44 call assert_equal(['foo'], readfile('Xrename')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
45 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
46 call assert_equal(0, rename('./Xrename', 'Xrename')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
47 call assert_equal(['foo'], readfile('Xrename')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
48 endfunc |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
49 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
50 func Test_rename_dir_to_dir() |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
51 call mkdir('Xrenamedir1') |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
52 call writefile(['foo'], 'Xrenamedir1/Xrenamefile') |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
53 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
54 call assert_equal(0, rename('Xrenamedir1', 'Xrenamedir2')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
55 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
56 call assert_equal('', glob('Xrenamedir1')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
57 call assert_equal(['foo'], readfile('Xrenamedir2/Xrenamefile')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
58 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
59 call delete('Xrenamedir2/Xrenamefile') |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
60 call delete('Xrenamedir2', 'd') |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
61 endfunc |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
62 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
63 func Test_rename_same_dir() |
30669
de319bf98a39
patch 9.0.0669: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents:
22087
diff
changeset
|
64 call mkdir('Xrenamedir', 'R') |
15961
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
65 call writefile(['foo'], 'Xrenamedir/Xrenamefile') |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
66 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
67 call assert_equal(0, rename('Xrenamedir', 'Xrenamedir')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
68 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
69 call assert_equal(['foo'], readfile('Xrenamedir/Xrenamefile')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
70 endfunc |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
71 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
72 func Test_rename_copy() |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
73 " Check that when original file can't be deleted, rename() |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
74 " still succeeds but copies the file. |
30669
de319bf98a39
patch 9.0.0669: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents:
22087
diff
changeset
|
75 call mkdir('Xrenamedir', 'R') |
15961
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
76 call writefile(['foo'], 'Xrenamedir/Xrenamefile') |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
77 call setfperm('Xrenamedir', 'r-xr-xr-x') |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
78 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
79 call assert_equal(0, rename('Xrenamedir/Xrenamefile', 'Xrenamefile')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
80 |
18277
f6dcf7eabd26
patch 8.1.2133: some tests fail when run as root
Bram Moolenaar <Bram@vim.org>
parents:
17982
diff
changeset
|
81 if !has('win32') && !IsRoot() |
15961
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
82 " On Windows, the source file is removed despite |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
83 " its directory being made not writable. |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
84 call assert_equal(['foo'], readfile('Xrenamedir/Xrenamefile')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
85 endif |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
86 call assert_equal(['foo'], readfile('Xrenamefile')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
87 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
88 call setfperm('Xrenamedir', 'rwxrwxrwx') |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
89 call delete('Xrenamefile') |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
90 endfunc |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
91 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
92 func Test_rename_fails() |
30669
de319bf98a39
patch 9.0.0669: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents:
22087
diff
changeset
|
93 call writefile(['foo'], 'Xrenamefile', 'D') |
15961
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
94 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
95 " Can't rename into a non-existing directory. |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
96 call assert_notequal(0, rename('Xrenamefile', 'Xdoesnotexist/Xrenamefile')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
97 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
98 " Can't rename a non-existing file. |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
99 call assert_notequal(0, rename('Xdoesnotexist', 'Xrenamefile2')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
100 call assert_equal('', glob('Xrenamefile2')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
101 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
102 " When rename() fails, the destination file should not be deleted. |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
103 call assert_notequal(0, rename('Xdoesnotexist', 'Xrenamefile')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
104 call assert_equal(['foo'], readfile('Xrenamefile')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
105 |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
106 " Can't rename to en empty file name. |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
107 call assert_notequal(0, rename('Xrenamefile', '')) |
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
108 |
22087
ff21e2962490
patch 8.2.1593: tests do not check the error number properly
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
109 call assert_fails('call rename("Xrenamefile", [])', 'E730:') |
ff21e2962490
patch 8.2.1593: tests do not check the error number properly
Bram Moolenaar <Bram@vim.org>
parents:
21765
diff
changeset
|
110 call assert_fails('call rename(0z, "Xrenamefile")', 'E976:') |
15961
4024dbfd3099
patch 8.1.0986: rename() is not propertly tested
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
111 endfunc |
21765
08940efa6b4e
patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents:
18277
diff
changeset
|
112 |
08940efa6b4e
patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents:
18277
diff
changeset
|
113 " vim: shiftwidth=2 sts=2 expandtab |