All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] kconfig: switch to "long long" for sanity
@ 2013-07-18 18:32 Kees Cook
  2013-07-18 20:00 ` Geert Uytterhoeven
  0 siblings, 1 reply; 4+ messages in thread
From: Kees Cook @ 2013-07-18 18:32 UTC (permalink / raw)
  To: linux-kernel
  Cc: Geert Uytterhoeven, Yann E. MORIN, Michal Marek,
	Arve Hjønnevåg, linux-kbuild

Instead of using "long" for kconfig "hex" and "range" values, which may
change in size depending on the host architecture, use "long long". This
will allow values greater than INT_MAX on 32-bit hosts when cross
compiling.

Signed-off-by: Kees Cook <keescook@chromium.org>
---
v2:
 - use "int" for base, since that's what strtoll expects, thanks to Geert
---
 scripts/kconfig/symbol.c |   19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index d550300..5d850e7 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -136,7 +136,7 @@ static struct property *sym_get_range_prop(struct symbol *sym)
 	return NULL;
 }
 
-static long sym_get_range_val(struct symbol *sym, int base)
+static long long sym_get_range_val(struct symbol *sym, int base)
 {
 	sym_calc_value(sym);
 	switch (sym->type) {
@@ -149,13 +149,14 @@ static long sym_get_range_val(struct symbol *sym, int base)
 	default:
 		break;
 	}
-	return strtol(sym->curr.val, NULL, base);
+	return strtoll(sym->curr.val, NULL, base);
 }
 
 static void sym_validate_range(struct symbol *sym)
 {
 	struct property *prop;
-	long base, val, val2;
+	int base;
+	long long val, val2;
 	char str[64];
 
 	switch (sym->type) {
@@ -171,7 +172,7 @@ static void sym_validate_range(struct symbol *sym)
 	prop = sym_get_range_prop(sym);
 	if (!prop)
 		return;
-	val = strtol(sym->curr.val, NULL, base);
+	val = strtoll(sym->curr.val, NULL, base);
 	val2 = sym_get_range_val(prop->expr->left.sym, base);
 	if (val >= val2) {
 		val2 = sym_get_range_val(prop->expr->right.sym, base);
@@ -179,9 +180,9 @@ static void sym_validate_range(struct symbol *sym)
 			return;
 	}
 	if (sym->type == S_INT)
-		sprintf(str, "%ld", val2);
+		sprintf(str, "%lld", val2);
 	else
-		sprintf(str, "0x%lx", val2);
+		sprintf(str, "0x%llx", val2);
 	sym->curr.val = strdup(str);
 }
 
@@ -594,7 +595,7 @@ bool sym_string_valid(struct symbol *sym, const char *str)
 bool sym_string_within_range(struct symbol *sym, const char *str)
 {
 	struct property *prop;
-	long val;
+	long long val;
 
 	switch (sym->type) {
 	case S_STRING:
@@ -605,7 +606,7 @@ bool sym_string_within_range(struct symbol *sym, const char *str)
 		prop = sym_get_range_prop(sym);
 		if (!prop)
 			return true;
-		val = strtol(str, NULL, 10);
+		val = strtoll(str, NULL, 10);
 		return val >= sym_get_range_val(prop->expr->left.sym, 10) &&
 		       val <= sym_get_range_val(prop->expr->right.sym, 10);
 	case S_HEX:
@@ -614,7 +615,7 @@ bool sym_string_within_range(struct symbol *sym, const char *str)
 		prop = sym_get_range_prop(sym);
 		if (!prop)
 			return true;
-		val = strtol(str, NULL, 16);
+		val = strtoll(str, NULL, 16);
 		return val >= sym_get_range_val(prop->expr->left.sym, 16) &&
 		       val <= sym_get_range_val(prop->expr->right.sym, 16);
 	case S_BOOLEAN:
-- 
1.7.9.5


-- 
Kees Cook
Chrome OS Security

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] kconfig: switch to "long long" for sanity
  2013-07-18 18:32 [PATCH v2] kconfig: switch to "long long" for sanity Kees Cook
@ 2013-07-18 20:00 ` Geert Uytterhoeven
  2013-07-18 20:47   ` Yann E. MORIN
  0 siblings, 1 reply; 4+ messages in thread
From: Geert Uytterhoeven @ 2013-07-18 20:00 UTC (permalink / raw)
  To: Kees Cook
  Cc: linux-kernel, Yann E. MORIN, Michal Marek,
	Arve Hjønnevåg, linux-kbuild

On Thu, Jul 18, 2013 at 8:32 PM, Kees Cook <keescook@chromium.org> wrote:
> Instead of using "long" for kconfig "hex" and "range" values, which may
> change in size depending on the host architecture, use "long long". This
> will allow values greater than INT_MAX on 32-bit hosts when cross
> compiling.
>
> Signed-off-by: Kees Cook <keescook@chromium.org>

Acked-by: Geert Uytterhoeven <geert@linux-m68k.org>

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] kconfig: switch to "long long" for sanity
  2013-07-18 20:00 ` Geert Uytterhoeven
@ 2013-07-18 20:47   ` Yann E. MORIN
  2013-07-18 22:01     ` Kees Cook
  0 siblings, 1 reply; 4+ messages in thread
From: Yann E. MORIN @ 2013-07-18 20:47 UTC (permalink / raw)
  To: Geert Uytterhoeven, Kees Cook
  Cc: linux-kernel, Michal Marek, Arve Hjønnevåg, linux-kbuild

Kees, Geert, All,

On 2013-07-18 22:00 +0200, Geert Uytterhoeven spake thusly:
> On Thu, Jul 18, 2013 at 8:32 PM, Kees Cook <keescook@chromium.org> wrote:
> > Instead of using "long" for kconfig "hex" and "range" values, which may
> > change in size depending on the host architecture, use "long long". This
> > will allow values greater than INT_MAX on 32-bit hosts when cross
> > compiling.
> >
> > Signed-off-by: Kees Cook <keescook@chromium.org>
> 
> Acked-by: Geert Uytterhoeven <geert@linux-m68k.org>

Ok, thanks, I'll take in my tree.

Is it material for -rc-fixes, or can it wait in -for-next?

My gut feelings is that it does not fix an existing breakage, but only a
potential problem in the future, so it would be a candidate for
-for-next. Agreed?

Regards,
Yann E. MORIN.

-- 
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] kconfig: switch to "long long" for sanity
  2013-07-18 20:47   ` Yann E. MORIN
@ 2013-07-18 22:01     ` Kees Cook
  0 siblings, 0 replies; 4+ messages in thread
From: Kees Cook @ 2013-07-18 22:01 UTC (permalink / raw)
  To: Yann E. MORIN
  Cc: Geert Uytterhoeven, linux-kernel, Michal Marek,
	Arve Hjønnevåg, linux-kbuild

On Thu, Jul 18, 2013 at 1:47 PM, Yann E. MORIN <yann.morin.1998@free.fr> wrote:
> Kees, Geert, All,
>
> On 2013-07-18 22:00 +0200, Geert Uytterhoeven spake thusly:
>> On Thu, Jul 18, 2013 at 8:32 PM, Kees Cook <keescook@chromium.org> wrote:
>> > Instead of using "long" for kconfig "hex" and "range" values, which may
>> > change in size depending on the host architecture, use "long long". This
>> > will allow values greater than INT_MAX on 32-bit hosts when cross
>> > compiling.
>> >
>> > Signed-off-by: Kees Cook <keescook@chromium.org>
>>
>> Acked-by: Geert Uytterhoeven <geert@linux-m68k.org>
>
> Ok, thanks, I'll take in my tree.
>
> Is it material for -rc-fixes, or can it wait in -for-next?
>
> My gut feelings is that it does not fix an existing breakage, but only a
> potential problem in the future, so it would be a candidate for
> -for-next. Agreed?

Correct. I'm not aware of anything in the tree that currently uses
>INT_MAX values in kconfig.

-Kees

-- 
Kees Cook
Chrome OS Security

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-07-18 22:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-18 18:32 [PATCH v2] kconfig: switch to "long long" for sanity Kees Cook
2013-07-18 20:00 ` Geert Uytterhoeven
2013-07-18 20:47   ` Yann E. MORIN
2013-07-18 22:01     ` Kees Cook

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.