Skip to content

Commit 5b7ff39

Browse files
authored
Merge pull request #302 from maxmind/greg/fix-ssize-check
Compare st_size with SSIZE_MAX rather than itself
2 parents 5cffab0 + c2d1e77 commit 5b7ff39

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
- name: Initialize CodeQL
3030
uses: github/codeql-action/init@v1
3131

32-
- run: sudo apt install libipc-run3-perl libfile-slurp-perl libfile-which-perl pandoc
32+
- run: sudo apt install libipc-run3-perl libipc-system-simple-perl libfile-slurp-perl libfile-which-perl pandoc
3333
- run: |
3434
./bootstrap
3535
./configure

Changes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
* The CMake build now uses the correct library directory on Linux systems
1010
using alternate directory structures. Pull request by Satadru Pramanik.
1111
GitHub #284.
12+
* File size check now correctly compares the size to `SSIZE_MAX`. Reported
13+
by marakew. GitHub #301.
1214

1315
## 1.6.0 - 2021-04-29
1416

src/maxminddb.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <errno.h>
99
#include <fcntl.h>
1010
#include <inttypes.h>
11+
#include <limits.h>
1112
#include <stdint.h>
1213
#include <stdlib.h>
1314
#include <string.h>
@@ -406,7 +407,6 @@ cleanup:;
406407
#else // _WIN32
407408

408409
static int map_file(MMDB_s *const mmdb) {
409-
ssize_t size;
410410
int status = MMDB_SUCCESS;
411411

412412
int o_flags = O_RDONLY;
@@ -432,8 +432,8 @@ static int map_file(MMDB_s *const mmdb) {
432432
goto cleanup;
433433
}
434434

435-
size = s.st_size;
436-
if (size < 0 || size != s.st_size) {
435+
off_t size = s.st_size;
436+
if (size < 0 || size > SSIZE_MAX) {
437437
status = MMDB_OUT_OF_MEMORY_ERROR;
438438
goto cleanup;
439439
}
@@ -449,7 +449,7 @@ static int map_file(MMDB_s *const mmdb) {
449449
goto cleanup;
450450
}
451451

452-
mmdb->file_size = size;
452+
mmdb->file_size = (ssize_t)size;
453453
mmdb->file_content = file_content;
454454

455455
cleanup:;

0 commit comments

Comments
 (0)