From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>,
"Claude Opus 4.6" <noreply@anthropic.com>
Subject: [PATCH v2025.09.y 39/58] open: add missing mode argument to O_CREAT calls
Date: Fri, 13 Mar 2026 14:25:23 +0100 [thread overview]
Message-ID: <20260313132631.2257573-40-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20260313132631.2257573-1-a.fatoum@pengutronix.de>
POSIX requires a third mode argument when open() is called with
O_CREAT. While barebox doesn't enforce file permissions, passing
mode satisfies static analyzers and is correct practice.
Also fix creat() to actually forward its mode parameter to open()
instead of silently discarding it.
Reported-by: GCC 14.2 -fanalyzer
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Link: https://lore.barebox.org/20260216084253.3547270-8-a.fatoum@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/echo.c | 2 +-
commands/edit.c | 2 +-
commands/uimage.c | 2 +-
commands/uncompress.c | 2 +-
common/bbu.c | 2 +-
common/console_common.c | 2 +-
common/fastboot.c | 4 ++--
common/globalvar.c | 2 +-
drivers/usb/gadget/function/dfu.c | 6 +++---
include/fcntl.h | 2 +-
lib/libfile.c | 4 ++--
lib/xymodem.c | 2 +-
12 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/commands/echo.c b/commands/echo.c
index 572b852ea32a..e39d9d30731b 100644
--- a/commands/echo.c
+++ b/commands/echo.c
@@ -96,7 +96,7 @@ static int do_echo(int argc, char *argv[])
exit_parse:
if (file) {
- fd = open(file, oflags);
+ fd = open(file, oflags, 0666);
if (fd < 0) {
perror("open");
return 1;
diff --git a/commands/edit.c b/commands/edit.c
index 28c9ab8877f7..c7262711d01f 100644
--- a/commands/edit.c
+++ b/commands/edit.c
@@ -243,7 +243,7 @@ static int save_file(const char *path)
int fd;
int ret = 0;
- fd = open(path, O_WRONLY | O_TRUNC | O_CREAT);
+ fd = open(path, O_WRONLY | O_TRUNC | O_CREAT, 0666);
if (fd < 0) {
printf("could not open file for writing: %m\n");
return fd;
diff --git a/commands/uimage.c b/commands/uimage.c
index 72b827b5b276..d7e881b35f7d 100644
--- a/commands/uimage.c
+++ b/commands/uimage.c
@@ -67,7 +67,7 @@ static int do_uimage(int argc, char *argv[])
}
if (extract) {
- fd = open(extract, O_WRONLY | O_CREAT | O_TRUNC);
+ fd = open(extract, O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (fd < 0) {
perror("open");
ret = fd;
diff --git a/commands/uncompress.c b/commands/uncompress.c
index 10884d675b3d..32e60e78072a 100644
--- a/commands/uncompress.c
+++ b/commands/uncompress.c
@@ -23,7 +23,7 @@ static int do_uncompress(int argc, char *argv[])
return 1;
}
- to = open(argv[2], O_WRONLY | O_CREAT);
+ to = open(argv[2], O_WRONLY | O_CREAT, 0666);
if (to < 0) {
perror("open");
ret = 1;
diff --git a/common/bbu.c b/common/bbu.c
index 03261583fe0b..1271ef2717f4 100644
--- a/common/bbu.c
+++ b/common/bbu.c
@@ -454,7 +454,7 @@ int bbu_std_file_handler(struct bbu_handler *handler,
if (ret)
return ret;
- fd = open(data->devicefile, oflags);
+ fd = open(data->devicefile, oflags, 0666);
if (fd < 0)
return fd;
diff --git a/common/console_common.c b/common/console_common.c
index 5b7a64c99c29..1c2da748b613 100644
--- a/common/console_common.c
+++ b/common/console_common.c
@@ -195,7 +195,7 @@ int log_writefile(const char *filepath)
int ret = 0, nbytes = 0, fd = -1;
struct log_entry *log;
- fd = open(filepath, O_WRONLY | O_CREAT | O_TRUNC);
+ fd = open(filepath, O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (fd < 0)
return -errno;
diff --git a/common/fastboot.c b/common/fastboot.c
index e5c79c22376c..e60091efc704 100644
--- a/common/fastboot.c
+++ b/common/fastboot.c
@@ -440,7 +440,7 @@ static void cb_download(struct fastboot *fb, const char *cmd)
close(fb->download_fd);
}
- fb->download_fd = open(fb->tempname, O_WRONLY | O_CREAT | O_TRUNC);
+ fb->download_fd = open(fb->tempname, O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (fb->download_fd < 0) {
fastboot_tx_print(fb, FASTBOOT_MSG_FAIL, "internal error");
return;
@@ -588,7 +588,7 @@ static int fastboot_handle_sparse(struct fastboot *fb,
return ret;
}
- fd = open(fentry->filename, flags);
+ fd = open(fentry->filename, flags, 0666);
if (fd < 0)
return -errno;
diff --git a/common/globalvar.c b/common/globalvar.c
index 77af6733a6a0..0472ecf9f58b 100644
--- a/common/globalvar.c
+++ b/common/globalvar.c
@@ -54,7 +54,7 @@ static int __nv_save(const char *prefix, const char *name, const char *val)
fname = basprintf("%s/%s", prefix, name);
- fd = open(fname, O_CREAT | O_WRONLY | O_TRUNC);
+ fd = open(fname, O_CREAT | O_WRONLY | O_TRUNC, 0666);
free(fname);
diff --git a/drivers/usb/gadget/function/dfu.c b/drivers/usb/gadget/function/dfu.c
index 893dcc7f7007..e8977a96d666 100644
--- a/drivers/usb/gadget/function/dfu.c
+++ b/drivers/usb/gadget/function/dfu.c
@@ -259,14 +259,14 @@ static void dfu_do_open_dnload(struct dfu_work *dw)
pr_debug("do open dnload\n");
if (dfu_file_entry->flags & FILE_LIST_FLAG_SAFE) {
- dfufd = open(DFU_TEMPFILE, O_WRONLY | O_CREAT);
+ dfufd = open(DFU_TEMPFILE, O_WRONLY | O_CREAT, 0666);
} else {
unsigned flags = O_WRONLY;
if (dfu_file_entry->flags & FILE_LIST_FLAG_CREATE)
flags |= O_CREAT | O_TRUNC;
- dfufd = open(dfu_file_entry->filename, flags);
+ dfufd = open(dfu_file_entry->filename, flags, 0666);
}
if (dfufd < 0) {
@@ -325,7 +325,7 @@ static void dfu_do_copy(struct dfu_work *dw)
if (dfu_file_entry->flags & FILE_LIST_FLAG_CREATE)
flags |= O_CREAT | O_TRUNC;
- fd = open(dfu_file_entry->filename, flags);
+ fd = open(dfu_file_entry->filename, flags, 0666);
if (fd < 0) {
perror("open");
dfu->dfu_state = DFU_STATE_dfuERROR;
diff --git a/include/fcntl.h b/include/fcntl.h
index db7926ee25fb..62dbf0f3c6d2 100644
--- a/include/fcntl.h
+++ b/include/fcntl.h
@@ -53,7 +53,7 @@ static inline int open(const char *pathname, int flags, ...)
static inline int creat(const char *pathname, mode_t mode)
{
- return open(pathname, O_CREAT | O_WRONLY | O_TRUNC);
+ return open(pathname, O_CREAT | O_WRONLY | O_TRUNC, mode);
}
#endif /* __FCNTL_H */
diff --git a/lib/libfile.c b/lib/libfile.c
index 7ca13a34b41d..e976b32e2c1f 100644
--- a/lib/libfile.c
+++ b/lib/libfile.c
@@ -380,7 +380,7 @@ int write_file(const char *filename, const void *buf, size_t size)
{
int fd, ret;
- fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT);
+ fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT, 0644);
if (fd < 0)
return fd;
@@ -476,7 +476,7 @@ int copy_file(const char *src, const char *dst, unsigned flags)
mode |= O_TRUNC;
}
- dstfd = open(dst, mode);
+ dstfd = open(dst, mode, 0666);
if (dstfd < 0) {
printf("could not open %s: %m\n", dst);
ret = dstfd;
diff --git a/lib/xymodem.c b/lib/xymodem.c
index 84a91157713b..bd5e114ee270 100644
--- a/lib/xymodem.c
+++ b/lib/xymodem.c
@@ -394,7 +394,7 @@ static int xy_await_header(struct xyz_ctxt *proto)
xy_dbg("header received, filename=%s, file length=%d\n",
proto->filename, proto->file_len);
if (proto->filename[0])
- proto->fd = open(proto->filename, O_WRONLY | O_CREAT);
+ proto->fd = open(proto->filename, O_WRONLY | O_CREAT, 0666);
else
proto->state = PROTO_STATE_FINISHED_XFER;
proto->nb_received = 0;
--
2.47.3
next prev parent reply other threads:[~2026-03-13 13:35 UTC|newest]
Thread overview: 60+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-13 13:24 [PATCH v2025.09.y 00/58] Backports for v2025.09.1 Ahmad Fatoum
2026-03-13 13:24 ` [PATCH v2025.09.y 01/58] clk: clkdev: fix format security Ahmad Fatoum
2026-03-13 13:24 ` [PATCH v2025.09.y 02/58] scripts: imx: fix string in further auth block Ahmad Fatoum
2026-03-13 13:24 ` [PATCH v2025.09.y 03/58] scripts: imx-image: support DCD_WRITE on closed dev Ahmad Fatoum
2026-03-13 13:24 ` [PATCH v2025.09.y 04/58] mci: am654-sdhci: Wait for transfer complete interrupt with MMC_RSP_BUSY cmd Ahmad Fatoum
2026-03-13 13:24 ` [PATCH v2025.09.y 05/58] video: simplefb-client: switch to dev_get_resource Ahmad Fatoum
2026-03-13 13:24 ` [PATCH v2025.09.y 06/58] MIPS: qemu-malta_defconfig: Use largest possible relocation table Ahmad Fatoum
2026-03-13 13:24 ` [PATCH v2025.09.y 07/58] firmware: handle firmware files being links correctly Ahmad Fatoum
2026-03-13 13:24 ` [PATCH v2025.09.y 08/58] drivers: don't propagate of_alias_get_id's -ENODEV out of probe Ahmad Fatoum
2026-03-13 13:24 ` [PATCH v2025.09.y 09/58] ARM: socfpga: arria10-reset-manager: release UART0 Ahmad Fatoum
2026-03-13 13:24 ` [PATCH v2025.09.y 10/58] bug: add support for CONFIG_DEBUG_BUGVERBOSE Ahmad Fatoum
2026-03-13 13:24 ` [PATCH v2025.09.y 11/58] driver: implement get_free_deviceid_from() Ahmad Fatoum
2026-03-13 13:24 ` [PATCH v2025.09.y 12/58] sandbox: fix make dependency for sandbox Ahmad Fatoum
2026-03-13 13:24 ` [PATCH v2025.09.y 13/58] gpio: Fix GPIOD_ASIS flag Ahmad Fatoum
2026-03-13 13:24 ` [PATCH v2025.09.y 14/58] i.MX: HAB: fix field return unlock fuse uid Ahmad Fatoum
2026-03-13 13:24 ` [PATCH v2025.09.y 15/58] ARM: cpu: common: skip R_ARM_NONE relocations Ahmad Fatoum
2026-03-13 13:25 ` [PATCH v2025.09.y 16/58] mmc: resolve conflict between MMC_CAP_NONREMOVABLE and MMC_CAP_1_8V_DDR Ahmad Fatoum
2026-03-13 13:25 ` [PATCH v2025.09.y 17/58] virtio: ring: fix stale data in queue after reset Ahmad Fatoum
2026-03-13 13:25 ` [PATCH v2025.09.y 18/58] scripts: Makefile.lib: suppress graph_port warnings for overlays Ahmad Fatoum
2026-03-13 13:25 ` [PATCH v2025.09.y 19/58] ARM: Rockchip: rk3576-prtpuk: suppress video graph warning Ahmad Fatoum
2026-03-13 13:25 ` [PATCH v2025.09.y 20/58] kbuild: fold rmdirs into rmfiles Ahmad Fatoum
2026-03-13 13:25 ` [PATCH v2025.09.y 21/58] mtd: nand: mxc_nand: use clk_get_optional for clock handling Ahmad Fatoum
2026-03-13 13:25 ` [PATCH v2025.09.y 22/58] FIT: fix double free issue with >1 reference count Ahmad Fatoum
2026-03-13 13:25 ` [PATCH v2025.09.y 23/58] net: phy: mdio_bus: fix freeing of cdev name before devfs_remove Ahmad Fatoum
2026-03-13 13:25 ` [PATCH v2025.09.y 24/58] bootm: fix bootm override saving/restoring Ahmad Fatoum
2026-03-13 13:25 ` [PATCH v2025.09.y 25/58] common: tlv: Correct eth address list fixup Ahmad Fatoum
2026-03-13 13:25 ` [PATCH v2025.09.y 26/58] common: tlv: fix link error when CONFIG_NET is disabled Ahmad Fatoum
2026-03-13 13:25 ` [PATCH v2025.09.y 27/58] include: array_size.h: make header self-contained Ahmad Fatoum
2026-03-13 13:25 ` [PATCH v2025.09.y 28/58] RISC-V: dts: fix generation of dtbs-list Ahmad Fatoum
2026-03-13 13:25 ` [PATCH v2025.09.y 29/58] of: overlay: propagate error unflattening DTBO Ahmad Fatoum
2026-03-13 13:25 ` [PATCH v2025.09.y 30/58] efi: fix potential NULL dereference Ahmad Fatoum
2026-03-13 13:25 ` [PATCH v2025.09.y 31/58] FIT: fix potential underflow of stack array Ahmad Fatoum
2026-03-13 13:25 ` [PATCH v2025.09.y 32/58] of: fdt: fix double free in fdt_ensure_space Ahmad Fatoum
2026-03-13 13:25 ` [PATCH v2025.09.y 33/58] of: overlay: initialize ret to fix garbage return value Ahmad Fatoum
2026-03-13 13:25 ` [PATCH v2025.09.y 34/58] firmware: xilinx-fpga: fix double free in probe error path Ahmad Fatoum
2026-03-13 13:25 ` [PATCH v2025.09.y 35/58] driver: fix missing va_end in dev_add_alias " Ahmad Fatoum
2026-03-13 13:25 ` [PATCH v2025.09.y 36/58] net: eth: avoid overlapping memcpy in eth_set_ethaddr Ahmad Fatoum
2026-03-13 13:25 ` [PATCH v2025.09.y 37/58] pmdomain: fix dereference before NULL check in genpd_get_from_provider Ahmad Fatoum
2026-03-13 13:25 ` [PATCH v2025.09.y 38/58] net: phy: add NULL check for phy driver in page accessors Ahmad Fatoum
2026-03-13 13:25 ` Ahmad Fatoum [this message]
2026-03-13 13:25 ` [PATCH v2025.09.y 40/58] hush: add NULL check for gl_pathv after do_glob_in_argv Ahmad Fatoum
2026-03-13 13:25 ` [PATCH v2025.09.y 41/58] i2c: rk3x: fix NULL pointer dereference on repeated NACK Ahmad Fatoum
2026-03-13 13:25 ` [PATCH v2025.09.y 42/58] mci: imx-esdhc: remove misleading NULL check for cmd pointer Ahmad Fatoum
2026-03-13 13:25 ` [PATCH v2025.09.y 43/58] mci: spi: initialize r1 to fix garbage return value Ahmad Fatoum
2026-03-13 13:25 ` [PATCH v2025.09.y 44/58] virtio: fix variable shadowing in virtqueue_add_sgs input scatter loop Ahmad Fatoum
2026-03-13 13:25 ` [PATCH v2025.09.y 45/58] video: mode-helpers: preserve sync polarity in fb_videomode conversion Ahmad Fatoum
2026-03-13 13:25 ` [PATCH v2025.09.y 46/58] ARM: rockchip: dmc: use define instead of hardcoded value Ahmad Fatoum
2026-03-13 13:25 ` [PATCH v2025.09.y 47/58] ARM: rockchip: atf: Fix memend Ahmad Fatoum
2026-03-13 13:25 ` [PATCH v2025.09.y 48/58] regulator: fix handling of off_on_delay Ahmad Fatoum
2026-03-13 13:25 ` [PATCH v2025.09.y 49/58] regulator: fixed: handle startup-delay-us property Ahmad Fatoum
2026-03-13 13:25 ` [PATCH v2025.09.y 50/58] scripts: include: break dependency of list.h on kernel.h Ahmad Fatoum
2026-03-13 13:25 ` [PATCH v2025.09.y 51/58] Makefile: include scripts/ in compile_commands.json Ahmad Fatoum
2026-03-13 13:25 ` [PATCH v2025.09.y 52/58] jwt: fix buffer overflow and double-free in jwt_part_parse Ahmad Fatoum
2026-03-13 13:25 ` [PATCH v2025.09.y 53/58] of: fdt: fix heap-buffer-overflow in fdt_machine_is_compatible Ahmad Fatoum
2026-03-13 13:25 ` [PATCH v2025.09.y 54/58] powerpc: fix initjmp storing function pointer at wrong offset Ahmad Fatoum
2026-03-13 13:25 ` [PATCH v2025.09.y 55/58] net: r8169: drain RX descriptor ring Ahmad Fatoum
2026-03-13 13:25 ` [PATCH v2025.09.y 56/58] of: fdt: refuse / in property and node names Ahmad Fatoum
2026-03-13 13:25 ` [PATCH v2025.09.y 57/58] FIT: reconstruct hashed-nodes property during verification Ahmad Fatoum
2026-03-13 13:25 ` [PATCH v2025.09.y 58/58] scripts: fix build failure with glibc 2.43 Ahmad Fatoum
2026-03-13 14:56 ` [PATCH v2025.09.y 00/58] Backports for v2025.09.1 Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260313132631.2257573-40-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=noreply@anthropic.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox