public inbox for linux-erofs@ozlabs.org
 help / color / mirror / Atom feed
From: Ajay Rajera <newajay.11r@gmail.com>
To: linux-erofs@lists.ozlabs.org
Cc: xiang@kernel.org, Ajay Rajera <newajay.11r@gmail.com>
Subject: [PATCH] erofs-utils: mount: fix unhandled realloc failure in flag parsing
Date: Sun,  5 Apr 2026 17:32:12 +0530	[thread overview]
Message-ID: <20260405120213.136-1-newajay.11r@gmail.com> (raw)

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



                 reply	other threads:[~2026-04-05 12:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260405120213.136-1-newajay.11r@gmail.com \
    --to=newajay.11r@gmail.com \
    --cc=linux-erofs@lists.ozlabs.org \
    --cc=xiang@kernel.org \
    /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