From: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
To: "Nicholas A. Bellinger" <nab@linux-iscsi.org>,
Sagi Grimberg <sagig@mellanox.com>
Cc: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>,
Andy Grover <agrover@redhat.com>,
Thomas Glanzmann <thomas@glanzmann.de>,
Christophe Vu-Brugier <cvubrugier@yahoo.fr>,
linux-scsi@vger.kernel.org, target-devel@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH] target: iscsi: iscsi_target_tpg.c: Cleaning up possible size overwriting in conjunction with sprintf
Date: Sun, 12 Oct 2014 19:55:58 +0200 [thread overview]
Message-ID: <1413136558-20790-1-git-send-email-rickard_strandqvist@spectrumdigital.se> (raw)
Changed same snprintf and sprintf to strlcpy and strlcat.
This will guarantee that the string size is not overwritten,
and they are significantly faster than sprintf also.
Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
---
drivers/target/iscsi/iscsi_target_tpg.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/drivers/target/iscsi/iscsi_target_tpg.c b/drivers/target/iscsi/iscsi_target_tpg.c
index c3cb5c1..6fc8bfe 100644
--- a/drivers/target/iscsi/iscsi_target_tpg.c
+++ b/drivers/target/iscsi/iscsi_target_tpg.c
@@ -608,7 +608,6 @@ int iscsit_tpg_set_initiator_node_queue_depth(
int iscsit_ta_authentication(struct iscsi_portal_group *tpg, u32 authentication)
{
unsigned char buf1[256], buf2[256], *none = NULL;
- int len;
struct iscsi_param *param;
struct iscsi_tpg_attrib *a = &tpg->tpg_attrib;
@@ -626,34 +625,33 @@ int iscsit_ta_authentication(struct iscsi_portal_group *tpg, u32 authentication)
return -EINVAL;
if (authentication) {
- snprintf(buf1, sizeof(buf1), "%s", param->value);
+ strlcpy(buf1, param->value, sizeof(buf1));
none = strstr(buf1, NONE);
if (!none)
goto out;
if (!strncmp(none + 4, ",", 1)) {
if (!strcmp(buf1, none))
- sprintf(buf2, "%s", none+5);
+ strlcpy(buf2, none+5, sizeof(buf2));
else {
none--;
*none = '\0';
- len = sprintf(buf2, "%s", buf1);
+ strlcpy(buf2, buf1, sizeof(buf2));
none += 5;
- sprintf(buf2 + len, "%s", none);
+ strlcat(buf2, none, sizeof(buf2));
}
} else {
none--;
*none = '\0';
- sprintf(buf2, "%s", buf1);
+ strlcpy(buf2, buf1, sizeof(buf2));
}
if (iscsi_update_param_value(param, buf2) < 0)
return -EINVAL;
} else {
- snprintf(buf1, sizeof(buf1), "%s", param->value);
+ strlcpy(buf1, param->value, sizeof(buf1));
none = strstr(buf1, NONE);
if (none)
goto out;
- strncat(buf1, ",", strlen(","));
- strncat(buf1, NONE, strlen(NONE));
+ strlcat(buf1, "," NONE , sizeof(buf1));
if (iscsi_update_param_value(param, buf1) < 0)
return -EINVAL;
}
--
1.7.10.4
next reply other threads:[~2014-10-12 17:53 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-12 17:55 Rickard Strandqvist [this message]
2014-10-12 18:18 ` Joe Perches
2014-10-12 19:32 ` Rickard Strandqvist
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=1413136558-20790-1-git-send-email-rickard_strandqvist@spectrumdigital.se \
--to=rickard_strandqvist@spectrumdigital.se \
--cc=agrover@redhat.com \
--cc=cvubrugier@yahoo.fr \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=nab@linux-iscsi.org \
--cc=sagig@mellanox.com \
--cc=target-devel@vger.kernel.org \
--cc=thomas@glanzmann.de \
/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
all inboxes | Powered by JetHome®