diff mbox

[07/10] acpi: cstates: fix potential integer overflow

Message ID 1398952881-27828-8-git-send-email-colin.king@canonical.com
State Accepted
Headers show

Commit Message

Colin Ian King May 1, 2014, 2:01 p.m. UTC
From: Colin Ian King <colin.king@canonical.com>

Coverity Scan detected a potential integer overflow, this can be
easily resolved by using the correct integer type for strtol

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/acpi/cstates/cstates.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Ivan Hu May 6, 2014, 3:14 a.m. UTC | #1
On 05/01/2014 10:01 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Coverity Scan detected a potential integer overflow, this can be
> easily resolved by using the correct integer type for strtol
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/acpi/cstates/cstates.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/src/acpi/cstates/cstates.c b/src/acpi/cstates/cstates.c
> index 9272512..e634f2d 100644
> --- a/src/acpi/cstates/cstates.c
> +++ b/src/acpi/cstates/cstates.c
> @@ -67,7 +67,7 @@ static void get_cstates(char *path, fwts_cstates *state)
>
>   	while ((entry = readdir(dir)) != NULL) {
>   		if (entry && strlen(entry->d_name)>3) {
> -			int nr;
> +			long int nr;
>   			int count;
>
>   			snprintf(filename, sizeof(filename), "%s/%s/name",
> @@ -81,13 +81,13 @@ static void get_cstates(char *path, fwts_cstates *state)
>   			 * where x is the C state number.
>   			 */
>   			if ((data[0] == 'C') && isdigit(data[1]))
> -				nr = strtoull(data+1, NULL, 10);
> +				nr = strtol(data + 1, NULL, 10);
>   			else if (strcmp("POLL", data) == 0)
>   				nr = 0;
>   			else {
>   				char *ptr = strstr(data, "-C");
>   				if (ptr)
> -					nr = strtoull(ptr + 2, NULL, 10);
> +					nr = strtol(ptr + 2, NULL, 10);
>   				else
>   					nr = 0;
>   			}
>

Acked-by: Ivan Hu <ivan.hu@canonical.com>
Alex Hung May 6, 2014, 8:28 a.m. UTC | #2
On 05/01/2014 10:01 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Coverity Scan detected a potential integer overflow, this can be
> easily resolved by using the correct integer type for strtol
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/acpi/cstates/cstates.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/src/acpi/cstates/cstates.c b/src/acpi/cstates/cstates.c
> index 9272512..e634f2d 100644
> --- a/src/acpi/cstates/cstates.c
> +++ b/src/acpi/cstates/cstates.c
> @@ -67,7 +67,7 @@ static void get_cstates(char *path, fwts_cstates *state)
>
>   	while ((entry = readdir(dir)) != NULL) {
>   		if (entry && strlen(entry->d_name)>3) {
> -			int nr;
> +			long int nr;
>   			int count;
>
>   			snprintf(filename, sizeof(filename), "%s/%s/name",
> @@ -81,13 +81,13 @@ static void get_cstates(char *path, fwts_cstates *state)
>   			 * where x is the C state number.
>   			 */
>   			if ((data[0] == 'C') && isdigit(data[1]))
> -				nr = strtoull(data+1, NULL, 10);
> +				nr = strtol(data + 1, NULL, 10);
>   			else if (strcmp("POLL", data) == 0)
>   				nr = 0;
>   			else {
>   				char *ptr = strstr(data, "-C");
>   				if (ptr)
> -					nr = strtoull(ptr + 2, NULL, 10);
> +					nr = strtol(ptr + 2, NULL, 10);
>   				else
>   					nr = 0;
>   			}
>

Acked-by: Alex Hung <alex.hung@canonical.com>
diff mbox

Patch

diff --git a/src/acpi/cstates/cstates.c b/src/acpi/cstates/cstates.c
index 9272512..e634f2d 100644
--- a/src/acpi/cstates/cstates.c
+++ b/src/acpi/cstates/cstates.c
@@ -67,7 +67,7 @@  static void get_cstates(char *path, fwts_cstates *state)
 
 	while ((entry = readdir(dir)) != NULL) {
 		if (entry && strlen(entry->d_name)>3) {
-			int nr;
+			long int nr;
 			int count;
 
 			snprintf(filename, sizeof(filename), "%s/%s/name",
@@ -81,13 +81,13 @@  static void get_cstates(char *path, fwts_cstates *state)
 			 * where x is the C state number.
 			 */
 			if ((data[0] == 'C') && isdigit(data[1]))
-				nr = strtoull(data+1, NULL, 10);
+				nr = strtol(data + 1, NULL, 10);
 			else if (strcmp("POLL", data) == 0)
 				nr = 0;
 			else {
 				char *ptr = strstr(data, "-C");
 				if (ptr) 
-					nr = strtoull(ptr + 2, NULL, 10);
+					nr = strtol(ptr + 2, NULL, 10);
 				else
 					nr = 0;
 			}