* [PATCH] RedfishPkg/RedfishLib: Avoid possible overflow in memcpy
@ 2023-01-25 14:23 houjingyi
2023-01-25 14:30 ` houjingyi647
2023-01-27 4:05 ` [edk2-devel] " Chang, Abner
0 siblings, 2 replies; 4+ messages in thread
From: houjingyi @ 2023-01-25 14:23 UTC (permalink / raw)
To: devel
[-- Attachment #1: Type: text/plain, Size: 1730 bytes --]
>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
[-- Attachment #2: Type: text/html, Size: 2118 bytes --]
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH] RedfishPkg/RedfishLib: Avoid possible overflow in memcpy
2023-01-25 14:23 [PATCH] RedfishPkg/RedfishLib: Avoid possible overflow in memcpy houjingyi
@ 2023-01-25 14:30 ` houjingyi647
2023-01-27 4:05 ` [edk2-devel] " Chang, Abner
1 sibling, 0 replies; 4+ messages in thread
From: houjingyi647 @ 2023-01-25 14:30 UTC (permalink / raw)
To: devel
[-- Attachment #1: Type: text/plain, Size: 1730 bytes --]
>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
[-- Attachment #2: Type: text/html, Size: 2204 bytes --]
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [edk2-devel] [PATCH] RedfishPkg/RedfishLib: Avoid possible overflow in memcpy
2023-01-25 14:23 [PATCH] RedfishPkg/RedfishLib: Avoid possible overflow in memcpy houjingyi
2023-01-25 14:30 ` houjingyi647
@ 2023-01-27 4:05 ` Chang, Abner
2023-01-27 7:27 ` houjingyi
1 sibling, 1 reply; 4+ messages in thread
From: Chang, Abner @ 2023-01-27 4:05 UTC (permalink / raw)
To: devel@edk2.groups.io, houjingyi647@gmail.com
[-- Attachment #1: Type: text/plain, Size: 2385 bytes --]
[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
[-- Attachment #2: Type: text/html, Size: 6533 bytes --]
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-01-27 7:27 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-25 14:23 [PATCH] RedfishPkg/RedfishLib: Avoid possible overflow in memcpy houjingyi
2023-01-25 14:30 ` houjingyi647
2023-01-27 4:05 ` [edk2-devel] " Chang, Abner
2023-01-27 7:27 ` houjingyi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox