From: houjingyi647@gmail.com
To: devel@edk2.groups.io
Subject: [PATCH] RedfishPkg/RedfishLib: Avoid possible overflow in memcpy
Date: Wed, 25 Jan 2023 22:30:58 +0800 [thread overview]
Message-ID: <CAN1eSkt+JDkvo4bXtK=7eod_oqCzkQehg+DmR_3b1t8gJdsR=Q@mail.gmail.com> (raw)
In-Reply-To: <CAN1eSkuRgusN=ozdcKrxQG5UNUeWcZ1=z_wZJ93=3u+vdjrvkg@mail.gmail.com>
[-- 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 --]
next prev parent reply other threads:[~2023-01-25 14:31 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-25 14:23 [PATCH] RedfishPkg/RedfishLib: Avoid possible overflow in memcpy houjingyi
2023-01-25 14:30 ` houjingyi647 [this message]
2023-01-27 4:05 ` [edk2-devel] " Chang, Abner
2023-01-27 7:27 ` houjingyi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAN1eSkt+JDkvo4bXtK=7eod_oqCzkQehg+DmR_3b1t8gJdsR=Q@mail.gmail.com' \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox