summaryrefslogtreecommitdiff
path: root/src/posix.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@microsoft.com>2015-02-11 13:01:00 -0500
committerEdward Thomson <ethomson@edwardthomson.com>2015-02-12 22:54:47 -0500
commit8d534b475829edf87c8126fc4ae30f593172f317 (patch)
tree72620bb55ad1a9781b09158c0cc4aa90eb8ccf8f /src/posix.c
parentec3b4d35f636c26d3c9b5703c3b7f87683800af8 (diff)
downloadlibgit2-8d534b475829edf87c8126fc4ae30f593172f317.tar.gz
p_read: ensure requested len is ssize_t
Ensure that the given length to `p_read` is of ssize_t and ensure that callers test the return as if it were an `ssize_t`.
Diffstat (limited to 'src/posix.c')
-rw-r--r--src/posix.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/posix.c b/src/posix.c
index d5e6875b5..8d86aa8bf 100644
--- a/src/posix.c
+++ b/src/posix.c
@@ -155,6 +155,14 @@ ssize_t p_read(git_file fd, void *buf, size_t cnt)
{
char *b = buf;
+ if (!git__is_ssizet(cnt)) {
+#ifdef GIT_WIN32
+ SetLastError(ERROR_INVALID_PARAMETER);
+#endif
+ errno = EINVAL;
+ return -1;
+ }
+
while (cnt) {
ssize_t r;
#ifdef GIT_WIN32
@@ -229,7 +237,9 @@ int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offs
out->data = malloc(len);
GITERR_CHECK_ALLOC(out->data);
- if ((p_lseek(fd, offset, SEEK_SET) < 0) || ((size_t)p_read(fd, out->data, len) != len)) {
+ if (!git__is_ssizet(len) ||
+ (p_lseek(fd, offset, SEEK_SET) < 0) ||
+ (p_read(fd, out->data, len) != (ssize_t)len)) {
giterr_set(GITERR_OS, "mmap emulation failed");
return -1;
}