1
0
mirror of https://xff.cz/git/u-boot/ synced 2025-09-01 00:32:04 +02:00

Use snprintf in confdata.c to avoid possible buffer overflow

And gcc8 warnings.

Signed-off-by: Ondrej Jirman <megous@megous.com>
This commit is contained in:
Ondrej Jirman
2018-07-09 07:16:20 +02:00
parent b46dd116ce
commit a9a2450f4d

View File

@@ -782,6 +782,7 @@ int conf_write(const char *name)
const char *str; const char *str;
char dirname[PATH_MAX+1], tmpname[PATH_MAX+22], newname[PATH_MAX+8]; char dirname[PATH_MAX+1], tmpname[PATH_MAX+22], newname[PATH_MAX+8];
char *env; char *env;
int ret;
dirname[0] = 0; dirname[0] = 0;
if (name && name[0]) { if (name && name[0]) {
@@ -804,10 +805,14 @@ int conf_write(const char *name)
} else } else
basename = conf_get_configname(); basename = conf_get_configname();
sprintf(newname, "%s%s", dirname, basename); ret = snprintf(newname, sizeof newname, "%s%s", dirname, basename);
if (ret == sizeof newname)
return 1;
env = getenv("KCONFIG_OVERWRITECONFIG"); env = getenv("KCONFIG_OVERWRITECONFIG");
if (!env || !*env) { if (!env || !*env) {
sprintf(tmpname, "%s.tmpconfig.%d", dirname, (int)getpid()); ret = snprintf(tmpname, sizeof tmpname, "%s.tmpconfig.%d", dirname, (int)getpid());
if (ret == sizeof tmpname)
return 1;
out = fopen(tmpname, "w"); out = fopen(tmpname, "w");
} else { } else {
*tmpname = 0; *tmpname = 0;