!27 backport patches to solve command parameter parse problem and deference null pointer problem
From: @geruijun Reviewed-by: @liuzhiqiang26 Signed-off-by: @liuzhiqiang26
This commit is contained in:
commit
0d55b0b1d6
41
0017-Updata-iscsi-dd.c.patch
Normal file
41
0017-Updata-iscsi-dd.c.patch
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
From 8592dc58838872d0d49c3d773df950f0b3e1eb4b Mon Sep 17 00:00:00 2001
|
||||||
|
From: sallyjunjun <72725839+sallyjunjun@users.noreply.github.com>
|
||||||
|
Date: Tue, 31 May 2022 14:20:43 +0800
|
||||||
|
Subject: [PATCH 1/4] Update iscsi-dd.c
|
||||||
|
|
||||||
|
add check after malloc to avoid referencing an illegal pointer
|
||||||
|
---
|
||||||
|
examples/iscsi-dd.c | 10 ++++++++++
|
||||||
|
1 file changed, 10 insertions(+)
|
||||||
|
|
||||||
|
diff --git a/examples/iscsi-dd.c b/examples/iscsi-dd.c
|
||||||
|
index b2d41ac..1f7ae9f 100644
|
||||||
|
--- a/examples/iscsi-dd.c
|
||||||
|
+++ b/examples/iscsi-dd.c
|
||||||
|
@@ -131,6 +131,11 @@ void read_cb(struct iscsi_context *iscsi, int status, void *command_data, void *
|
||||||
|
}
|
||||||
|
|
||||||
|
wt = malloc(sizeof(struct write_task));
|
||||||
|
+ if (wt == NULL) {
|
||||||
|
+ fprintf(stderr, "failed to alloc write task\n");
|
||||||
|
+ exit(10);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
wt->rt = task;
|
||||||
|
wt->client = client;
|
||||||
|
|
||||||
|
@@ -430,6 +435,11 @@ void cscd_ident_inq(struct iscsi_context *iscsi,
|
||||||
|
_tgt_desig->designator_type = tgt_desig->designator_type;
|
||||||
|
_tgt_desig->designator_length = tgt_desig->designator_length;
|
||||||
|
_tgt_desig->designator = malloc(tgt_desig->designator_length);
|
||||||
|
+ if (_tgt_desig->designator == NULL) {
|
||||||
|
+ fprintf(stderr, "failed to alloc designator\n");
|
||||||
|
+ exit(10);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
memcpy(_tgt_desig->designator, tgt_desig->designator, tgt_desig->designator_length);
|
||||||
|
|
||||||
|
scsi_free_scsi_task(task);
|
||||||
|
--
|
||||||
|
1.8.3.1
|
||||||
|
|
||||||
47
0018-iscsi-swp-handle-setting-of-debug_level-correctly.patch
Normal file
47
0018-iscsi-swp-handle-setting-of-debug_level-correctly.patch
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
From b087a09a0b7754765d3d646c20b5a122eb2b3847 Mon Sep 17 00:00:00 2001
|
||||||
|
From: sallyjunjun <72725839+sallyjunjun@users.noreply.github.com>
|
||||||
|
Date: Tue, 31 May 2022 17:21:09 +0800
|
||||||
|
Subject: [PATCH 2/4] iscsi-swp: handle setting of debug_level correctly
|
||||||
|
|
||||||
|
According to the man page and help info, --debug=integer can specify the
|
||||||
|
debug_level, while it would report following error:
|
||||||
|
|
||||||
|
iscsi-swp --debug=1
|
||||||
|
iscsi-swp: option '--debug' doesn't allow an argument
|
||||||
|
---
|
||||||
|
utils/iscsi-swp.c | 6 +++---
|
||||||
|
1 file changed, 3 insertions(+), 3 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/utils/iscsi-swp.c b/utils/iscsi-swp.c
|
||||||
|
index af07c81..8c2ca31 100644
|
||||||
|
--- a/utils/iscsi-swp.c
|
||||||
|
+++ b/utils/iscsi-swp.c
|
||||||
|
@@ -75,14 +75,14 @@ int main(int argc, char *argv[])
|
||||||
|
static struct option long_options[] = {
|
||||||
|
{"help", no_argument, NULL, 'h'},
|
||||||
|
{"usage", no_argument, NULL, 'u'},
|
||||||
|
- {"debug", no_argument, NULL, 'd'},
|
||||||
|
+ {"debug", required_argument, NULL, 'd'},
|
||||||
|
{"initiator-name", required_argument, NULL, 'i'},
|
||||||
|
{"swp", required_argument, NULL, 's'},
|
||||||
|
{0, 0, 0, 0}
|
||||||
|
};
|
||||||
|
int option_index;
|
||||||
|
|
||||||
|
- while ((c = getopt_long(argc, argv, "h?udi:s:", long_options,
|
||||||
|
+ while ((c = getopt_long(argc, argv, "h?ud:i:s:", long_options,
|
||||||
|
&option_index)) != -1) {
|
||||||
|
switch (c) {
|
||||||
|
case 'h':
|
||||||
|
@@ -93,7 +93,7 @@ int main(int argc, char *argv[])
|
||||||
|
show_usage = 1;
|
||||||
|
break;
|
||||||
|
case 'd':
|
||||||
|
- debug = 1;
|
||||||
|
+ debug = atoi(optarg);
|
||||||
|
break;
|
||||||
|
case 'i':
|
||||||
|
initiator = optarg;
|
||||||
|
--
|
||||||
|
1.8.3.1
|
||||||
|
|
||||||
121
0019-fix-iscsi-ls-parameter-parse.patch
Normal file
121
0019-fix-iscsi-ls-parameter-parse.patch
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
From 045c2387e77f2c20359e956e3327b006e5814cc6 Mon Sep 17 00:00:00 2001
|
||||||
|
From: sallyjunjun <72725839+sallyjunjun@users.noreply.github.com>
|
||||||
|
Date: Wed, 8 Jun 2022 10:02:04 +0800
|
||||||
|
Subject: [PATCH 3/4] fix iscsi-ls parameter parse
|
||||||
|
MIME-Version: 1.0
|
||||||
|
Content-Type: text/plain; charset=UTF-8
|
||||||
|
Content-Transfer-Encoding: 8bit
|
||||||
|
|
||||||
|
If invalid option is input with iscsi-ls, such as "iscsi-ls -a iscsi://", the command just stuck here and do not print useful information for the user to correct.
|
||||||
|
Fix this problem with getopt_long.
|
||||||
|
---
|
||||||
|
utils/iscsi-ls.c | 64 ++++++++++++++++++++++++++++++++++++--------------------
|
||||||
|
1 file changed, 41 insertions(+), 23 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/utils/iscsi-ls.c b/utils/iscsi-ls.c
|
||||||
|
index 2b1d5e2..107121d 100644
|
||||||
|
--- a/utils/iscsi-ls.c
|
||||||
|
+++ b/utils/iscsi-ls.c
|
||||||
|
@@ -37,6 +37,7 @@ WSADATA wsaData;
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
+#include <getopt.h>
|
||||||
|
#include "iscsi.h"
|
||||||
|
#include "scsi-lowlevel.h"
|
||||||
|
|
||||||
|
@@ -329,7 +330,7 @@ void print_help(void)
|
||||||
|
fprintf(stderr, " -i, --initiator-name=iqn-name Initiatorname to use\n");
|
||||||
|
fprintf(stderr, " -d, --debug Print debug information\n");
|
||||||
|
fprintf(stderr, " -s, --show-luns Show the luns for each target\n");
|
||||||
|
- fprintf(stderr, " --url Output targets in URL format\n");
|
||||||
|
+ fprintf(stderr, " -U, --url Output targets in URL format\n");
|
||||||
|
fprintf(stderr, " (does not work with -s)\n");
|
||||||
|
fprintf(stderr, "\n");
|
||||||
|
fprintf(stderr, "Help options:\n");
|
||||||
|
@@ -350,7 +351,8 @@ int main(int argc, char *argv[])
|
||||||
|
struct iscsi_url *iscsi_url = NULL;
|
||||||
|
struct client_state state;
|
||||||
|
const char *url = NULL;
|
||||||
|
- int i;
|
||||||
|
+ int c;
|
||||||
|
+ int option_index;
|
||||||
|
static int show_help = 0, show_usage = 0, debug = 0;
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
@@ -360,31 +362,44 @@ int main(int argc, char *argv[])
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
- for (i = 1; i < argc; i++) {
|
||||||
|
- if (!strcmp(argv[i], "-?") ||
|
||||||
|
- !strcmp(argv[i], "-h") ||
|
||||||
|
- !strcmp(argv[i], "--help")) {
|
||||||
|
- show_help = 1;
|
||||||
|
- } else if (!strcmp(argv[i], "-u") ||
|
||||||
|
- !strcmp(argv[i], "-usage")) {
|
||||||
|
+ static struct option long_options[] = {
|
||||||
|
+ {"help", no_argument, NULL, 'h'},
|
||||||
|
+ {"usage", no_argument, NULL, 'u'},
|
||||||
|
+ {"debug", no_argument, NULL, 'd'},
|
||||||
|
+ {"initiator-name", required_argument, NULL, 'i'},
|
||||||
|
+ {"show-luns", no_argument, NULL, 's'},
|
||||||
|
+ {"url", no_argument, NULL, 'U'},
|
||||||
|
+ {0, 0, 0, 0}
|
||||||
|
+ };
|
||||||
|
+
|
||||||
|
+ while ((c = getopt_long(argc, argv, "h?udi:sU", long_options,
|
||||||
|
+ &option_index)) != -1) {
|
||||||
|
+ switch (c) {
|
||||||
|
+ case 'h':
|
||||||
|
+ case '?':
|
||||||
|
+ show_help = 1;
|
||||||
|
+ break;
|
||||||
|
+ case 'u':
|
||||||
|
show_usage = 1;
|
||||||
|
- } else if (!strcmp(argv[i], "-d") ||
|
||||||
|
- !strcmp(argv[i], "--debug")) {
|
||||||
|
+ break;
|
||||||
|
+ case 'd':
|
||||||
|
debug = 1;
|
||||||
|
- } else if (!strcmp(argv[i], "-i") ||
|
||||||
|
- !strcmp(argv[i], "--initiator-name")) {
|
||||||
|
- initiator = argv[++i];
|
||||||
|
- } else if (!strcmp(argv[i], "-s") ||
|
||||||
|
- !strcmp(argv[i], "--show-luns")) {
|
||||||
|
+ break;
|
||||||
|
+ case 'i':
|
||||||
|
+ initiator = optarg;
|
||||||
|
+ break;
|
||||||
|
+ case 's':
|
||||||
|
showluns = 1;
|
||||||
|
- } else if (!strcmp(argv[i], "-U") ||
|
||||||
|
- !strcmp(argv[i], "--url")) {
|
||||||
|
+ break;
|
||||||
|
+ case 'U':
|
||||||
|
useurls = 1;
|
||||||
|
- } else if (!strncmp("iscsi://", argv[i], 8) ||
|
||||||
|
- !strncmp("iser://", argv[i], 7)) {
|
||||||
|
- url = strdup(argv[i]);
|
||||||
|
- }
|
||||||
|
- }
|
||||||
|
+ break;
|
||||||
|
+ default:
|
||||||
|
+ fprintf(stderr, "Unrecognized option '%c'\n\n", c);
|
||||||
|
+ print_help();
|
||||||
|
+ exit(0);
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
|
||||||
|
if (show_help != 0) {
|
||||||
|
print_help();
|
||||||
|
@@ -398,6 +413,9 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
|
memset(&state, 0, sizeof(state));
|
||||||
|
|
||||||
|
+ if (argv[optind] != NULL) {
|
||||||
|
+ url = strdup(argv[optind]);
|
||||||
|
+ }
|
||||||
|
if (url == NULL) {
|
||||||
|
fprintf(stderr, "You must specify iscsi target portal.\n");
|
||||||
|
print_usage();
|
||||||
98
0020-Check-return-value-of-scsi_malloc-in-order-to.patch
Normal file
98
0020-Check-return-value-of-scsi_malloc-in-order-to.patch
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
From acd147cb884f170ddac027881a9b4bb12a36ee2e Mon Sep 17 00:00:00 2001
|
||||||
|
From: geruijun <geruijun@huawei.com>
|
||||||
|
Date: Wed, 16 Mar 2022 01:36:22 +0800
|
||||||
|
Subject: [PATCH 4/4] Check return value of scsi_malloc in order to avoid
|
||||||
|
dereferencing NULL return value.
|
||||||
|
|
||||||
|
Signed-off-by: geruijun <geruijun@huawei.com>
|
||||||
|
---
|
||||||
|
lib/scsi-lowlevel.c | 30 ++++++++++++++++++++++++++++++
|
||||||
|
1 file changed, 30 insertions(+)
|
||||||
|
|
||||||
|
diff --git a/lib/scsi-lowlevel.c b/lib/scsi-lowlevel.c
|
||||||
|
index 4039cea..0161852 100644
|
||||||
|
--- a/lib/scsi-lowlevel.c
|
||||||
|
+++ b/lib/scsi-lowlevel.c
|
||||||
|
@@ -2912,9 +2912,15 @@ scsi_modesense_marshall_caching(struct scsi_task *task,
|
||||||
|
struct scsi_data *data;
|
||||||
|
|
||||||
|
data = scsi_malloc(task, sizeof(struct scsi_data));
|
||||||
|
+ if (data == NULL) {
|
||||||
|
+ return NULL;
|
||||||
|
+ }
|
||||||
|
|
||||||
|
data->size = 20 + hdr_size;
|
||||||
|
data->data = scsi_malloc(task, data->size);
|
||||||
|
+ if (data->data == NULL) {
|
||||||
|
+ return NULL;
|
||||||
|
+ }
|
||||||
|
|
||||||
|
if (mp->caching.ic) data->data[hdr_size + 2] |= 0x80;
|
||||||
|
if (mp->caching.abpf) data->data[hdr_size + 2] |= 0x40;
|
||||||
|
@@ -2953,9 +2959,15 @@ scsi_modesense_marshall_control(struct scsi_task *task,
|
||||||
|
struct scsi_data *data;
|
||||||
|
|
||||||
|
data = scsi_malloc(task, sizeof(struct scsi_data));
|
||||||
|
+ if (data == NULL) {
|
||||||
|
+ return NULL;
|
||||||
|
+ }
|
||||||
|
|
||||||
|
data->size = 12 + hdr_size;
|
||||||
|
data->data = scsi_malloc(task, data->size);
|
||||||
|
+ if (data->data == NULL) {
|
||||||
|
+ return NULL;
|
||||||
|
+ }
|
||||||
|
|
||||||
|
data->data[hdr_size + 2] |= (mp->control.tst << 5) & 0xe0;
|
||||||
|
if (mp->control.tmf_only) data->data[hdr_size + 2] |= 0x10;
|
||||||
|
@@ -2993,9 +3005,15 @@ scsi_modesense_marshall_power_condition(struct scsi_task *task,
|
||||||
|
struct scsi_data *data;
|
||||||
|
|
||||||
|
data = scsi_malloc(task, sizeof(struct scsi_data));
|
||||||
|
+ if (data == NULL) {
|
||||||
|
+ return NULL;
|
||||||
|
+ }
|
||||||
|
|
||||||
|
data->size = 40 + hdr_size;
|
||||||
|
data->data = scsi_malloc(task, data->size);
|
||||||
|
+ if (data->data == NULL) {
|
||||||
|
+ return NULL;
|
||||||
|
+ }
|
||||||
|
|
||||||
|
data->data[hdr_size + 2] |=
|
||||||
|
(mp->power_condition.pm_bg_precedence << 6) & 0xc0;
|
||||||
|
@@ -3035,9 +3053,15 @@ scsi_modesense_marshall_disconnect_reconnect(struct scsi_task *task,
|
||||||
|
struct scsi_data *data;
|
||||||
|
|
||||||
|
data = scsi_malloc(task, sizeof(struct scsi_data));
|
||||||
|
+ if (data == NULL) {
|
||||||
|
+ return NULL;
|
||||||
|
+ }
|
||||||
|
|
||||||
|
data->size = 16 + hdr_size;
|
||||||
|
data->data = scsi_malloc(task, data->size);
|
||||||
|
+ if (data->data == NULL) {
|
||||||
|
+ return NULL;
|
||||||
|
+ }
|
||||||
|
|
||||||
|
data->data[hdr_size + 2] = mp->disconnect_reconnect.buffer_full_ratio;
|
||||||
|
data->data[hdr_size + 3] = mp->disconnect_reconnect.buffer_empty_ratio;
|
||||||
|
@@ -3064,9 +3088,15 @@ scsi_modesense_marshall_informational_exceptions_control(struct scsi_task *task,
|
||||||
|
struct scsi_data *data;
|
||||||
|
|
||||||
|
data = scsi_malloc(task, sizeof(struct scsi_data));
|
||||||
|
+ if (data == NULL) {
|
||||||
|
+ return NULL;
|
||||||
|
+ }
|
||||||
|
|
||||||
|
data->size = 12 + hdr_size;
|
||||||
|
data->data = scsi_malloc(task, data->size);
|
||||||
|
+ if (data->data == NULL) {
|
||||||
|
+ return NULL;
|
||||||
|
+ }
|
||||||
|
|
||||||
|
if (mp->iec.perf) data->data[hdr_size + 2] |= 0x80;
|
||||||
|
if (mp->iec.ebf) data->data[hdr_size + 2] |= 0x20;
|
||||||
|
--
|
||||||
|
1.8.3.1
|
||||||
|
|
||||||
@ -1,6 +1,6 @@
|
|||||||
Name: libiscsi
|
Name: libiscsi
|
||||||
Version: 1.19.0
|
Version: 1.19.0
|
||||||
Release: 7
|
Release: 8
|
||||||
Summary: Client-side library to implement the iSCSI protocol
|
Summary: Client-side library to implement the iSCSI protocol
|
||||||
Recommends: %{name}-utils
|
Recommends: %{name}-utils
|
||||||
License: LGPLv2+ and GPLv2+
|
License: LGPLv2+ and GPLv2+
|
||||||
@ -22,6 +22,10 @@ Patch13: 0013-test-tool-remove-unused-iscsi_queue_pdu-symbol-overl.patch
|
|||||||
Patch14: 0014-iser-remove-__packed-from-struct-iser_cm_hdr-declaration.patch
|
Patch14: 0014-iser-remove-__packed-from-struct-iser_cm_hdr-declaration.patch
|
||||||
Patch15: 0015-test-tools-use-extern-init-in-headers.patch
|
Patch15: 0015-test-tools-use-extern-init-in-headers.patch
|
||||||
Patch16: 0016-iscsi-inq-handle-setting-of-debug_level-correctly.patch
|
Patch16: 0016-iscsi-inq-handle-setting-of-debug_level-correctly.patch
|
||||||
|
Patch17: 0017-Updata-iscsi-dd.c.patch
|
||||||
|
Patch18: 0018-iscsi-swp-handle-setting-of-debug_level-correctly.patch
|
||||||
|
Patch19: 0019-fix-iscsi-ls-parameter-parse.patch
|
||||||
|
Patch20: 0020-Check-return-value-of-scsi_malloc-in-order-to.patch
|
||||||
|
|
||||||
Source: https://github.com/sahlberg/%{name}/archive/%{version}.tar.gz
|
Source: https://github.com/sahlberg/%{name}/archive/%{version}.tar.gz
|
||||||
|
|
||||||
@ -123,6 +127,10 @@ This package contains utilities of %{name} to connect to iSCSI targets
|
|||||||
%{_bindir}/iscsi-test-cu
|
%{_bindir}/iscsi-test-cu
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Fri Jun 10 2022 Ruijun Ge <geruijun@huawei.com> - 1.19.0-8
|
||||||
|
- DESC: backport patches to solve command parameter parse problem
|
||||||
|
and dereference null pointer problem
|
||||||
|
|
||||||
* Tue Apr 12 2022 haowenchao <haowenchao@huawei.com> - 1.19.0-7
|
* Tue Apr 12 2022 haowenchao <haowenchao@huawei.com> - 1.19.0-7
|
||||||
- DESC: iscsi-inq: handle setting of debug_level correctly
|
- DESC: iscsi-inq: handle setting of debug_level correctly
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user