mirror of
https://github.com/edk2-porting/linux-next.git
synced 2025-01-21 12:04:03 +08:00
kconfig: do not accept a directory for configuration output
Currently, conf_write() can be called with a directory name instead of a file name. As far as I see, this can happen for menuconfig, nconfig, gconfig. If it is given with a directory path, conf_write() kindly appends getenv("KCONFIG_CONFIG"), but this ends up with hacky dir/basename handling, and screwed up in corner-cases like "what if KCONFIG_CONFIG is an absolute path?" as discussed before: https://patchwork.kernel.org/patch/9910037/ Since conf_write() is already messed up, I'd say "do not do it". Please pass a file path all the time. If a directory path is specified for the configuration output, conf_write() will simply error out. Now that the tmp file is created in the same directory as the .config, the previously reported "what if KCONFIG_CONFIG points to a different file system?" has been solved. Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com> Cc: Nicolas Porcel <nicolasporcel06@gmail.com>
This commit is contained in:
parent
65be755a54
commit
ceb7f3296e
@ -817,40 +817,31 @@ int conf_write(const char *name)
|
|||||||
FILE *out;
|
FILE *out;
|
||||||
struct symbol *sym;
|
struct symbol *sym;
|
||||||
struct menu *menu;
|
struct menu *menu;
|
||||||
const char *basename;
|
|
||||||
const char *str;
|
const char *str;
|
||||||
char dirname[PATH_MAX+1], tmpname[PATH_MAX+22], newname[PATH_MAX+8];
|
char tmpname[PATH_MAX + 1], oldname[PATH_MAX + 1];
|
||||||
char *env;
|
char *env;
|
||||||
|
|
||||||
dirname[0] = 0;
|
if (!name)
|
||||||
if (name && name[0]) {
|
name = conf_get_configname();
|
||||||
char *slash;
|
|
||||||
|
|
||||||
if (is_dir(name)) {
|
if (!*name) {
|
||||||
strcpy(dirname, name);
|
fprintf(stderr, "config name is empty\n");
|
||||||
strcat(dirname, "/");
|
return -1;
|
||||||
basename = conf_get_configname();
|
}
|
||||||
} else if ((slash = strrchr(name, '/'))) {
|
|
||||||
int size = slash - name + 1;
|
if (is_dir(name)) {
|
||||||
memcpy(dirname, name, size);
|
fprintf(stderr, "%s: Is a directory\n", name);
|
||||||
dirname[size] = 0;
|
return -1;
|
||||||
if (slash[1])
|
}
|
||||||
basename = slash + 1;
|
|
||||||
else
|
|
||||||
basename = conf_get_configname();
|
|
||||||
} else
|
|
||||||
basename = name;
|
|
||||||
} else
|
|
||||||
basename = conf_get_configname();
|
|
||||||
|
|
||||||
sprintf(newname, "%s%s", dirname, basename);
|
|
||||||
env = getenv("KCONFIG_OVERWRITECONFIG");
|
env = getenv("KCONFIG_OVERWRITECONFIG");
|
||||||
if (!env || !*env) {
|
if (env && *env) {
|
||||||
sprintf(tmpname, "%s.tmpconfig.%d", dirname, (int)getpid());
|
|
||||||
out = fopen(tmpname, "w");
|
|
||||||
} else {
|
|
||||||
*tmpname = 0;
|
*tmpname = 0;
|
||||||
out = fopen(newname, "w");
|
out = fopen(name, "w");
|
||||||
|
} else {
|
||||||
|
snprintf(tmpname, sizeof(tmpname), "%s.%d.tmp",
|
||||||
|
name, (int)getpid());
|
||||||
|
out = fopen(tmpname, "w");
|
||||||
}
|
}
|
||||||
if (!out)
|
if (!out)
|
||||||
return 1;
|
return 1;
|
||||||
@ -897,14 +888,13 @@ next:
|
|||||||
fclose(out);
|
fclose(out);
|
||||||
|
|
||||||
if (*tmpname) {
|
if (*tmpname) {
|
||||||
strcat(dirname, basename);
|
snprintf(oldname, sizeof(oldname), "%s.old", name);
|
||||||
strcat(dirname, ".old");
|
rename(name, oldname);
|
||||||
rename(newname, dirname);
|
if (rename(tmpname, name))
|
||||||
if (rename(tmpname, newname))
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
conf_message("configuration written to %s", newname);
|
conf_message("configuration written to %s", name);
|
||||||
|
|
||||||
sym_set_change_count(0);
|
sym_set_change_count(0);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user