From: David Disseldorp <ddiss@suse.de>
To: target-devel@vger.kernel.org
Cc: linux-scsi@vger.kernel.org, David Disseldorp <ddiss@suse.de>
Subject: [PATCH 1/2] scsi: target: add extract_param_str() helper
Date: Tue, 2 Jun 2026 21:43:57 +1000 [thread overview]
Message-ID: <20260602115840.26490-2-ddiss@suse.de> (raw)
In-Reply-To: <20260602115840.26490-1-ddiss@suse.de>
The existing extract_param() helper, detects and strips any hex (0x/0X)
or base64 (0b/0B). This makes sense for some parameters, but not strings
such as CHAP_N.
Signed-off-by: David Disseldorp <ddiss@suse.de>
---
drivers/target/iscsi/iscsi_target_nego.c | 37 ++++++++++++++++++++++++
drivers/target/iscsi/iscsi_target_nego.h | 1 +
2 files changed, 38 insertions(+)
diff --git a/drivers/target/iscsi/iscsi_target_nego.c b/drivers/target/iscsi/iscsi_target_nego.c
index b03ed154ca34e..53b17d3cc86c3 100644
--- a/drivers/target/iscsi/iscsi_target_nego.c
+++ b/drivers/target/iscsi/iscsi_target_nego.c
@@ -98,6 +98,43 @@ int extract_param(
return 0;
}
+/* same as extract_param() above, but don't interpret any type-prefix */
+int extract_param_str(
+ const char *in_buf,
+ const char *pattern,
+ unsigned int max_length,
+ char *out_buf)
+{
+ char *ptr;
+ int len;
+
+ if (!in_buf || !pattern || !out_buf)
+ return -EINVAL;
+
+ ptr = strstr(in_buf, pattern);
+ if (!ptr)
+ return -ENOENT;
+
+ ptr = strstr(ptr, "=");
+ if (!ptr)
+ return -EINVAL;
+
+ ptr += 1;
+ len = strlen_semi(ptr);
+ if (len < 0)
+ return -EINVAL;
+
+ if (len >= max_length) {
+ pr_err("Length of input: %d exceeds max_length:"
+ " %d\n", len, max_length);
+ return -EINVAL;
+ }
+ memcpy(out_buf, ptr, len);
+ out_buf[len] = '\0';
+
+ return 0;
+}
+
static struct iscsi_node_auth *iscsi_get_node_auth(struct iscsit_conn *conn)
{
struct iscsi_portal_group *tpg;
diff --git a/drivers/target/iscsi/iscsi_target_nego.h b/drivers/target/iscsi/iscsi_target_nego.h
index e60a46d348352..6b72edd2aef2e 100644
--- a/drivers/target/iscsi/iscsi_target_nego.h
+++ b/drivers/target/iscsi/iscsi_target_nego.h
@@ -13,6 +13,7 @@ struct iscsi_np;
extern void convert_null_to_semi(char *, int);
extern int extract_param(const char *, const char *, unsigned int, char *,
unsigned char *);
+extern int extract_param_str(const char *, const char *, unsigned int, char *);
extern int iscsi_target_check_login_request(struct iscsit_conn *,
struct iscsi_login *);
extern int iscsi_target_locate_portal(struct iscsi_np *, struct iscsit_conn *,
--
2.51.0
next prev parent reply other threads:[~2026-06-02 11:59 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-02 11:43 [PATCH 0/2] scsi: target: fix CHAP_N handling David Disseldorp
2026-06-02 11:43 ` David Disseldorp [this message]
2026-06-03 16:30 ` [PATCH 1/2] scsi: target: add extract_param_str() helper Lee Duncan
2026-06-02 11:43 ` [PATCH 2/2] scsi: target: fix auth when CHAP_N carries a hex/b64 prefix David Disseldorp
2026-06-03 16:30 ` Lee Duncan
2026-06-02 16:42 ` [PATCH 0/2] scsi: target: fix CHAP_N handling John Garry
2026-06-02 23:19 ` David Disseldorp
2026-06-03 8:24 ` John Garry
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=20260602115840.26490-2-ddiss@suse.de \
--to=ddiss@suse.de \
--cc=linux-scsi@vger.kernel.org \
--cc=target-devel@vger.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