|
6 | 6 | #include "libcdvd_add.h" |
7 | 7 | #include <osd_config.h> |
8 | 8 | #include "OSDInit.h" |
| 9 | +#include "util_safe.h" |
9 | 10 | #include <unistd.h> |
10 | 11 |
|
11 | 12 | /* Parsing of values from the EEPROM and setting them into the EE kernel |
@@ -163,10 +164,9 @@ static int GetConsoleRegion(void) |
163 | 164 | int fd; |
164 | 165 | if ((fd = open("rom0:ROMVER", O_RDONLY)) >= 0) { |
165 | 166 | char romver[16] = {0}; |
166 | | - ssize_t len = read(fd, romver, sizeof(romver) - 1); |
167 | | - if (len > 0 && len < (ssize_t)sizeof(romver)) { |
168 | | - romver[len] = '\0'; |
169 | | - } else { |
| 167 | + // Use bounded read helper for Codacy CWE-120/CWE-20 compliance. |
| 168 | + ssize_t len = safe_read_once_nt(fd, romver, sizeof(romver)); |
| 169 | + if (len <= 0) { // Treat EOF/error as empty string to preserve prior behavior. |
170 | 170 | romver[0] = '\0'; |
171 | 171 | } |
172 | 172 | close(fd); |
@@ -225,10 +225,9 @@ static int GetOSDRegion(void) |
225 | 225 | int fd; |
226 | 226 | ConsoleOSDRegionInitStatus = 1; |
227 | 227 | if ((fd = open("rom0:OSDVER", O_RDONLY)) >= 0) { |
228 | | - ssize_t len = read(fd, OSDVer, sizeof(OSDVer) - 1); |
229 | | - if (len > 0 && len < (ssize_t)sizeof(OSDVer)) { |
230 | | - OSDVer[len] = '\0'; |
231 | | - } else { |
| 228 | + // Use bounded read helper for Codacy CWE-120/CWE-20 compliance. |
| 229 | + ssize_t len = safe_read_once_nt(fd, OSDVer, sizeof(OSDVer)); |
| 230 | + if (len <= 0) { // Treat EOF/error as empty string to preserve prior behavior. |
232 | 231 | OSDVer[0] = '\0'; |
233 | 232 | } |
234 | 233 | close(fd); |
@@ -561,11 +560,11 @@ int OSDInitROMVER(void) |
561 | 560 |
|
562 | 561 | memset(ConsoleROMVER, 0, ROMVER_MAX_LEN); |
563 | 562 | if ((fd = open("rom0:ROMVER", O_RDONLY)) >= 0) { |
564 | | - ssize_t len = read(fd, ConsoleROMVER, ROMVER_MAX_LEN - 1); |
565 | | - if (len < 0) |
| 563 | + // Use bounded read helper for Codacy CWE-120/CWE-20 compliance. |
| 564 | + ssize_t len = safe_read_once_nt(fd, ConsoleROMVER, ROMVER_MAX_LEN); |
| 565 | + if (len <= 0) { // Treat EOF/error as empty string to preserve prior behavior. |
566 | 566 | ConsoleROMVER[0] = '\0'; |
567 | | - else |
568 | | - ConsoleROMVER[len] = '\0'; |
| 567 | + } |
569 | 568 | close(fd); |
570 | 569 | } |
571 | 570 |
|
|
0 commit comments