From 85a2f90d5829b68514058dbd520395a506b8c87c Mon Sep 17 00:00:00 2001 From: Vinicius Costa Gomes Date: Fri, 28 May 2010 15:37:59 -0300 Subject: [PATCH] obexd: Fix dealing with large files In C, the result of an operation has always the size of the largest operand, in this case both operands are unsigned longs, which was causing the operation to overflow on 32bit machines. The solution is to force an operand to be of a size that would not overflow and to store the result somewhere with a safe size. --- obexd/plugins/filesystem.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/obexd/plugins/filesystem.c b/obexd/plugins/filesystem.c index 633036b13..284432981 100644 --- a/obexd/plugins/filesystem.c +++ b/obexd/plugins/filesystem.c @@ -138,6 +138,7 @@ static void *filesystem_open(const char *name, int oflag, mode_t mode, char *folder; gboolean root; int fd = open(name, oflag, mode); + uint64_t avail; if (fd < 0) { if (err) @@ -181,7 +182,8 @@ static void *filesystem_open(const char *name, int oflag, mode_t mode, if (size == NULL) goto done; - if (buf.f_bsize * buf.f_bavail < *size) { + avail = (uint64_t) buf.f_bsize * buf.f_bavail; + if (avail < *size) { if (err) *err = -ENOSPC; goto failed; -- 2.47.3