summaryrefslogtreecommitdiff
path: root/src/basic/io-util.h
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-01-26 19:02:12 +0100
committerSven Eden <yamakuzure@gmx.net>2017-05-17 15:22:15 +0200
commit69db37b5fbcf6d4d26839860d5e067a45f3f7023 (patch)
tree220dc2633f4555d3d0be785fcca398d3820ac2ad /src/basic/io-util.h
parent7634579fb338f996cecb6f49b1183e0a4e491617 (diff)
machined: add early checks for unrealistically large image/pool sizes
Diffstat (limited to 'src/basic/io-util.h')
-rw-r--r--src/basic/io-util.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/basic/io-util.h b/src/basic/io-util.h
index 5f77a556c..7d0d2bd81 100644
--- a/src/basic/io-util.h
+++ b/src/basic/io-util.h
@@ -77,3 +77,21 @@ static inline size_t IOVEC_INCREMENT(struct iovec *i, unsigned n, size_t k) {
return k;
}
+
+static inline bool FILE_SIZE_VALID(uint64_t l) {
+ /* ftruncate() and friends take an unsigned file size, but actually cannot deal with file sizes larger than
+ * 2^63 since the kernel internally handles it as signed value. This call allows checking for this early. */
+
+ return (l >> 63) == 0;
+}
+
+static inline bool FILE_SIZE_VALID_OR_INFINITY(uint64_t l) {
+
+ /* Same as above, but allows one extra value: -1 as indication for infinity. */
+
+ if (l == (uint64_t) -1)
+ return true;
+
+ return FILE_SIZE_VALID(l);
+
+}