xen/Kconfig: Fix -Wformat-security when compiling with Clang
PATCH 1/1 xen/Kconfig: Fix -Wformat-security when compiling with Clang
Clang observes:
tools/kconfig/conf.c:77:10:
warning: format string is not a string literal (potentially insecure)
[-Wformat-security]
printf(_("aborted!\n\n"));
^~~~~~~~~~~~~~~~~And it is absolutely correct. gettext() can easily return a string with a % in.
This could be fixed by switching to using printf("%s", _(...)), or by switching to puts() (as there is no formatting going on), but the better option is follow Linux and remove localisation support.
Linux changeset: 694c49a7c01cc87194be40cb26404b58b68c291c
Author: Sam Ravnborg <[email protected]>
Date: Tue May 22 20:36:12 2018
kconfig: drop localization support
The localization support is broken and appears unused. There is no google hits on the update-po-config target.
And there is no recent (5 years) activity related to the localization.
So lets just drop this as it is no longer used.
---
CC: Doug Goldstein <[email protected]>
--- xen/tools/kconfig/.gitignore | 4 - xen/tools/kconfig/Makefile | 39 +----- xen/tools/kconfig/POTFILES.in | 12 -- xen/tools/kconfig/check.sh | 13 -- xen/tools/kconfig/conf.c | 57 ++++---- xen/tools/kconfig/confdata.c | 4 +- xen/tools/kconfig/gconf.c | 46 +++---- xen/tools/kconfig/kxgettext.c | 235 --------------------------------- xen/tools/kconfig/lkc.h | 14 -- xen/tools/kconfig/lxdialog/checklist.c | 4 +- xen/tools/kconfig/lxdialog/dialog.h | 6 - xen/tools/kconfig/lxdialog/inputbox.c | 4 +- xen/tools/kconfig/lxdialog/menubox.c | 10 +- xen/tools/kconfig/lxdialog/textbox.c | 2 +- xen/tools/kconfig/lxdialog/yesno.c | 4 +- xen/tools/kconfig/mconf.c | 141 ++++++++++---------- xen/tools/kconfig/menu.c | 18 +-- xen/tools/kconfig/nconf.c | 148 ++++++++++----------- xen/tools/kconfig/nconf.h | 1 - xen/tools/kconfig/qconf.cc | 112 +++++++--------- xen/tools/kconfig/zconf.tab.c_shipped | 2 +- xen/tools/kconfig/zconf.y | 2 +- 22 files changed, 265 insertions(+), 613 deletions(-) delete mode 100644 xen/tools/kconfig/POTFILES.in delete mode 100755 xen/tools/kconfig/check.sh delete mode 100644 xen/tools/kconfig/kxgettext.c
xen/tools/kconfig/.gitignore +0 -4
@@ -7,9 +7,6 @@ config* *.tab.h zconf.hash.c *.moc -gconf.glade.h -*.pot -*.mo # # configuration programs
@@ -19,4 +16,3 @@ mconf nconf qconf gconf -kxgettext
xen/tools/kconfig/Makefile +3 -36
@@ -2,7 +2,7 @@ # Kernel configuration targets # These targets are used from top-level makefile -PHONY += xconfig gconfig menuconfig config silentoldconfig update-po-config \ +PHONY += xconfig gconfig menuconfig config silentoldconfig \ localmodconfig localyesconfig ifdef KBUILD_KCONFIG
@@ -52,29 +52,6 @@ localyesconfig localmodconfig: $(obj)/streamline_config.pl $(obj)/conf fi $(Q)rm -f .tmp.config -# Create new linux.pot file -# Adjust charset to UTF-8 in .po file to accept UTF-8 in Kconfig files -update-po-config: $(obj)/kxgettext $(obj)/gconf.glade.h - $(Q)$(kecho) " GEN config.pot" - $(Q)xgettext --default-domain=linux \ - --add-comments --keyword=_ --keyword=N_ \ - --from-code=UTF-8 \ - --files-from=$(srctree)/scripts/kconfig/POTFILES.in \ - --directory=$(srctree) --directory=$(objtree) \ - --output $(obj)/config.pot - $(Q)sed -i s/CHARSET/UTF-8/ $(obj)/config.pot - $(Q)(for i in `ls $(srctree)/arch/*/Kconfig \ - $(srctree)/arch/*/um/Kconfig`; \ - do \ - $(kecho) " GEN $$i"; \ - $(obj)/kxgettext $$i \ - >> $(obj)/config.pot; \ - done ) - $(Q)$(kecho) " GEN linux.pot" - $(Q)msguniq --sort-by-file --to-code=UTF-8 $(obj)/config.pot \ - --output $(obj)/linux.pot - $(Q)rm -f $(obj)/config.pot - # These targets map 1:1 to the commandline options of 'conf' simple-targets := oldconfig allnoconfig allyesconfig allmodconfig \ alldefconfig randconfig listnewconfig olddefconfig
@@ -176,16 +153,14 @@ lxdialog += lxdialog/textbox.o lxdialog/yesno.o lxdialog/menubox.o conf-objs := conf.o zconf.tab.o mconf-objs := mconf.o zconf.tab.o $(lxdialog) nconf-objs := nconf.o zconf.tab.o nconf.gui.o -kxgettext-objs := kxgettext.o zconf.tab.o qconf-cxxobjs := qconf.o qconf-objs := zconf.tab.o gconf-objs := gconf.o zconf.tab.o -hostprogs-y := conf nconf mconf kxgettext qconf gconf +hostprogs-y := conf nconf mconf qconf gconf clean-files := qconf.moc .tmp_qtcheck .tmp_gtkcheck -clean-files += zconf.tab.c zconf.lex.c zconf.hash.c gconf.glade.h -clean-files += config.pot linux.pot +clean-files += zconf.tab.c zconf.lex.c zconf.hash.c # Check that we have the required ncurses stuff installed for lxdialog (menuconfig) PHONY += $(obj)/dochecklxdialog
@@ -195,9 +170,6 @@ $(obj)/dochecklxdialog: always := dochecklxdialog -# Add environment specific flags -HOST_EXTRACFLAGS += $(shell $(CONFIG_SHELL) $(srctree)/$(src)/check.sh $(HOSTCC) $(HOSTCFLAGS)) - # generated files seem to need this to find local include files HOSTCFLAGS_zconf.lex.o := -I$(src) HOSTCFLAGS_zconf.tab.o := -I$(src)
@@ -310,8 +282,3 @@ quiet_cmd_moc = MOC $@ $(obj)/%.moc: $(src)/%.h $(obj)/.tmp_qtcheck $(call cmd,moc) - -# Extract gconf menu items for i18n support -$(obj)/gconf.glade.h: $(obj)/gconf.glade - $(Q)intltool-extract --type=gettext/glade --srcdir=$(srctree) \ - $(obj)/gconf.glade
xen/tools/kconfig/POTFILES.in deleted +0 -12
@@ -1,12 +0,0 @@ -scripts/kconfig/lxdialog/checklist.c -scripts/kconfig/lxdialog/inputbox.c -scripts/kconfig/lxdialog/menubox.c -scripts/kconfig/lxdialog/textbox.c -scripts/kconfig/lxdialog/util.c -scripts/kconfig/lxdialog/yesno.c -scripts/kconfig/mconf.c -scripts/kconfig/conf.c -scripts/kconfig/confdata.c -scripts/kconfig/gconf.c -scripts/kconfig/gconf.glade.h -scripts/kconfig/qconf.cc
xen/tools/kconfig/check.sh deleted +0 -13
@@ -1,13 +0,0 @@ -#!/bin/sh -# Needed for systems without gettext -$* -x c -o /dev/null - > /dev/null 2>&1 << EOF -#include <libintl.h> -int main() -{ - gettext(""); - return 0; -} -EOF -if [ ! "$?" -eq "0" ]; then - echo -DKBUILD_NO_NLS; -fi
xen/tools/kconfig/conf.c +26 -31
193 lines not on this page · raw message
xen/tools/kconfig/confdata.c +2 -2
@@ -279,7 +279,7 @@ int conf_read_simple(const char *name, int def) name =conf_expand_value (prop->expr->left.sym->name); in =zconf_fopen (name);if (in) { -conf_message (_ ("using defaults found in %s" ), +conf_message ("using defaults found in %s" , name); goto load; }
@@ -828,7 +828,7 @@ int conf_write(const char *name)return 1 ; } -conf_message (_ ("configuration written to %s" ), newname); +conf_message ("configuration written to %s" , newname);sym_set_change_count (0 );
xen/tools/kconfig/gconf.c +21 -25
167 lines not on this page · raw message
xen/tools/kconfig/kxgettext.c deleted +0 -235
235 lines not on this page · raw message
xen/tools/kconfig/lkc.h +0 -14
@@ -8,15 +8,6 @@#include "expr.h" -#ifndef KBUILD_NO_NLS -# include <libintl.h> -#else -static inline const char *gettext (const char *txt) {return txt; } -static inline void textdomain (const char *domainname) {} -static inline void bindtextdomain (const char *name,const char *dir) {} -static inline char *bind_textdomain_codeset (const char *dn,char *c) {return c; } -#endif -#ifdef __cplusplusextern "C" {#endif
@@ -29,11 +20,6 @@ extern "C" {#define PACKAGE "linux"#endif -#define LOCALEDIR "/usr/share/locale" - -#define _ (text) gettext(text) -#define N_ (text) (text) -#ifndef CONFIG_ #define CONFIG_ "CONFIG_"#endif
xen/tools/kconfig/lxdialog/checklist.c +2 -2
@@ -103,8 +103,8 @@ static void print_buttons(WINDOW * dialog, int height, int width, int selected)int x = width /2 -11 ;int y = height -2 ; -print_button (dialog,gettext ("Select" ), y, x, selected ==0 ); -print_button (dialog,gettext (" Help " ), y, x +14 , selected ==1 ); +print_button (dialog,"Select" , y, x, selected ==0 ); +print_button (dialog," Help " , y, x +14 , selected ==1 );wmove (dialog, y, x +1 +14 * selected);wrefresh (dialog);
xen/tools/kconfig/lxdialog/dialog.h +0 -6
@@ -26,12 +26,6 @@#include <string.h> #include <stdbool.h> -#ifndef KBUILD_NO_NLS -# include <libintl.h> -#else -# define gettext (Msgid) ((const char *) (Msgid)) -#endif -#ifdef __sun__#define CURS_MACROS #endif
xen/tools/kconfig/lxdialog/inputbox.c +2 -2
@@ -31,8 +31,8 @@ static void print_buttons(WINDOW * dialog, int height, int width, int selected)int x = width /2 -11 ;int y = height -2 ; -print_button (dialog,gettext (" Ok " ), y, x, selected ==0 ); -print_button (dialog,gettext (" Help " ), y, x +14 , selected ==1 ); +print_button (dialog," Ok " , y, x, selected ==0 ); +print_button (dialog," Help " , y, x +14 , selected ==1 );wmove (dialog, y, x +1 +14 * selected);wrefresh (dialog);
xen/tools/kconfig/lxdialog/menubox.c +5 -5
@@ -157,11 +157,11 @@ static void print_buttons(WINDOW * win, int height, int width, int selected)int x = width /2 -28 ;int y = height -2 ; -print_button (win,gettext ("Select" ), y, x, selected ==0 ); -print_button (win,gettext (" Exit " ), y, x +12 , selected ==1 ); -print_button (win,gettext (" Help " ), y, x +24 , selected ==2 ); -print_button (win,gettext (" Save " ), y, x +36 , selected ==3 ); -print_button (win,gettext (" Load " ), y, x +48 , selected ==4 ); +print_button (win,"Select" , y, x, selected ==0 ); +print_button (win," Exit " , y, x +12 , selected ==1 ); +print_button (win," Help " , y, x +24 , selected ==2 ); +print_button (win," Save " , y, x +36 , selected ==3 ); +print_button (win," Load " , y, x +48 , selected ==4 );wmove (win, y, x +1 +12 * selected);wrefresh (win);
xen/tools/kconfig/lxdialog/textbox.c +1 -1
@@ -129,7 +129,7 @@ int dialog_textbox(const char *title, char *tbuf, int initial_height,print_title (dialog, title, width); -print_button (dialog,gettext (" Exit " ), height -2 , width /2 -4 , TRUE); +print_button (dialog," Exit " , height -2 , width /2 -4 , TRUE);wnoutrefresh (dialog);getyx (dialog, cur_y, cur_x);/* Save cursor position */
xen/tools/kconfig/lxdialog/yesno.c +2 -2
@@ -29,8 +29,8 @@ static void print_buttons(WINDOW * dialog, int height, int width, int selected)int x = width /2 -10 ;int y = height -2 ; -print_button (dialog,gettext (" Yes " ), y, x, selected ==0 ); -print_button (dialog,gettext (" No " ), y, x +13 , selected ==1 ); +print_button (dialog," Yes " , y, x, selected ==0 ); +print_button (dialog," No " , y, x +13 , selected ==1 );wmove (dialog, y, x +1 +13 * selected);wrefresh (dialog);
xen/tools/kconfig/mconf.c +68 -73
367 lines not on this page · raw message
xen/tools/kconfig/menu.c +9 -9
@@ -550,7 +550,7 @@ static void get_prompt_str(struct gstr *r, struct property *prop,struct menu *submenu[8 ], *menu, *location =NULL ;struct jump_key *jump =NULL ; -str_printf (r,_ ("Prompt: %s\n" ),_ (prop->text)); +str_printf (r,"Prompt: %s\n" , prop->text); menu = prop->menu->parent;for (i =0 ; menu != &rootmenu && i <8 ; menu = menu->parent) {bool accessible =menu_is_visible (menu);
@@ -583,16 +583,16 @@ static void get_prompt_str(struct gstr *r, struct property *prop, }if (i >0 ) { -str_printf (r,_ (" Location:\n" )); +str_printf (r," Location:\n" );for (j =4 ; --i >=0 ; j +=2 ) { menu = submenu[i];if (jump && menu == location) jump->offset =strlen (r->s);str_printf (r,"%*c-> %s" , j,' ' , -_ (menu_get_prompt (menu))); +menu_get_prompt (menu));if (menu->sym) {str_printf (r," (%s [=%s])" , menu->sym->name ? - menu->sym->name :_ ("<choice>" ), + menu->sym->name :"<choice>" ,sym_get_string_value (menu->sym)); }str_append (r,"\n" );
@@ -639,10 +639,10 @@ static void get_symbol_str(struct gstr *r, struct symbol *sym, prop =get_symbol_prop (sym);if (prop) { -str_printf (r,_ (" Defined at %s:%d\n" ), prop->menu->file->name, +str_printf (r," Defined at %s:%d\n" , prop->menu->file->name, prop->menu->lineno);if (!expr_is_yes (prop->visible.expr)) { -str_append (r,_ (" Depends on: " )); +str_append (r," Depends on: " );expr_gstr_print (prop->visible.expr, r);str_append (r,"\n" ); }
@@ -660,7 +660,7 @@ static void get_symbol_str(struct gstr *r, struct symbol *sym,if (hit)str_append (r,"\n" );if (sym->rev_dep.expr) { -str_append (r,_ (" Selected by: " )); +str_append (r," Selected by: " );expr_gstr_print (sym->rev_dep.expr, r);str_append (r,"\n" ); }
@@ -676,7 +676,7 @@ struct gstr get_relations_str(struct symbol **sym_arr, struct list_head *head)for (i =0 ; sym_arr && (sym = sym_arr[i]); i++)get_symbol_str (&res, sym, head);if (!i) -str_append (&res,_ ("No matches found.\n" )); +str_append (&res,"No matches found.\n" );return res; }
@@ -691,7 +691,7 @@ void menu_get_ext_help(struct menu *menu, struct gstr *help)str_printf (help,"%s%s:\n\n" ,CONFIG_ , sym->name); help_text =menu_get_help (menu); } -str_printf (help,"%s\n" ,_ (help_text)); +str_printf (help,"%s\n" , help_text);if (sym)get_symbol_str (help, sym,NULL ); }
xen/tools/kconfig/nconf.c +72 -76
388 lines not on this page · raw message
xen/tools/kconfig/nconf.h +0 -1
@@ -14,7 +14,6 @@#include <stdlib.h> #include <string.h> #include <unistd.h> -#include <locale.h> #include <curses.h> #include <menu.h> #include <panel.h>
xen/tools/kconfig/qconf.cc +50 -62
317 lines not on this page · raw message
xen/tools/kconfig/zconf.tab.c_shipped +1 -1
@@ -2349,7 +2349,7 @@ void conf_parse(const char *name) if (!modules_sym) modules_sym = sym_find( "n" ); - rootmenu.prompt->text = _(rootmenu.prompt->text); + rootmenu.prompt->text = rootmenu.prompt->text; rootmenu.prompt->text = sym_expand_string_value(rootmenu.prompt->text); menu_finalize(&rootmenu);
xen/tools/kconfig/zconf.y +1 -1
@@ -512,7 +512,7 @@ void conf_parse(const char *name) if (!modules_sym) modules_sym = sym_find( "n" ); - rootmenu.prompt->text = _(rootmenu.prompt->text); + rootmenu.prompt->text = rootmenu.prompt->text; rootmenu.prompt->text = sym_expand_string_value(rootmenu.prompt->text); menu_finalize(&rootmenu);
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 27 lines · Andrew Cooper
Clang observes:
tools/kconfig/conf.c:77:10:
warning: format string is not a string literal (potentially insecure)[-Wformat-security] printf(_("aborted!\n\n")); ^~~~~~~~~~~~~~~~~And it is absolutely correct.
gettext()can easily return a string with a % in.This could be fixed by switching to using
printf("%s", _(...)), or by switching toputs()(as there is no formatting going on), but the better option is follow Linux and remove localisation support.Linux changeset:
694c49a7c01cc87194be40cb26404b58b68c291c
Author: Sam Ravnborg <[email protected]>
Date: Tue May 22 20:36:12 2018kconfig: drop localization support
The localization support is broken and appears unused. There is no google hits on the update-po-config target.
And there is no recent (5 years) activity related to the localization.So lets just drop this as it is no longer used.
Quoted 8 lines
Suggested-by Ulf Magnusson <[email protected]>Suggested-by Masahiro Yamada <[email protected]>Signed-off-by Sam Ravnborg <[email protected]>Signed-off-by Masahiro Yamada <[email protected]>[Ported to Xen]Reported-by Roger Pau Monné <[email protected]>Signed-off-by Andrew Cooper <[email protected]>
I haven't built this locally but overall I think this is a good backport to do. In the past there were a lot of concerns about the size of the Kconfig code base that we were bringing into the tree and some of the functionality that seemed less than necessary. The approach was taken to always backport from Linux to ease the maintenance burden for Xen but a backport like this seems like it achieves both goals.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 26.06.19 at 19:36, <[email protected]> wrote:
Clang observes:
tools/kconfig/conf.c:77:10:
warning: format string is not a string literal (potentially insecure)[-Wformat-security] printf(_("aborted!\n\n")); ^~~~~~~~~~~~~~~~~And it is absolutely correct.
gettext()can easily return a string with a % in.
I'm pretty curious: Where would a % come from when there's none in the original English string? I wouldn't call it "proper translation" if a translated string had non-textual things in it that the original didn't have. Or are there languages using % in ordinary words?
Note that this is in no way an objection to the change, the more that it's a reduction of source size.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 9 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 26.06.19 at 19:36, <[email protected]> wrote:
Clang observes:
tools/kconfig/conf.c:77:10:
warning: format string is not a string literal (potentially insecure)[-Wformat-security] printf(_("aborted!\n\n")); ^~~~~~~~~~~~~~~~~
Quoted 6 lines
Quoted 2 lines
And it is absolutely correct.
gettext()can easily return a string with a % in.I'm pretty curious: Where would a % come from when there's none in the original English string? I wouldn't call it "proper translation" if a translated string had non-textual things in it that the original didn't have. Or are there languages using % in ordinary words?
Well - thats why I carefully worded it as "easy to return", rather than "there are valid translations which contain..."
That said, I bet you can have a lot of fun with translations which use non-ASCII characters.
Quoted 2 lines
Note that this is in no way an objection to the change, the more that it's a reduction of source size.
In which case can I further recommend that we drop the QT and glade versions. They don't build (and never have it seems).
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel