r1608: Fix from Nick THOMPSON <nickthompson@agere.com> to protect smbd
authorJeremy Allison <jra@samba.org>
Fri, 30 Jul 2004 00:19:41 +0000 (00:19 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 15:52:16 +0000 (10:52 -0500)
against broken filesystems which return zero blocksize.
Jeremy.
(This used to be commit 23d157a0bea16366f0361ab68193b479ed844291)

source3/lib/fsusage.c

index bb7cff06453930a508071aec2c1bf7aeda33bfc3..036f276319ff300b4c9a609aef0ec5d4b1896db6 100644 (file)
 */
 static SMB_BIG_UINT adjust_blocks(SMB_BIG_UINT blocks, SMB_BIG_UINT fromsize, SMB_BIG_UINT tosize)
 {
-       if (fromsize == tosize) /* e.g., from 512 to 512 */
+       if (fromsize == tosize) /* e.g., from 512 to 512 */
                return blocks;
-       else if (fromsize > tosize)     /* e.g., from 2048 to 512 */
+       } else if (fromsize > tosize) { /* e.g., from 2048 to 512 */
                return blocks * (fromsize / tosize);
-       else                            /* e.g., from 256 to 512 */
+       } else { /* e.g., from 256 to 512 */
+               /* Protect against broken filesystems... */
+               if (fromsize == 0) {
+                       fromsize = tosize;
+               }
                return (blocks + 1) / (tosize / fromsize);
+       }
 }
 
 /* this does all of the system specific guff to get the free disk space.