Skip to content

Commit 0307d6e

Browse files
committed
scrips/kconfig: reduce impact of getenv() buffer overflow
getenv() returns an string of unknown size, so Coverity warns that it might be used to overflow the stack in the call chain off conf_read_simple(). To avoid that, wisdom says copy to an string of known size and pass that. Change-Id: I9e468de0ae66429062027f58fe0a0a4e1197218f Coverity-ID: 150819 Signed-off-by: Inaky Perez-Gonzalez <[email protected]>
1 parent f38cbb5 commit 0307d6e

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

scripts/kconfig/conf.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,10 +600,22 @@ int main(int ac, char **av)
600600
if (!name)
601601
break;
602602
if ((strcmp(name, "") != 0) && (strcmp(name, "1") != 0)) {
603-
if (conf_read_simple(name, S_DEF_USER)) {
603+
/*
604+
* "640kb ought to be enough for anybody" sic
605+
*
606+
* Limit the _name variable, as environment
607+
* wise it is not limited and this way we
608+
* ensure there can be no attacks through it.
609+
*
610+
* Coverity made me do it.
611+
*/
612+
char _name[256];
613+
614+
strncpy(_name, name, sizeof(_name));
615+
if (conf_read_simple(_name, S_DEF_USER)) {
604616
fprintf(stderr,
605617
_("*** Can't read seed configuration \"%s\"!\n"),
606-
name);
618+
_name);
607619
exit(1);
608620
}
609621
break;

0 commit comments

Comments
 (0)