]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
mdadm: super-intel fix bad shift
authorNigel Croxon <ncroxon@redhat.com>
Wed, 22 May 2024 20:53:22 +0000 (16:53 -0400)
committerMariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Thu, 23 May 2024 10:36:01 +0000 (12:36 +0200)
In the expression "1 << i", left shifting by more than 31 bits has undefined behavior.
The shift amount, "i", is as much as 63. The operand has type "int" (32 bits) and will
be shifted as an "int". The fix is to change to a 64 bit int.

Signed-off-by: Nigel Croxon <ncroxon@redhat.com>
super-intel.c

index d1b737c7fe5b766027a8c44777e00d2e2dce8bc9..0287a6184047d5f139f8fe80dfa56002fca1fce5 100644 (file)
@@ -2343,7 +2343,8 @@ void print_encryption_information(int disk_fd, enum sys_dev_type hba_type)
               get_encryption_status_string(information.status));
 }
 
-static int ahci_enumerate_ports(struct sys_dev *hba, int port_count, int host_base, int verbose)
+static int ahci_enumerate_ports(struct sys_dev *hba, unsigned long port_count, int host_base,
+                               int verbose)
 {
        /* dump an unsorted list of devices attached to AHCI Intel storage
         * controller, as well as non-connected ports
@@ -2357,7 +2358,7 @@ static int ahci_enumerate_ports(struct sys_dev *hba, int port_count, int host_ba
 
        if (port_count > (int)sizeof(port_mask) * 8) {
                if (verbose > 0)
-                       pr_err("port_count %d out of range\n", port_count);
+                       pr_err("port_count %ld out of range\n", port_count);
                return 2;
        }
 
@@ -2499,11 +2500,11 @@ static int ahci_enumerate_ports(struct sys_dev *hba, int port_count, int host_ba
        if (dir)
                closedir(dir);
        if (err == 0) {
-               int i;
+               unsigned long i;
 
                for (i = 0; i < port_count; i++)
-                       if (port_mask & (1 << i))
-                               printf("          Port%d : - no device attached -\n", i);
+                       if (port_mask & (1L << i))
+                               printf("          Port%ld : - no device attached -\n", i);
        }
 
        return err;