mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-11-26 17:30:28 +08:00
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 <julian@oes.ch>
This commit is contained in:
1 parent
269fba3e53
commit
fd04678b67
1 file changed
+4
-3
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user