diff mbox

kconfig: protect locale-unsafe calls

Message ID 1313471973-13966-1-git-send-email-lacombar@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Arnaud Lacombe Aug. 16, 2011, 5:19 a.m. UTC
There is a few calls in kconfig where we end-up using tolower(3) or toupper(3)
in an unsafe manner. As highlighted by Serdar, it would seem that Turkish's
locale do not have representable lowercase for the Engligh capital-dotless-i.

Introduces locale-safe portion in the backend where we reset the local to the
default "C".

Reported-by: Serdar KÖYLÜ <s.koylux@gmail.com>
Signed-off-by: Arnaud Lacombe <lacombar@gmail.com>
---
 scripts/kconfig/confdata.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

Comments

Arnaud Lacombe Aug. 16, 2011, 5:21 a.m. UTC | #1
Hi,

On Tue, Aug 16, 2011 at 1:19 AM, Arnaud Lacombe <lacombar@gmail.com> wrote:
> There is a few calls in kconfig where we end-up using tolower(3) or toupper(3)
> in an unsafe manner. As highlighted by Serdar, it would seem that Turkish's
> locale do not have representable lowercase for the Engligh capital-dotless-i.
>
> Introduces locale-safe portion in the backend where we reset the local to the
> default "C".
>
> Reported-by: Serdar KÖYLÜ <s.koylux@gmail.com>
> Signed-off-by: Arnaud Lacombe <lacombar@gmail.com>
>
This is not a perfect solution as we might writing stuff on the
console on those protected range, but that's a start.

 - Arnaud

> ---
>  scripts/kconfig/confdata.c |   10 ++++++++++
>  1 files changed, 10 insertions(+), 0 deletions(-)
>
> diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
> index 5a58965..7b1bbb8 100644
> --- a/scripts/kconfig/confdata.c
> +++ b/scripts/kconfig/confdata.c
> @@ -828,6 +828,8 @@ static int conf_split_config(void)
>        if (chdir("include/config"))
>                return 1;
>
> +       setlocale(LC_ALL, "C");
> +
>        res = 0;
>        for_all_symbols(i, sym) {
>                sym_calc_value(sym);
> @@ -918,6 +920,9 @@ static int conf_split_config(void)
>                }
>                close(fd);
>        }
> +
> +       setlocale(LC_ALL, "");
> +
>  out:
>        if (chdir("../.."))
>                return 1;
> @@ -956,6 +961,8 @@ int conf_write_autoconf(void)
>                return 1;
>        }
>
> +       setlocale(LC_ALL, "C");
> +
>        conf_write_heading(out, &kconfig_printer_cb, NULL);
>
>        conf_write_heading(tristate, &tristate_printer_cb, NULL);
> @@ -979,6 +986,9 @@ int conf_write_autoconf(void)
>
>                conf_write_symbol(out_h, sym, &header_printer_cb, NULL);
>        }
> +
> +       setlocale(LC_ALL, "");
> +
>        fclose(out);
>        fclose(tristate);
>        fclose(out_h);
> --
> 1.7.6.153.g78432
>
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Michal Marek Aug. 31, 2011, 12:19 p.m. UTC | #2
On 16.8.2011 07:19, Arnaud Lacombe wrote:
> There is a few calls in kconfig where we end-up using tolower(3) or toupper(3)
> in an unsafe manner. As highlighted by Serdar, it would seem that Turkish's
> locale do not have representable lowercase for the Engligh capital-dotless-i.
> 
> Introduces locale-safe portion in the backend where we reset the local to the
> default "C".
> 
> Reported-by: Serdar KÖYLÜ <s.koylux@gmail.com>
> Signed-off-by: Arnaud Lacombe <lacombar@gmail.com>
> ---
>  scripts/kconfig/confdata.c |   10 ++++++++++

I think that just changing kconfig will make things even worse, because
fixdep does the same operation (CONFIG_FOO -> include/config/foo.h) and
would get out of sync with kconfig now. I guess the direct cause for
Serdar's build failure was this staging driver:
drivers/staging/cxt1e1/sbecom_inline_linux.h:

    53  #if defined(CONFIG_MODVERSIONS) && defined(MODULE) && !
defined(MODVERSIONS)
    54  #define MODVERSIONS
    55  #endif
    56
    57  #ifdef MODULE
    58  #ifdef MODVERSIONS
    59  #include <config/modversions.h>
                  ^^^^^^^^^^^^^^^^^^^^
    60  #endif
    61  #include <linux/module.h>
    62  #endif
    63  #endif

I'll send a patch cleaning this up once I verify that it really is the
cause.

As for the tollower/toupper issue, I would propose a much simpler way:
Let's not try to be cute and simply use include/config/FOO_BAR.h for
each CONFIG_FOO_BAR. x86_64 allmodconfig results in some 5k symbols
enabled, I'm sure any filesystem will handle a directory with 5k files
in it.

Michal
--
To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Arnaud Lacombe Aug. 31, 2011, 1:35 p.m. UTC | #3
Hi,

On Wed, Aug 31, 2011 at 8:19 AM, Michal Marek <mmarek@suse.cz> wrote:
> On 16.8.2011 07:19, Arnaud Lacombe wrote:
>> There is a few calls in kconfig where we end-up using tolower(3) or toupper(3)
>> in an unsafe manner. As highlighted by Serdar, it would seem that Turkish's
>> locale do not have representable lowercase for the Engligh capital-dotless-i.
>>
>> Introduces locale-safe portion in the backend where we reset the local to the
>> default "C".
>>
>> Reported-by: Serdar KÖYLÜ <s.koylux@gmail.com>
>> Signed-off-by: Arnaud Lacombe <lacombar@gmail.com>
>> ---
>>  scripts/kconfig/confdata.c |   10 ++++++++++
>
> I think that just changing kconfig will make things even worse, because
> fixdep does the same operation (CONFIG_FOO -> include/config/foo.h) and
> would get out of sync with kconfig now. I guess the direct cause for
> Serdar's build failure was this staging driver:
> drivers/staging/cxt1e1/sbecom_inline_linux.h:
>
>    53  #if defined(CONFIG_MODVERSIONS) && defined(MODULE) && !
> defined(MODVERSIONS)
>    54  #define MODVERSIONS
>    55  #endif
>    56
>    57  #ifdef MODULE
>    58  #ifdef MODVERSIONS
>    59  #include <config/modversions.h>
>                  ^^^^^^^^^^^^^^^^^^^^
>    60  #endif
>    61  #include <linux/module.h>
>    62  #endif
>    63  #endif
>
> I'll send a patch cleaning this up once I verify that it really is the
> cause.
>
> As for the tollower/toupper issue, I would propose a much simpler way:
> Let's not try to be cute and simply use include/config/FOO_BAR.h for
> each CONFIG_FOO_BAR. x86_64 allmodconfig results in some 5k symbols
> enabled, I'm sure any filesystem will handle a directory with 5k files
> in it.
>
fine with me.

 - Arnaud

> Michal
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Michal Marek Sept. 1, 2011, 2:23 p.m. UTC | #4
On 31.8.2011 14:19, Michal Marek wrote:
> As for the tollower/toupper issue, I would propose a much simpler way:
> Let's not try to be cute and simply use include/config/FOO_BAR.h for
> each CONFIG_FOO_BAR. x86_64 allmodconfig results in some 5k symbols
> enabled, I'm sure any filesystem will handle a directory with 5k files
> in it.

Unfortunately, we can't do this, because updating from a tree that used
include/config/foo/bar.h would result in missed rebuilds :-(.

Michal
--
To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index 5a58965..7b1bbb8 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -828,6 +828,8 @@  static int conf_split_config(void)
 	if (chdir("include/config"))
 		return 1;
 
+	setlocale(LC_ALL, "C");
+
 	res = 0;
 	for_all_symbols(i, sym) {
 		sym_calc_value(sym);
@@ -918,6 +920,9 @@  static int conf_split_config(void)
 		}
 		close(fd);
 	}
+
+	setlocale(LC_ALL, "");
+
 out:
 	if (chdir("../.."))
 		return 1;
@@ -956,6 +961,8 @@  int conf_write_autoconf(void)
 		return 1;
 	}
 
+	setlocale(LC_ALL, "C");
+
 	conf_write_heading(out, &kconfig_printer_cb, NULL);
 
 	conf_write_heading(tristate, &tristate_printer_cb, NULL);
@@ -979,6 +986,9 @@  int conf_write_autoconf(void)
 
 		conf_write_symbol(out_h, sym, &header_printer_cb, NULL);
 	}
+
+	setlocale(LC_ALL, "");
+
 	fclose(out);
 	fclose(tristate);
 	fclose(out_h);