vim-patch:9.1.0662: filecopy() may return wrong value when readlink() fails (#29998)

Problem:  filecopy() may return wrong value when readlink() fails.
Solution: Set ret to -1 so that 0 is returned when readlink() fails.
          (zeertzjq)

closes: vim/vim#15438

da090f95df
This commit is contained in:
zeertzjq 2024-08-07 06:14:05 +08:00 committed by GitHub
parent 0a1212ef94
commit 4ddc4a11ca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2710,7 +2710,7 @@ int vim_rename(const char *from, const char *to)
}
/// Create the new file with same permissions as the original.
/// Return -1 for failure, 0 for success.
/// Return FAIL for failure, OK for success.
int vim_copyfile(const char *from, const char *to)
{
char *errmsg = NULL;
@ -2718,7 +2718,7 @@ int vim_copyfile(const char *from, const char *to)
#ifdef HAVE_READLINK
FileInfo from_info;
if (os_fileinfo_link(from, &from_info) && S_ISLNK(from_info.stat.st_mode)) {
int ret = FAIL;
int ret = -1;
char linkbuf[MAXPATHL + 1];
ssize_t len = readlink(from, linkbuf, MAXPATHL);