Re: [PATCH v5 1/2] block: fix signed int overflow in Amiga partition support

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

 



Hi Geert,

Am 12.10.2018 um 21:59 schrieb Geert Uytterhoeven:

Changes from v4:

Andreas Schwab:
- correct cast to sector_t in sector address calculations

Which you only did for the first case...

--- a/block/partitions/amiga.c
+++ b/block/partitions/amiga.c

@@ -100,14 +101,14 @@ int amiga_partition(struct parsed_partitions *state)

                /* Tell Kernel about it */

-               nr_sects = (be32_to_cpu(pb->pb_Environment[10]) + 1 -
-                           be32_to_cpu(pb->pb_Environment[9])) *
+               nr_sects = ((sector_t) be32_to_cpu(pb->pb_Environment[10])

...here ...

+                          + 1 - be32_to_cpu(pb->pb_Environment[9])) *
                           be32_to_cpu(pb->pb_Environment[3]) *
                           be32_to_cpu(pb->pb_Environment[5]) *
                           blksize;
                if (!nr_sects)
                        continue;
-               start_sect = be32_to_cpu(pb->pb_Environment[9]) *
+               start_sect = (sector_t) be32_to_cpu(pb->pb_Environment[9]) *

... but not here?

I meant to cast the first operand to sector_t here?

Using

int main(int argc, char *argv) {
  unsigned int a, b;
  unsigned long long c, d;

  a = 0xffffffff;
  b = 0xffffffff;

  c = a * b;
  d = (unsigned long long) a * b;

  fprintf(stdout, "%llx %llx\n", c, d);
}

I get this:

1 fffffffe00000001

But I can add brackets if you think the compiler might get this wrong.

Cheers,

	Michael


                             be32_to_cpu(pb->pb_Environment[3]) *
                             be32_to_cpu(pb->pb_Environment[5]) *
                             blksize;

Gr{oetje,eeting}s,

                        Geert




[Index of Archives]     [Video for Linux]     [Yosemite News]     [Linux S/390]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux