.../RedfishLib/edk2libredfish/src/redpath.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
From 0541928e66eb01802a855bbbae125ef0b02259d6 Mon Sep 17 00:00:00 2001
From: houjingyi233 <houjingyi647@gmail.com>
Date: Wed, 25 Jan 2023 22:11:31 +0800
Subject: [PATCH] RedfishPkg/RedfishLib: Avoid possible overflow in memcpy
It is possible that when the third argument of the memcpy is unequal
to the first argument of malloc will cause overflow, when +1 in malloc
cause int overflow malloc a very small size of memory and followed memcpy
will cause heap overflow.
Signed-off-by: houjingyi233 <houjingyi647@gmail.com>
---
.../RedfishLib/edk2libredfish/src/redpath.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git
a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/redpath.c
b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/redpath.c
index cf5ab85165..a1523938f7 100644
--- a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/redpath.c
+++ b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/redpath.c
@@ -175,6 +175,10 @@ parseNode (
return;
}
+ if ((opChars - index)+1 < opChars - index) {
+ return;
+ }
+
node->next->propName = (char *)malloc ((opChars - index)+1);
memcpy (node->next->propName, index, (opChars - index));
node->next->propName[(opChars - index)] = 0;
@@ -189,6 +193,9 @@ parseNode (
break;
}
+ if (tmpIndex+1 < tmpIndex) {
+ return;
+ }
node->next->op = (char *)malloc (tmpIndex+1);
memcpy (node->next->op, opChars, tmpIndex);
node->next->op[tmpIndex] = 0;
@@ -217,6 +224,10 @@ getStringTill (
return strdup (string);
}
+ if ((end-string)+1 < end-string) {
+ return;
+ }
+
ret = (char *)malloc ((end-string)+1);
memcpy (ret, string, (end-string));
ret[(end-string)] = 0;
--
2.37.3
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#99032): https://edk2.groups.io/g/devel/message/99032
Mute This Topic: https://groups.io/mt/96524716/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
[AMD Official Use Only - General] Hi houjingyi, May I know why there are two messages with the same subject? Are these two identical? Thanks Abner From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of houjingyi via groups.io Sent: Wednesday, January 25, 2023 10:23 PM To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH] RedfishPkg/RedfishLib: Avoid possible overflow in memcpy Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding. From 0541928e66eb01802a855bbbae125ef0b02259d6 Mon Sep 17 00:00:00 2001 From: houjingyi233 <houjingyi647@gmail.com<mailto:houjingyi647@gmail.com>> Date: Wed, 25 Jan 2023 22:11:31 +0800 Subject: [PATCH] RedfishPkg/RedfishLib: Avoid possible overflow in memcpy It is possible that when the third argument of the memcpy is unequal to the first argument of malloc will cause overflow, when +1 in malloc cause int overflow malloc a very small size of memory and followed memcpy will cause heap overflow. Signed-off-by: houjingyi233 <houjingyi647@gmail.com<mailto:houjingyi647@gmail.com>> --- .../RedfishLib/edk2libredfish/src/redpath.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/redpath.c b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/redpath.c index cf5ab85165..a1523938f7 100644 --- a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/redpath.c +++ b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/redpath.c @@ -175,6 +175,10 @@ parseNode ( return; } + if ((opChars - index)+1 < opChars - index) { + return; + } + node->next->propName = (char *)malloc ((opChars - index)+1); memcpy (node->next->propName, index, (opChars - index)); node->next->propName[(opChars - index)] = 0; @@ -189,6 +193,9 @@ parseNode ( break; } + if (tmpIndex+1 < tmpIndex) { + return; + } node->next->op = (char *)malloc (tmpIndex+1); memcpy (node->next->op, opChars, tmpIndex); node->next->op[tmpIndex] = 0; @@ -217,6 +224,10 @@ getStringTill ( return strdup (string); } + if ((end-string)+1 < end-string) { + return; + } + ret = (char *)malloc ((end-string)+1); memcpy (ret, string, (end-string)); ret[(end-string)] = 0; -- 2.37.3 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#99120): https://edk2.groups.io/g/devel/message/99120 Mute This Topic: https://groups.io/mt/96524716/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=-=-=-=-=-=-=-=-=-=-=-
From 0541928e66eb01802a855bbbae125ef0b02259d6 Mon Sep 17 00:00:00 2001
From: houjingyi233 <houjingyi647@gmail.com>
Date: Wed, 25 Jan 2023 22:11:31 +0800
Subject: [PATCH] RedfishPkg/RedfishLib: Avoid possible overflow in memcpy
It is possible that when the third argument of the memcpy is unequal
to the first argument of malloc will cause overflow, when +1 in malloc
cause int overflow malloc a very small size of memory and followed memcpy
will cause heap overflow.
Signed-off-by: houjingyi233 <houjingyi647@gmail.com>
---
.../RedfishLib/edk2libredfish/src/redpath.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git
a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/redpath.c
b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/redpath.c
index cf5ab85165..a1523938f7 100644
--- a/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/redpath.c
+++ b/RedfishPkg/PrivateLibrary/RedfishLib/edk2libredfish/src/redpath.c
@@ -175,6 +175,10 @@ parseNode (
return;
}
+ if ((opChars - index)+1 < opChars - index) {
+ return;
+ }
+
node->next->propName = (char *)malloc ((opChars - index)+1);
memcpy (node->next->propName, index, (opChars - index));
node->next->propName[(opChars - index)] = 0;
@@ -189,6 +193,9 @@ parseNode (
break;
}
+ if (tmpIndex+1 < tmpIndex) {
+ return;
+ }
node->next->op = (char *)malloc (tmpIndex+1);
memcpy (node->next->op, opChars, tmpIndex);
node->next->op[tmpIndex] = 0;
@@ -217,6 +224,10 @@ getStringTill (
return strdup (string);
}
+ if ((end-string)+1 < end-string) {
+ return;
+ }
+
ret = (char *)malloc ((end-string)+1);
memcpy (ret, string, (end-string));
ret[(end-string)] = 0;
--
2.37.3
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#99033): https://edk2.groups.io/g/devel/message/99033
Mute This Topic: https://groups.io/mt/96524716/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
© 2016 - 2024 Red Hat, Inc.