public inbox for linux-cifs@vger.kernel.org
 help / color / mirror / Atom feed
From: David Disseldorp <ddiss@suse.de>
To: linux-cifs@vger.kernel.org
Cc: Steve French <smfrench@gmail.com>,
	David Disseldorp <ddiss@suse.de>,
	Meetakshi Setiya <msetiya@microsoft.com>
Subject: [PATCH 3/3] mount.cifs: remove runtime pass_length calculation
Date: Tue, 31 Mar 2026 11:37:53 +1100	[thread overview]
Message-ID: <20260331012508.17410-4-ddiss@suse.de> (raw)
In-Reply-To: <20260331012508.17410-1-ddiss@suse.de>

The parsed_mount_info.password and parsed_mount_info.password2 arrays
are both the same length, so drop version-specific length calculations
and use a build-time assertion to avoid future breakage.

Cc: Meetakshi Setiya <msetiya@microsoft.com>
Signed-off-by: David Disseldorp <ddiss@suse.de>
---
 mount.cifs.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/mount.cifs.c b/mount.cifs.c
index 945196f..836a060 100644
--- a/mount.cifs.c
+++ b/mount.cifs.c
@@ -63,6 +63,7 @@
 #include "mount.h"
 #include "util.h"
 #include "resolve_host.h"
+#include "build_assert.h"
 
 #ifndef MS_MOVE 
 #define MS_MOVE 8192 
@@ -343,14 +344,12 @@ set_password(struct parsed_mount_info *parsed_info, const char *src,
 {
 	int is_pass2 = which_pass == OPT_PASS2 || which_pass == CRED_PASS2;
 
-	char *dst = is_pass2 ?
-				parsed_info->password2 : parsed_info->password;
-	unsigned int pass_length = is_pass2 ?
-					  sizeof(parsed_info->password2) : sizeof(parsed_info->password);
+	char *dst = is_pass2 ? parsed_info->password2 : parsed_info->password;
 	unsigned int i = 0, j = 0;
+	BUILD_ASSERT(sizeof(parsed_info->password) == sizeof(parsed_info->password2));
 
 	while (src[i]) {
-		if (j + 2 >= pass_length) {
+		if (j + 2 >= sizeof(parsed_info->password)) {
 			fprintf(stderr, "Converted password too long!\n");
 			return EX_USAGE;
 		}
@@ -362,7 +361,8 @@ set_password(struct parsed_mount_info *parsed_info, const char *src,
 	if (is_pass2)
 		parsed_info->got_password2 = 1;
 	else
-	parsed_info->got_password = 1;
+		parsed_info->got_password = 1;
+
 	return 0;
 }
 
@@ -681,10 +681,8 @@ get_password_from_file(int file_descript, char *filename,
 			   const int which_pass)
 {
 	int rc = 0;
-	int is_pass2 = which_pass == OPT_PASS2;
-	unsigned int pass_length = is_pass2 ?
-					  sizeof(parsed_info->password2) : sizeof(parsed_info->password);
-	char buf[pass_length];
+	char buf[sizeof(parsed_info->password)];
+	BUILD_ASSERT(sizeof(parsed_info->password) == sizeof(parsed_info->password2));
 
 	if (filename != NULL) {
 		rc = toggle_dac_capability(0, 1);
-- 
2.51.0


  parent reply	other threads:[~2026-03-31  1:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-31  0:37 [PATCH 0/3] mount.cifs: minor buflen tracking cleanups David Disseldorp
2026-03-31  0:37 ` [PATCH 1/3] build_assert: add ccan build_assert.h header David Disseldorp
2026-03-31  0:37 ` [PATCH 2/3] mount.cifs: adjust get_password_from_file() buf size David Disseldorp
2026-03-31  0:37 ` David Disseldorp [this message]
2026-03-31 18:06 ` [PATCH 0/3] mount.cifs: minor buflen tracking cleanups Henrique Carvalho
2026-04-01  2:14   ` Steve French

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=20260331012508.17410-4-ddiss@suse.de \
    --to=ddiss@suse.de \
    --cc=linux-cifs@vger.kernel.org \
    --cc=msetiya@microsoft.com \
    --cc=smfrench@gmail.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