Patchwork acpi: acpidump: fix overflow before widening bug

login
register
mail settings
Submitter Colin King
Date May 7, 2013, 12:56 a.m.
Message ID <1367888195-25667-1-git-send-email-colin.king@canonical.com>
Download mbox | patch
Permalink /patch/241864/
State Accepted
Headers show

Comments

Colin King - May 7, 2013, 12:56 a.m.
From: Colin Ian King <colin.king@canonical.com>

Coverity CID#997275, Unintentional integer overflow (OVERFLOW_BEFORE_WIDEN)

To avoid 32 bit overflow, cast info->bit_field_nbits to uint64_t before the
shift.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/acpi/acpidump/acpidump.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Alex Hung - May 10, 2013, 1:19 a.m.
On 05/07/2013 08:56 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Coverity CID#997275, Unintentional integer overflow (OVERFLOW_BEFORE_WIDEN)
>
> To avoid 32 bit overflow, cast info->bit_field_nbits to uint64_t before the
> shift.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/acpi/acpidump/acpidump.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/acpi/acpidump/acpidump.c b/src/acpi/acpidump/acpidump.c
> index 3bfbc2a..e509949 100644
> --- a/src/acpi/acpidump/acpidump.c
> +++ b/src/acpi/acpidump/acpidump.c
> @@ -101,7 +101,7 @@ static void acpi_dump_str(fwts_framework *fw, fwts_acpidump_field *info, void *d
>   static uint64_t apci_dump_get_uint64_t(fwts_acpidump_field *info, void *data)
>   {
>   	uint64_t	ret;
> -	uint64_t	mask = (1<<info->bit_field_nbits) - 1;
> +	uint64_t	mask = (1<<(uint64_t)info->bit_field_nbits) - 1;
>   	int i;
>
>   	switch (info->size) {
>
Acked-by: Alex Hung <alex.hung@canonical.com>
Keng-Yu Lin - May 20, 2013, 7:21 a.m.
On Tue, May 7, 2013 at 8:56 AM, Colin King <colin.king@canonical.com> wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Coverity CID#997275, Unintentional integer overflow (OVERFLOW_BEFORE_WIDEN)
>
> To avoid 32 bit overflow, cast info->bit_field_nbits to uint64_t before the
> shift.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/acpi/acpidump/acpidump.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/acpi/acpidump/acpidump.c b/src/acpi/acpidump/acpidump.c
> index 3bfbc2a..e509949 100644
> --- a/src/acpi/acpidump/acpidump.c
> +++ b/src/acpi/acpidump/acpidump.c
> @@ -101,7 +101,7 @@ static void acpi_dump_str(fwts_framework *fw, fwts_acpidump_field *info, void *d
>  static uint64_t apci_dump_get_uint64_t(fwts_acpidump_field *info, void *data)
>  {
>         uint64_t        ret;
> -       uint64_t        mask = (1<<info->bit_field_nbits) - 1;
> +       uint64_t        mask = (1<<(uint64_t)info->bit_field_nbits) - 1;
>         int i;
>
>         switch (info->size) {
> --
> 1.8.1.2
>
Acked-by: Keng-Yu Lin <kengyu@canonical.com>

Patch

diff --git a/src/acpi/acpidump/acpidump.c b/src/acpi/acpidump/acpidump.c
index 3bfbc2a..e509949 100644
--- a/src/acpi/acpidump/acpidump.c
+++ b/src/acpi/acpidump/acpidump.c
@@ -101,7 +101,7 @@  static void acpi_dump_str(fwts_framework *fw, fwts_acpidump_field *info, void *d
 static uint64_t apci_dump_get_uint64_t(fwts_acpidump_field *info, void *data)
 {
 	uint64_t	ret;
-	uint64_t	mask = (1<<info->bit_field_nbits) - 1;
+	uint64_t	mask = (1<<(uint64_t)info->bit_field_nbits) - 1;
 	int i;
 
 	switch (info->size) {