* [PATCH] erofs-utils: mount: fix unhandled realloc failure in flag parsing
@ 2026-04-05 12:02 Ajay Rajera
0 siblings, 0 replies; only message in thread
From: Ajay Rajera @ 2026-04-05 12:02 UTC (permalink / raw)
To: linux-erofs; +Cc: xiang, Ajay Rajera
erofsmount_parse_flagopts() correctly returns -ENOMEM when realloc()
fails while extending the mount options string. However, the caller
erofsmount_parse_options() directly assigns the return value to
mountcfg.flags without checking for negative error codes.
On realloc() failure, mountcfg.flags is set to -ENOMEM (-12), which
in two's complement silently activates nearly every mount flag bit
(MS_NOSUID, MS_NODEV, MS_NOEXEC, etc.). Instead of aborting with a
clear error, the program continues with a corrupted flags bitmask,
leading to unexpected mount behavior.
Fix by capturing the return value in a local variable first and
propagating the error to the caller before modifying mountcfg.flags.
Signed-off-by: Ajay Rajera <newajay.11r@gmail.com>
---
mount/main.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/mount/main.c b/mount/main.c
index 5fdda81..449b35b 100644
--- a/mount/main.c
+++ b/mount/main.c
@@ -303,12 +303,17 @@ static int erofsmount_parse_options(int argc, char **argv)
}
cfg.c_dbg_lvl = i;
break;
- case 'o':
+ case 'o': {
+ long flags;
+
mountcfg.full_options = optarg;
- mountcfg.flags =
- erofsmount_parse_flagopts(optarg, mountcfg.flags,
+ flags = erofsmount_parse_flagopts(optarg, mountcfg.flags,
&mountcfg.options);
+ if (flags < 0)
+ return flags;
+ mountcfg.flags = flags;
break;
+ }
case 't':
dot = strchr(optarg, '.');
if (dot) {
--
2.51.0.windows.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-04-05 12:02 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-05 12:02 [PATCH] erofs-utils: mount: fix unhandled realloc failure in flag parsing Ajay Rajera
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox