[PATCH v2 2/2] common: buffer access out-of-bounds
Abdelrahman Youssef via B4 Relay
devnull+abdelrahmanyossef12.gmail.com at kernel.org
Fri Oct 18 04:45:56 PDT 2024
From: Abdelrahman Youssef <abdelrahmanyossef12 at gmail.com>
in file_detect_type() to detect file of type socfpga_xload you need at least
68 bytes bytes, so we need to check if we have enough bufsize.
So I moved it after checking if `bufsize >= 256`.
Signed-off-by: Abdelrahman Youssef <abdelrahmanyossef12 at gmail.com>
---
common/filetype.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/common/filetype.c b/common/filetype.c
index 3690d4ae07..3f74871d7f 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -374,9 +374,6 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize)
if (le32_to_cpu(buf[5]) == 0x504d5453)
return filetype_mxs_bootstream;
- if (buf[16] == 0x31305341)
- return filetype_socfpga_xload;
-
if (is_barebox_arm_head(_buf))
return filetype_arm_barebox;
if (buf[9] == 0x016f2818 || buf[9] == 0x18286f01)
@@ -388,7 +385,10 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize)
if (bufsize < 256)
return filetype_unknown;
- if (strncmp(buf8, "STM\x32", 4) == 0) {
+ if (buf[16] == 0x31305341)
+ return filetype_socfpga_xload;
+
+ if (strncmp(buf8, "STM\x32", 4) == 0) {
if (buf8[74] == 0x01) {
switch(le32_to_cpu(buf[63])) {
case 0x00000000:
--
2.43.0
More information about the barebox
mailing list