Skip to content

Commit b9d1a8e

Browse files
Jacob Garbermasahir0y
authored andcommitted
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 <[email protected]> Signed-off-by: Masahiro Yamada <[email protected]>
1 parent 4cb7261 commit b9d1a8e

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

scripts/kconfig/confdata.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ char *conf_get_default_confname(void)
241241
name = expand_string(conf_defname);
242242
env = getenv(SRCTREE);
243243
if (env) {
244-
sprintf(fullname, "%s/%s", env, name);
244+
snprintf(fullname, sizeof(fullname), "%s/%s", env, name);
245245
if (is_present(fullname))
246246
return fullname;
247247
}

scripts/kconfig/lexer.l

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,8 @@ FILE *zconf_fopen(const char *name)
378378
if (!f && name != NULL && name[0] != '/') {
379379
env = getenv(SRCTREE);
380380
if (env) {
381-
sprintf(fullname, "%s/%s", env, name);
381+
snprintf(fullname, sizeof(fullname),
382+
"%s/%s", env, name);
382383
f = fopen(fullname, "r");
383384
}
384385
}

0 commit comments

Comments
 (0)