Skip to content

Commit

Permalink
#1241 issue fixing
Browse files Browse the repository at this point in the history
Due type cast firmware file size compared not with signed int max value. Instead unsigned int max value used and after type casting converted to -1. Then function returns error message.
Type fixed, function working.
  • Loading branch information
hydroconstructor committed Jan 9, 2022
1 parent 4132973 commit 5e9650e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
#define O_BINARY 0
#endif

#ifndef OFF_T_MAX
#define OFF_T_MAX 1073741824 // signed long int max value
#endif

#ifdef _MSC_VER
#define __attribute__(x)
#endif
Expand Down Expand Up @@ -2200,7 +2204,7 @@ static int map_file(mapped_file_t *mf, const char *path) {

if (sizeof(st.st_size) != sizeof(size_t)) {
// on 32 bit systems, check if there is an overflow
if (st.st_size > (off_t)SSIZE_MAX) {
if (st.st_size > (off_t)OFF_T_MAX) {
fprintf(stderr, "mmap() size_t overflow for file %s\n", path);
goto on_error;
}
Expand Down

0 comments on commit 5e9650e

Please sign in to comment.