From d03dfb4e9523b4f8537a673727d252695c241745 Mon Sep 17 00:00:00 2001 From: TIAN Yuanhao <78596099+tianyuanhao@users.noreply.github.com> Date: Fri, 23 Sep 2022 00:33:33 +0800 Subject: 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 Signed-off-by: TIAN Yuanhao --- libopeniscsiusr/session.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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); -- cgit v1.2.1