diff options
author | Jacob Garber <jgarber1@ualberta.ca> | 2019-05-10 15:28:52 -0400 |
---|---|---|
committer | Masahiro Yamada <yamada.masahiro@socionext.com> | 2019-05-14 10:23:25 -0400 |
commit | b9d1a8e9302e68ee03571a286aadeb8041e0b2ca (patch) | |
tree | 372b2d2bee6137d794110d7ff7e106b086dfbe99 /scripts | |
parent | 4cb726121e2cce18d4db5e79347f3ade5fd661a2 (diff) |
kconfig: use snprintf for formatting pathnames
Valid pathnames will never exceed PATH_MAX, but these file names
are unsanitized and can cause buffer overflow if set incorrectly.
Use snprintf to avoid this. This was flagged during a Coverity scan
of the coreboot project, which also uses kconfig for its build system.
Signed-off-by: Jacob Garber <jgarber1@ualberta.ca>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/kconfig/confdata.c | 2 | ||||
-rw-r--r-- | scripts/kconfig/lexer.l | 3 |
2 files changed, 3 insertions, 2 deletions
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index b7bdd9690319..8bb74d468f45 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c | |||
@@ -241,7 +241,7 @@ char *conf_get_default_confname(void) | |||
241 | name = expand_string(conf_defname); | 241 | name = expand_string(conf_defname); |
242 | env = getenv(SRCTREE); | 242 | env = getenv(SRCTREE); |
243 | if (env) { | 243 | if (env) { |
244 | sprintf(fullname, "%s/%s", env, name); | 244 | snprintf(fullname, sizeof(fullname), "%s/%s", env, name); |
245 | if (is_present(fullname)) | 245 | if (is_present(fullname)) |
246 | return fullname; | 246 | return fullname; |
247 | } | 247 | } |
diff --git a/scripts/kconfig/lexer.l b/scripts/kconfig/lexer.l index c9df1c8b9824..6354c905b006 100644 --- a/scripts/kconfig/lexer.l +++ b/scripts/kconfig/lexer.l | |||
@@ -378,7 +378,8 @@ FILE *zconf_fopen(const char *name) | |||
378 | if (!f && name != NULL && name[0] != '/') { | 378 | if (!f && name != NULL && name[0] != '/') { |
379 | env = getenv(SRCTREE); | 379 | env = getenv(SRCTREE); |
380 | if (env) { | 380 | if (env) { |
381 | sprintf(fullname, "%s/%s", env, name); | 381 | snprintf(fullname, sizeof(fullname), |
382 | "%s/%s", env, name); | ||
382 | f = fopen(fullname, "r"); | 383 | f = fopen(fullname, "r"); |
383 | } | 384 | } |
384 | } | 385 | } |