Skip to content

Commit 129784a

Browse files
keesyann-morin-1998
authored andcommitted
kconfig: switch to "long long" for sanity
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>
1 parent c3286ee commit 129784a

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

‎scripts/kconfig/symbol.c‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ static struct property *sym_get_range_prop(struct symbol *sym)
136136
return NULL;
137137
}
138138

139-
static long sym_get_range_val(struct symbol *sym, int base)
139+
static long long sym_get_range_val(struct symbol *sym, int base)
140140
{
141141
sym_calc_value(sym);
142142
switch (sym->type) {
@@ -149,13 +149,14 @@ static long sym_get_range_val(struct symbol *sym, int base)
149149
default:
150150
break;
151151
}
152-
return strtol(sym->curr.val, NULL, base);
152+
return strtoll(sym->curr.val, NULL, base);
153153
}
154154

155155
static void sym_validate_range(struct symbol *sym)
156156
{
157157
struct property *prop;
158-
long base, val, val2;
158+
int base;
159+
long long val, val2;
159160
char str[64];
160161

161162
switch (sym->type) {
@@ -171,17 +172,17 @@ static void sym_validate_range(struct symbol *sym)
171172
prop = sym_get_range_prop(sym);
172173
if (!prop)
173174
return;
174-
val = strtol(sym->curr.val, NULL, base);
175+
val = strtoll(sym->curr.val, NULL, base);
175176
val2 = sym_get_range_val(prop->expr->left.sym, base);
176177
if (val >= val2) {
177178
val2 = sym_get_range_val(prop->expr->right.sym, base);
178179
if (val <= val2)
179180
return;
180181
}
181182
if (sym->type == S_INT)
182-
sprintf(str, "%ld", val2);
183+
sprintf(str, "%lld", val2);
183184
else
184-
sprintf(str, "0x%lx", val2);
185+
sprintf(str, "0x%llx", val2);
185186
sym->curr.val = strdup(str);
186187
}
187188

@@ -594,7 +595,7 @@ bool sym_string_valid(struct symbol *sym, const char *str)
594595
bool sym_string_within_range(struct symbol *sym, const char *str)
595596
{
596597
struct property *prop;
597-
long val;
598+
long long val;
598599

599600
switch (sym->type) {
600601
case S_STRING:
@@ -605,7 +606,7 @@ bool sym_string_within_range(struct symbol *sym, const char *str)
605606
prop = sym_get_range_prop(sym);
606607
if (!prop)
607608
return true;
608-
val = strtol(str, NULL, 10);
609+
val = strtoll(str, NULL, 10);
609610
return val >= sym_get_range_val(prop->expr->left.sym, 10) &&
610611
val <= sym_get_range_val(prop->expr->right.sym, 10);
611612
case S_HEX:
@@ -614,7 +615,7 @@ bool sym_string_within_range(struct symbol *sym, const char *str)
614615
prop = sym_get_range_prop(sym);
615616
if (!prop)
616617
return true;
617-
val = strtol(str, NULL, 16);
618+
val = strtoll(str, NULL, 16);
618619
return val >= sym_get_range_val(prop->expr->left.sym, 16) &&
619620
val <= sym_get_range_val(prop->expr->right.sym, 16);
620621
case S_BOOLEAN:

0 commit comments

Comments
 (0)