DragonFly BSD
DragonFly commits List (threaded) for 2005-02
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: cvs commit: src/sbin/badsect Makefile badsect.c


From: Joerg Sonnenberger <joerg@xxxxxxxxxxxxxxxxx>
Date: Mon, 14 Feb 2005 08:46:31 +0100
Mail-followup-to: commits@crater.dragonflybsd.org

On Sun, Feb 13, 2005 at 11:22:42AM -0800, Chris Pressey wrote:
> cpressey    2005/02/13 11:22:42 PST
> 
> DragonFly src repository
> 
>   Modified files:
>     sbin/badsect         Makefile badsect.c 
>   Log:
>   Raise WARNS to 6:
>   - Double-cast values when testing their ranges for validity.

@@ -142,7 +142,7 @@ main(int argc, char **argv)
                 * bit was lost by bogus sign extensions.
                 */
                diskbn = dbtofsb(fs, number);
-               if ((dev_t)diskbn != diskbn) {
+               if ((daddr_t)((dev_t)diskbn) != diskbn) {
                        printf("sector %ld cannot be represented as a dev_t\n",
                            (long)number);
                        errs++;

This is bad. The old code is evil, but that's even worse. Can you think
of a better way to test it?

@@ -163,7 +163,7 @@ chkuse(daddr_t blkno, int cnt)
        daddr_t fsbn, bn;

        fsbn = dbtofsb(fs, blkno);
-       if ((unsigned)(fsbn+cnt) > fs->fs_size) {
+       if ((int32_t)((unsigned)(fsbn+cnt)) > fs->fs_size) {
                printf("block %ld out of range of file system\n", (long)blkno);

This part is bogus. fsbn + cnt can overflow and the int32_t cast makes
it smaller than any non-negative fs->fs_size.

Joerg



[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]