summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr/discovery.c8
-rw-r--r--usr/strings.c6
-rw-r--r--usr/strings.h2
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);