AP_Filesystem: fixed fseek and open of directories

This commit is contained in:
Andrew Tridgell 2023-12-04 14:38:37 +11:00
parent a77331e725
commit 0f0aed66b7
2 changed files with 8 additions and 1 deletions

View File

@ -58,6 +58,12 @@ int AP_Filesystem_Posix::open(const char *fname, int flags, bool allow_absolute_
if (! allow_absolute_paths) {
fname = map_filename(fname);
}
struct stat st;
if (::stat(fname, &st) == 0 &&
((st.st_mode & S_IFMT) != S_IFREG && (st.st_mode & S_IFMT) != S_IFLNK)) {
// only allow links and files
return -1;
}
// we automatically add O_CLOEXEC as we always want it for ArduPilot FS usage
return ::open(fname, flags | O_CLOEXEC, 0644);
}

View File

@ -170,7 +170,8 @@ int apfs_fseek(APFS_FILE *stream, long offset, int whence)
{
CHECK_STREAM(stream, EOF);
stream->eof = false;
return AP::FS().lseek(stream->fd, offset, whence);
AP::FS().lseek(stream->fd, offset, whence);
return 0;
}
int apfs_ferror(APFS_FILE *stream)