Commit 8d213559 authored by Joern Engel's avatar Joern Engel Committed by Nicholas Bellinger

target: Fix possible memory leak in aptpl_metadata parsing

Each case of match_strdup could leak memory if the same argument was
present before.  I am not too concerned, as it would require a
non-sensical combination like "target_lun=foo target_lun=bar", done
with root privileges and even then leak just a few bytes per instance.

But arg_p is different, as it will always leak memory.  Let's plug that
one.  And while at it, replace some &args[0] with args.

Found by coverity.
Signed-off-by: default avatarJoern Engel <joern@logfs.org>
Signed-off-by: default avatarNicholas Bellinger <nab@linux-iscsi.org>
parent fdc84d11
...@@ -1263,7 +1263,7 @@ static ssize_t target_core_dev_pr_store_attr_res_aptpl_metadata( ...@@ -1263,7 +1263,7 @@ static ssize_t target_core_dev_pr_store_attr_res_aptpl_metadata(
{ {
unsigned char *i_fabric = NULL, *i_port = NULL, *isid = NULL; unsigned char *i_fabric = NULL, *i_port = NULL, *isid = NULL;
unsigned char *t_fabric = NULL, *t_port = NULL; unsigned char *t_fabric = NULL, *t_port = NULL;
char *orig, *ptr, *arg_p, *opts; char *orig, *ptr, *opts;
substring_t args[MAX_OPT_ARGS]; substring_t args[MAX_OPT_ARGS];
unsigned long long tmp_ll; unsigned long long tmp_ll;
u64 sa_res_key = 0; u64 sa_res_key = 0;
...@@ -1295,14 +1295,14 @@ static ssize_t target_core_dev_pr_store_attr_res_aptpl_metadata( ...@@ -1295,14 +1295,14 @@ static ssize_t target_core_dev_pr_store_attr_res_aptpl_metadata(
token = match_token(ptr, tokens, args); token = match_token(ptr, tokens, args);
switch (token) { switch (token) {
case Opt_initiator_fabric: case Opt_initiator_fabric:
i_fabric = match_strdup(&args[0]); i_fabric = match_strdup(args);
if (!i_fabric) { if (!i_fabric) {
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto out;
} }
break; break;
case Opt_initiator_node: case Opt_initiator_node:
i_port = match_strdup(&args[0]); i_port = match_strdup(args);
if (!i_port) { if (!i_port) {
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto out;
...@@ -1316,7 +1316,7 @@ static ssize_t target_core_dev_pr_store_attr_res_aptpl_metadata( ...@@ -1316,7 +1316,7 @@ static ssize_t target_core_dev_pr_store_attr_res_aptpl_metadata(
} }
break; break;
case Opt_initiator_sid: case Opt_initiator_sid:
isid = match_strdup(&args[0]); isid = match_strdup(args);
if (!isid) { if (!isid) {
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto out;
...@@ -1330,15 +1330,9 @@ static ssize_t target_core_dev_pr_store_attr_res_aptpl_metadata( ...@@ -1330,15 +1330,9 @@ static ssize_t target_core_dev_pr_store_attr_res_aptpl_metadata(
} }
break; break;
case Opt_sa_res_key: case Opt_sa_res_key:
arg_p = match_strdup(&args[0]); ret = kstrtoull(args->from, 0, &tmp_ll);
if (!arg_p) {
ret = -ENOMEM;
goto out;
}
ret = kstrtoull(arg_p, 0, &tmp_ll);
if (ret < 0) { if (ret < 0) {
pr_err("kstrtoull() failed for" pr_err("kstrtoull() failed for sa_res_key=\n");
" sa_res_key=\n");
goto out; goto out;
} }
sa_res_key = (u64)tmp_ll; sa_res_key = (u64)tmp_ll;
...@@ -1370,14 +1364,14 @@ static ssize_t target_core_dev_pr_store_attr_res_aptpl_metadata( ...@@ -1370,14 +1364,14 @@ static ssize_t target_core_dev_pr_store_attr_res_aptpl_metadata(
* PR APTPL Metadata for Target Port * PR APTPL Metadata for Target Port
*/ */
case Opt_target_fabric: case Opt_target_fabric:
t_fabric = match_strdup(&args[0]); t_fabric = match_strdup(args);
if (!t_fabric) { if (!t_fabric) {
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto out;
} }
break; break;
case Opt_target_node: case Opt_target_node:
t_port = match_strdup(&args[0]); t_port = match_strdup(args);
if (!t_port) { if (!t_port) {
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto out;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment