OSDN Git Service

Installd: Fix math overflow on quota calculation
authorJerry Wong <jerry.wong@broadcom.com>
Fri, 28 Jul 2017 22:54:58 +0000 (15:54 -0700)
committerJeff Sharkey <jsharkey@android.com>
Mon, 31 Jul 2017 20:45:54 +0000 (14:45 -0600)
On 32-bit devices, the hard quota size calculation could overflow that
would cause the hard quota limit size to be much lower than intended.

b/64160395

Change-Id: If7b0f2a40f77bb5e5957c663999544f4ab2e69be

cmds/installd/InstalldNativeService.cpp

index 202fdd1..a711813 100644 (file)
@@ -320,7 +320,8 @@ static int prepare_app_quota(const std::unique_ptr<std::string>& uuid, const std
         }
 
         dq.dqb_valid = QIF_LIMITS;
-        dq.dqb_bhardlimit = (((stat.f_blocks * stat.f_frsize) / 10) * 9) / QIF_DQBLKSIZE;
+        dq.dqb_bhardlimit =
+            (((static_cast<uint64_t>(stat.f_blocks) * stat.f_frsize) / 10) * 9) / QIF_DQBLKSIZE;
         dq.dqb_ihardlimit = (stat.f_files / 2);
         if (quotactl(QCMD(Q_SETQUOTA, USRQUOTA), device.c_str(), uid,
                 reinterpret_cast<char*>(&dq)) != 0) {