Skip to content

Commit

Permalink
kconfig: switch to "long long" for sanity
Browse files Browse the repository at this point in the history
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>
Tested-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
  • Loading branch information
kees authored and yann-morin-1998 committed Aug 15, 2013
1 parent c3286ee commit 129784a
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions scripts/kconfig/symbol.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -171,17 +172,17 @@ 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);
if (val <= val2)
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);
}

Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit 129784a

Please sign in to comment.