From fd04678b6714bbdedf98cb86fe0b02b1f8d5ddf8 Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Fri, 11 Sep 2026 14:09:35 +1200 Subject: [PATCH] fix(mavlink): authorize FTP opens by access mode, not by flag bits (#28652) The write authorization added to _workOpen() in #28584 tested the open flags against O_WRONLY | O_RDWR | O_CREAT | O_TRUNC. On Linux O_RDONLY is zero so a read-only open never matched, but on NuttX O_RDONLY is a bit and O_RDWR is O_RDONLY | O_WRONLY, so every OpenFileRO was treated as a write and confined to the storage directory. That rejected reads of anything outside /fs/microsd with "File Protected", including the component metadata PX4 advertises under /etc/extras, so QGC could no longer load it from NuttX boards while SITL kept working. Decide on the access mode instead. CreateFile and OpenFileWO both open with O_WRONLY, so nothing changes for the write paths. Assisted-by: Claude:claude-fable-5-1 Signed-off-by: Julian Oes --- src/modules/mavlink/mavlink_ftp.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/modules/mavlink/mavlink_ftp.cpp b/src/modules/mavlink/mavlink_ftp.cpp index 1f6cfd65cac..a9227345bf8 100644 --- a/src/modules/mavlink/mavlink_ftp.cpp +++ b/src/modules/mavlink/mavlink_ftp.cpp @@ -591,9 +591,10 @@ MavlinkFTP::_workOpen(PayloadHeader *payload, int oflag) } // CreateFile and OpenFileWO create or truncate the file as part of the open, so the - // effect lands before any write arrives and has to be authorized here. - if ((oflag & (O_WRONLY | O_RDWR | O_CREAT | O_TRUNC)) != 0 - && !_validatePathIsWritable(_work_buffer1)) { + // effect lands before any write arrives and has to be authorized here. Test the + // access mode rather than the individual flags: on NuttX O_RDONLY is a bit and + // O_RDWR is O_RDONLY | O_WRONLY, so a read-only open would match O_RDWR. + if (for_write && !_validatePathIsWritable(_work_buffer1)) { return kErrFailFileProtected; }