summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2012-06-05 11:10:42 -0400
committerNick Mathewson <nickm@torproject.org>2012-06-05 11:10:42 -0400
commitd09a3ecd01330e2ec5da942a0469a37416da75ed (patch)
treeff7d33d41388e35867e534741ceb18af505ae55a
parentb482c870ca3d70bc5611b8eb447ebbe3418bf3a9 (diff)
parente7d34935fb3050065cf0d8350b5d75f72c1fe6c4 (diff)
downloadtor-d09a3ecd01330e2ec5da942a0469a37416da75ed.tar.gz
tor-d09a3ecd01330e2ec5da942a0469a37416da75ed.zip
Merge remote-tracking branch 'public/getfilesize_64'
Conflicts: src/common/compat.c The getfilesize change conflicted with the removal of file_handle from the windows tor_mmap_t.
-rw-r--r--changes/getfilesize_643
-rw-r--r--src/common/compat.c24
2 files changed, 19 insertions, 8 deletions
diff --git a/changes/getfilesize_64 b/changes/getfilesize_64
new file mode 100644
index 0000000000..abcdab6eee
--- /dev/null
+++ b/changes/getfilesize_64
@@ -0,0 +1,3 @@
+ o Minor bugfixes:
+ - On Windows, correctly detect errors and large file sizes from
+ GetFileSize. Fixes bug 5957; bugfix on Tor 0.1.2.1-alpha.
diff --git a/src/common/compat.c b/src/common/compat.c
index 87fe84cb4b..334ea1b8b4 100644
--- a/src/common/compat.c
+++ b/src/common/compat.c
@@ -229,6 +229,8 @@ tor_mmap_file(const char *filename)
tor_mmap_t *res = tor_malloc_zero(sizeof(tor_mmap_t));
int empty = 0;
HANDLE file_handle = INVALID_HANDLE_VALUE;
+ DWORD size_low, size_high;
+ uint64_t real_size;
res->mmap_handle = NULL;
#ifdef UNICODE
mbstowcs(tfilename,filename,MAX_PATH);
@@ -245,23 +247,29 @@ tor_mmap_file(const char *filename)
if (file_handle == INVALID_HANDLE_VALUE)
goto win_err;
- res->size = GetFileSize(file_handle, NULL);
+ size_low = GetFileSize(file_handle, &size_high);
- if (res->size == 0) {
+ if (size_low == INVALID_FILE_SIZE && GetLastError() != NO_ERROR) {
+ log_warn(LD_FS,"Error getting size of \"%s\".",filename);
+ goto win_err;
+ }
+ if (size_low == 0 && size_high == 0) {
log_info(LD_FS,"File \"%s\" is empty. Ignoring.",filename);
empty = 1;
goto err;
}
+ real_size = (((uint64_t)size_high)<<32) | size_low;
+ if (real_size > SIZE_MAX) {
+ log_warn(LD_FS,"File \"%s\" is too big to map; not trying.",filename);
+ goto err;
+ }
+ res->size = real_size;
res->mmap_handle = CreateFileMapping(file_handle,
NULL,
PAGE_READONLY,
-#if SIZEOF_SIZE_T > 4
- (res->base.size >> 32),
-#else
- 0,
-#endif
- (res->size & 0xfffffffful),
+ size_high,
+ size_low,
NULL);
if (res->mmap_handle == NULL)
goto win_err;