diff options
| author | Masahiro Yamada <yamada.masahiro@socionext.com> | 2019-05-10 02:12:04 -0400 |
|---|---|---|
| committer | Masahiro Yamada <yamada.masahiro@socionext.com> | 2019-05-10 13:14:27 -0400 |
| commit | ceb7f3296ea1fa652d68e5ecb0facf5fba19a554 (patch) | |
| tree | 7b7bbbb1e9eb33a74f6221c433f7fc6e5c0309a6 /scripts | |
| parent | 65be755a54117fc02134c288e41e8d3d5e586c4e (diff) | |
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>
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/kconfig/confdata.c | 58 |
1 files changed, 24 insertions, 34 deletions
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index 08ba146a83c5..9fd6430c93d2 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c | |||
| @@ -817,40 +817,31 @@ int conf_write(const char *name) | |||
| 817 | FILE *out; | 817 | FILE *out; |
| 818 | struct symbol *sym; | 818 | struct symbol *sym; |
| 819 | struct menu *menu; | 819 | struct menu *menu; |
| 820 | const char *basename; | ||
| 821 | const char *str; | 820 | const char *str; |
| 822 | char dirname[PATH_MAX+1], tmpname[PATH_MAX+22], newname[PATH_MAX+8]; | 821 | char tmpname[PATH_MAX + 1], oldname[PATH_MAX + 1]; |
| 823 | char *env; | 822 | char *env; |
| 824 | 823 | ||
| 825 | dirname[0] = 0; | 824 | if (!name) |
| 826 | if (name && name[0]) { | 825 | name = conf_get_configname(); |
| 827 | char *slash; | 826 | |
| 828 | 827 | if (!*name) { | |
| 829 | if (is_dir(name)) { | 828 | fprintf(stderr, "config name is empty\n"); |
| 830 | strcpy(dirname, name); | 829 | return -1; |
| 831 | strcat(dirname, "/"); | 830 | } |
| 832 | basename = conf_get_configname(); | 831 | |
| 833 | } else if ((slash = strrchr(name, '/'))) { | 832 | if (is_dir(name)) { |
| 834 | int size = slash - name + 1; | 833 | fprintf(stderr, "%s: Is a directory\n", name); |
| 835 | memcpy(dirname, name, size); | 834 | return -1; |
| 836 | dirname[size] = 0; | 835 | } |
| 837 | if (slash[1]) | 836 | |
| 838 | basename = slash + 1; | ||
| 839 | else | ||
| 840 | basename = conf_get_configname(); | ||
| 841 | } else | ||
| 842 | basename = name; | ||
| 843 | } else | ||
| 844 | basename = conf_get_configname(); | ||
| 845 | |||
| 846 | sprintf(newname, "%s%s", dirname, basename); | ||
| 847 | env = getenv("KCONFIG_OVERWRITECONFIG"); | 837 | env = getenv("KCONFIG_OVERWRITECONFIG"); |
| 848 | if (!env || !*env) { | 838 | if (env && *env) { |
| 849 | sprintf(tmpname, "%s.tmpconfig.%d", dirname, (int)getpid()); | ||
| 850 | out = fopen(tmpname, "w"); | ||
| 851 | } else { | ||
| 852 | *tmpname = 0; | 839 | *tmpname = 0; |
| 853 | out = fopen(newname, "w"); | 840 | out = fopen(name, "w"); |
| 841 | } else { | ||
| 842 | snprintf(tmpname, sizeof(tmpname), "%s.%d.tmp", | ||
| 843 | name, (int)getpid()); | ||
| 844 | out = fopen(tmpname, "w"); | ||
| 854 | } | 845 | } |
| 855 | if (!out) | 846 | if (!out) |
| 856 | return 1; | 847 | return 1; |
| @@ -897,14 +888,13 @@ next: | |||
| 897 | fclose(out); | 888 | fclose(out); |
| 898 | 889 | ||
| 899 | if (*tmpname) { | 890 | if (*tmpname) { |
| 900 | strcat(dirname, basename); | 891 | snprintf(oldname, sizeof(oldname), "%s.old", name); |
| 901 | strcat(dirname, ".old"); | 892 | rename(name, oldname); |
| 902 | rename(newname, dirname); | 893 | if (rename(tmpname, name)) |
| 903 | if (rename(tmpname, newname)) | ||
| 904 | return 1; | 894 | return 1; |
| 905 | } | 895 | } |
| 906 | 896 | ||
| 907 | conf_message("configuration written to %s", newname); | 897 | conf_message("configuration written to %s", name); |
| 908 | 898 | ||
| 909 | sym_set_change_count(0); | 899 | sym_set_change_count(0); |
| 910 | 900 | ||
