Commit 68c4101d authored by Dag Erling Smørgrav's avatar Dag Erling Smørgrav

Merged revisions 1794 via svnmerge from

file:///var/lib/svn/varnish/trunk/varnish-cache

........
  r1794 | des | 2007-08-03 20:50:05 +0200 (Fri, 03 Aug 2007) | 3 lines
  
  Try harder to avoid integer overflows in cache file size calculations
  on 32-bit platforms.
........


git-svn-id: http://www.varnish-cache.org/svn/branches/1.1@1826 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 2df9e89e
...@@ -126,6 +126,7 @@ smf_calcsize(struct smf_sc *sc, const char *size, int newfile) ...@@ -126,6 +126,7 @@ smf_calcsize(struct smf_sc *sc, const char *size, int newfile)
AN(sc); AN(sc);
AZ(fstat(sc->fd, &st)); AZ(fstat(sc->fd, &st));
xxxassert(S_ISREG(st.st_mode));
AZ(fstatfs(sc->fd, &fsst)); AZ(fstatfs(sc->fd, &fsst));
...@@ -133,8 +134,9 @@ smf_calcsize(struct smf_sc *sc, const char *size, int newfile) ...@@ -133,8 +134,9 @@ smf_calcsize(struct smf_sc *sc, const char *size, int newfile)
bs = sc->pagesize; bs = sc->pagesize;
if (bs < fsst.f_bsize) if (bs < fsst.f_bsize)
bs = fsst.f_bsize; bs = fsst.f_bsize;
xxxassert(bs % sc->pagesize == 0);
xxxassert(S_ISREG(st.st_mode)); xxxassert(bs % fsst.f_bsize == 0);
fssize = fsst.f_bsize * fsst.f_bavail;
i = sscanf(size, "%ju%1s", &l, suff); /* can return -1, 0, 1 or 2 */ i = sscanf(size, "%ju%1s", &l, suff); /* can return -1, 0, 1 or 2 */
...@@ -175,7 +177,7 @@ smf_calcsize(struct smf_sc *sc, const char *size, int newfile) ...@@ -175,7 +177,7 @@ smf_calcsize(struct smf_sc *sc, const char *size, int newfile)
l *= (uintmax_t)(1024UL * 1024UL) * l *= (uintmax_t)(1024UL * 1024UL) *
(uintmax_t)(1024UL * 1024UL); (uintmax_t)(1024UL * 1024UL);
else if (suff[0] == '%') { else if (suff[0] == '%') {
l *= fsst.f_bsize * fsst.f_bavail; l *= fssize;
l /= 100; l /= 100;
} }
} }
...@@ -196,14 +198,14 @@ smf_calcsize(struct smf_sc *sc, const char *size, int newfile) ...@@ -196,14 +198,14 @@ smf_calcsize(struct smf_sc *sc, const char *size, int newfile)
if (l < st.st_size) { if (l < st.st_size) {
AZ(ftruncate(sc->fd, l)); AZ(ftruncate(sc->fd, l));
} else if (l - st.st_size > fsst.f_bsize * fsst.f_bavail) { } else if (l - st.st_size > fssize) {
l = ((uintmax_t)fsst.f_bsize * fsst.f_bavail * 80) / 100; l = fssize * 80 / 100;
fprintf(stderr, "WARNING: storage file size reduced" fprintf(stderr, "WARNING: storage file size reduced"
" to %ju (80%% of available disk space)\n", l); " to %ju (80%% of available disk space)\n", l);
} }
} }
/* round down to of filesystem blocksize or pagesize */ /* round down to multiple of filesystem blocksize or pagesize */
l -= (l % bs); l -= (l % bs);
if (l < MINPAGES * (uintmax_t)sc->pagesize) { if (l < MINPAGES * (uintmax_t)sc->pagesize) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment