This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch releases/13.0
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/releases/13.0 by this push:
new 335aacbf1a5 arch/common: fix host_flags_to_mode() O_RDONLY sentinel
collision
335aacbf1a5 is described below
commit 335aacbf1a503271cff253124ffdccd870210cbe
Author: liang.huang <[email protected]>
AuthorDate: Wed Jul 15 06:58:25 2026 +0800
arch/common: fix host_flags_to_mode() O_RDONLY sentinel collision
host_flags_to_mode() used a trailing 0 entry in modeflags[] as the
loop-termination sentinel. O_RDONLY is defined as 0 and is exactly
modeflags[1], so the loop's termination check fired before ever
comparing that entry, and a bare O_RDONLY open always fell through
to -EINVAL.
Bound the loop by array size (nitems()) instead of a value sentinel.
Signed-off-by: liang.huang <[email protected]>
---
arch/arm/src/common/arm_hostfs.c | 4 ++--
arch/arm64/src/common/arm64_hostfs.c | 4 ++--
arch/risc-v/src/common/riscv_hostfs.c | 4 ++--
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/arch/arm/src/common/arm_hostfs.c b/arch/arm/src/common/arm_hostfs.c
index 9f3d829c365..fbfd9a52485 100644
--- a/arch/arm/src/common/arm_hostfs.c
+++ b/arch/arm/src/common/arm_hostfs.c
@@ -31,6 +31,7 @@
#include <errno.h>
#include <fcntl.h>
#include <string.h>
+#include <sys/param.h>
#include <syscall.h>
#include <unistd.h>
@@ -94,11 +95,10 @@ static int host_flags_to_mode(int flags)
O_WRONLY | O_CREAT | O_APPEND,
O_RDWR | O_CREAT | O_APPEND | O_TEXT,
O_RDWR | O_CREAT | O_APPEND,
- 0,
};
int i;
- for (i = 0; modeflags[i] != 0; i++)
+ for (i = 0; i < nitems(modeflags); i++)
{
if ((modemasks & flags) == modeflags[i])
{
diff --git a/arch/arm64/src/common/arm64_hostfs.c
b/arch/arm64/src/common/arm64_hostfs.c
index 0bcbef7b098..ddd064ed07d 100644
--- a/arch/arm64/src/common/arm64_hostfs.c
+++ b/arch/arm64/src/common/arm64_hostfs.c
@@ -31,6 +31,7 @@
#include <errno.h>
#include <fcntl.h>
#include <string.h>
+#include <sys/param.h>
#include <syscall.h>
#include <unistd.h>
@@ -94,11 +95,10 @@ static int host_flags_to_mode(int flags)
O_WRONLY | O_CREAT | O_APPEND,
O_RDWR | O_CREAT | O_APPEND | O_TEXT,
O_RDWR | O_CREAT | O_APPEND,
- 0,
};
int i;
- for (i = 0; modeflags[i] != 0; i++)
+ for (i = 0; i < nitems(modeflags); i++)
{
if ((modemasks & flags) == modeflags[i])
{
diff --git a/arch/risc-v/src/common/riscv_hostfs.c
b/arch/risc-v/src/common/riscv_hostfs.c
index a22ea85440f..c077044054e 100644
--- a/arch/risc-v/src/common/riscv_hostfs.c
+++ b/arch/risc-v/src/common/riscv_hostfs.c
@@ -31,6 +31,7 @@
#include <errno.h>
#include <fcntl.h>
#include <string.h>
+#include <sys/param.h>
#include <syscall.h>
#include <unistd.h>
@@ -94,11 +95,10 @@ static int host_flags_to_mode(int flags)
O_WRONLY | O_CREAT | O_APPEND,
O_RDWR | O_CREAT | O_APPEND | O_TEXT,
O_RDWR | O_CREAT | O_APPEND,
- 0,
};
int i;
- for (i = 0; modeflags[i] != 0; i++)
+ for (i = 0; i < nitems(modeflags); i++)
{
if ((modemasks & flags) == modeflags[i])
{