diff options
author | Mike Christie <michaelc@cs.wisc.edu> | 2010-01-29 19:33:50 -0600 |
---|---|---|
committer | Mike Christie <michaelc@cs.wisc.edu> | 2010-03-22 17:36:52 -0500 |
commit | 4fe8b06ed9be29efa6427a0a862968c0539b33c7 (patch) | |
tree | 1ea3bcd3860aa4f1a5a6088044e5002b3bc7f996 | |
parent | cbb01e46eaa40a46e9f62871f17877e52b7fdc08 (diff) | |
download | open-iscsi-4fe8b06ed9be29efa6427a0a862968c0539b33c7.tar.gz |
iscsi tools: do not exit on mem alloc failures during discovery
If st discovery fails, do not exit(). Just return a failure
and pass the error upwards.
Signed-off-by: Mike Christie <michaelc@cs.wisc.edu>
-rw-r--r-- | usr/discovery.c | 8 | ||||
-rw-r--r-- | usr/strings.c | 6 | ||||
-rw-r--r-- | usr/strings.h | 2 |
3 files changed, 12 insertions, 4 deletions
diff --git a/usr/discovery.c b/usr/discovery.c index a121ddc..e78177c 100644 --- a/usr/discovery.c +++ b/usr/discovery.c @@ -944,7 +944,13 @@ process_recvd_pdu(struct iscsi_hdr *pdu, * buffer is now valid */ curr_data_length = str_data_length(sendtargets); - str_enlarge_data(sendtargets, dlength); + if (str_enlarge_data(sendtargets, dlength)) { + log_error("Could not allocate memory to " + "process SendTargets response."); + rc = 0; + goto done; + } + memcpy(str_buffer_data(sendtargets) + curr_data_length, data, dlength); diff --git a/usr/strings.c b/usr/strings.c index fc38ed4..ee6a51c 100644 --- a/usr/strings.c +++ b/usr/strings.c @@ -67,7 +67,7 @@ void str_free_buffer(struct str_buffer *s) } } -void str_enlarge_data(struct str_buffer *s, int length) +int str_enlarge_data(struct str_buffer *s, int length) { void *new_buf; @@ -83,7 +83,7 @@ void str_enlarge_data(struct str_buffer *s, int length) "bytes, with only %d bytes of buffer " "space", s, (int)s->data_length, (int)s->allocated_length); - exit(1); + return ENOMEM; } s->buffer = new_buf; memset(s->buffer + s->allocated_length, 0, @@ -91,6 +91,8 @@ void str_enlarge_data(struct str_buffer *s, int length) s->allocated_length = s->data_length; } } + + return 0; } void str_remove_initial(struct str_buffer *s, int length) diff --git a/usr/strings.h b/usr/strings.h index 503ef14..22d21e4 100644 --- a/usr/strings.h +++ b/usr/strings.h @@ -31,7 +31,7 @@ extern int str_init_buffer(struct str_buffer *s, size_t initial_allocation); extern struct str_buffer *str_alloc_buffer(size_t initial_allocation); extern void str_free_buffer(struct str_buffer *s); -extern void str_enlarge_data(struct str_buffer *s, int length); +extern int str_enlarge_data(struct str_buffer *s, int length); extern void str_remove_initial(struct str_buffer *s, int length); extern void str_truncate_buffer(struct str_buffer *s, size_t length); extern char *str_buffer_data(struct str_buffer *s); |