Patchwork acpi: acpidump: ensure we are shifting a 64 bit unsigned long

login
register
mail settings
Submitter Colin King
Date May 20, 2013, noon
Message ID <1369051233-27613-1-git-send-email-colin.king@canonical.com>
Download mbox | patch
Permalink /patch/245009/
State Accepted
Headers show

Comments

Colin King - May 20, 2013, noon
From: Colin Ian King <colin.king@canonical.com>

Coverity CID#997275, Unintentional integer overflow (OVERFLOW_BEFORE_WIDEN)

To avoid 32 bit overflow, ensure 1 is a 64 bit unsigned long before
shifting it.

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 21, 2013, 5:52 a.m.
On 05/20/2013 08:00 PM, 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, ensure 1 is a 64 bit unsigned long before
> shifting it.
>
> 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 e509949..d95c166 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<<(uint64_t)info->bit_field_nbits) - 1;
> +	uint64_t	mask = (1ULL<<(uint64_t)info->bit_field_nbits) - 1;
>   	int i;
>
>   	switch (info->size) {
>
Acked-by: Alex Hung <alex.hung@canonical.com>
Ivan Hu - May 22, 2013, 2:29 a.m.
On 05/20/2013 08:00 PM, 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, ensure 1 is a 64 bit unsigned long before
> shifting it.
>
> 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 e509949..d95c166 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<<(uint64_t)info->bit_field_nbits) - 1;
> +	uint64_t	mask = (1ULL<<(uint64_t)info->bit_field_nbits) - 1;
>   	int i;
>
>   	switch (info->size) {
>

Acked-by: Ivan Hu <ivan.hu@canonical.com>

Patch

diff --git a/src/acpi/acpidump/acpidump.c b/src/acpi/acpidump/acpidump.c
index e509949..d95c166 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<<(uint64_t)info->bit_field_nbits) - 1;
+	uint64_t	mask = (1ULL<<(uint64_t)info->bit_field_nbits) - 1;
 	int i;
 
 	switch (info->size) {