[Gptfdisk-general] [PATCH 4/4] seek: detect and complain about seek overflows
Brought to you by:
srs5694
|
From: Cody P S. <de...@co...> - 2015-06-17 21:34:39
|
---
diskio-unix.cc | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/diskio-unix.cc b/diskio-unix.cc
index 71b4387..4a835a5 100644
--- a/diskio-unix.cc
+++ b/diskio-unix.cc
@@ -280,7 +280,12 @@ int DiskIO::Seek(uint64_t sector) {
} // if
if (isOpen) {
- seekTo = sector * (uint64_t) GetBlockSize();
+ uint64_t b = (uint64_t) GetBlockSize();
+ if (UINT64_MAX / b <= sector) {
+ cerr << "Overflow in seek calculation: " << b << " * " << sector << endl;
+ return 0;
+ }
+ seekTo = sector * b;
sought = lseek64(fd, seekTo, SEEK_SET);
if (sought != seekTo) {
retval = 0;
--
2.4.3
|