summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTIAN Yuanhao <78596099+tianyuanhao@users.noreply.github.com>2022-09-23 00:33:33 +0800
committerGitHub <noreply@github.com>2022-09-22 09:33:33 -0700
commitd03dfb4e9523b4f8537a673727d252695c241745 (patch)
tree51bdefd90bc00482f4b677dd6b69aac00475d610
parent531039d15c3fe34fcd373d0923e0c7a34786c58c (diff)
downloadopen-iscsi-d03dfb4e9523b4f8537a673727d252695c241745.tar.gz
libopeniscsiusr: use realloc instead of reallocarray (#368)
realloc is similar to reallocarray, except it doesn't check for integer overflow when computing num * size. On 32-bit systems, integer overflow may not happen because the old array is likely to be smaller than 4G and the new array is smaller than the old array. On 64-bit systems, integer overflow can never happen because num is less than 4G and size is always 8. This fixes build errors when using uClibc. Signed-off-by: TIAN Yuanhao <tianyuanhao3@163.com> Signed-off-by: TIAN Yuanhao <tianyuanhao3@163.com>
-rw-r--r--libopeniscsiusr/session.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/libopeniscsiusr/session.c b/libopeniscsiusr/session.c
index 6b06241..489cea7 100644
--- a/libopeniscsiusr/session.c
+++ b/libopeniscsiusr/session.c
@@ -291,7 +291,11 @@ int iscsi_sessions_get(struct iscsi_context *ctx,
}
/* reset session count and sessions array length to what we were able to read from sysfs */
*session_count = j;
- *sessions = reallocarray(*sessions, *session_count, sizeof(struct iscsi_session *));
+ /* XXX: asserts that there is no integer overflow */
+ assert(!(sizeof(struct iscsi_session *) &&
+ *session_count > UINT_MAX / sizeof(struct iscsi_session *)));
+ *sessions =
+ realloc(*sessions, *session_count * sizeof(struct iscsi_session *));
out:
free(sids);