diff options
author | Tobias Stoeckmann <tobias@stoeckmann.org> | 2016-12-11 13:50:05 +0100 |
---|---|---|
committer | Matthieu Herrb <matthieu@herrb.eu> | 2016-12-12 22:49:54 +0100 |
commit | 8b3024e6871ce50b34bf2dff924774bd654703bc (patch) | |
tree | 42b8546fdb926d2d35ea6fa77e2984214f7f2443 | |
parent | d1167418f0fd02a27f617ec5afd6db053afbe185 (diff) |
Handle size_t in file/buffer length
The values of file sizes and buffer sizes can exceed current limits.
Therefore, use proper variable types for these operations.
Signed-off-by: Matthieu Herrb <matthieu@herrb.eu>
Reviewed-by: Matthieu Herrb <matthieu@herrb.eu>
-rw-r--r-- | src/RdFToBuf.c | 4 | ||||
-rw-r--r-- | src/WrFFrBuf.c | 2 |
2 files changed, 5 insertions, 1 deletions
diff --git a/src/RdFToBuf.c b/src/RdFToBuf.c index 7f8ebee..69e3347 100644 --- a/src/RdFToBuf.c +++ b/src/RdFToBuf.c @@ -89,6 +89,10 @@ XpmReadFileToBuffer( return XpmOpenFailed; } len = stats.st_size; + if (len < 0 || len >= SIZE_MAX) { + close(fd); + return XpmOpenFailed; + } ptr = (char *) XpmMalloc(len + 1); if (!ptr) { fclose(fp); diff --git a/src/WrFFrBuf.c b/src/WrFFrBuf.c index b80aa62..0e57cc8 100644 --- a/src/WrFFrBuf.c +++ b/src/WrFFrBuf.c @@ -44,7 +44,7 @@ XpmWriteFileFromBuffer( const char *filename, char *buffer) { - int fcheck, len; + size_t fcheck, len; FILE *fp = fopen(filename, "w"); if (!fp) |