Skip to contentSkip to conversation

build: Add warnings for non-literal strings

PATCH In review Bastien Nocera 3 participants 8 messages Mar 4, 2021 – Mar 5, 2021 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 build: Add warnings for non-literal strings

---
 acinclude.m4 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
acinclude.m4 +1 -1
index 529848357..6ae34b8ae 100644
@@ -21,7 +21,7 @@ AC_DEFUN([COMPILER_FLAGS], [
 		with_cflags="$with_cflags -Wredundant-decls"
 		with_cflags="$with_cflags -Wcast-align"
 		with_cflags="$with_cflags -Wswitch-enum"
-		with_cflags="$with_cflags -Wformat -Wformat-security"
+		with_cflags="$with_cflags -Wformat -Wformat-security -Wformat-nonliteral"
 		with_cflags="$with_cflags -DG_DISABLE_DEPRECATED"
 		with_cflags="$with_cflags -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_28"
 		with_cflags="$with_cflags -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_32"
Signature · 1 line
2.29.2
#1 lore raw

PATCH 2/3 obex: Work-around compilation failure

obexd/plugins/bluetooth.c: In function 'register_profile':
obexd/plugins/bluetooth.c:310:7: error: format not a string literal, argument types not checked [-Werror=format-nonliteral]

       profile->driver->port);
       ^~~~~~~
obexd/plugins/bluetooth.c:314:7: error: format not a string literal, argument types not checked [-Werror=format-nonliteral]
       profile->driver->name);
       ^~~~~~~
---
 obexd/plugins/bluetooth.c | 4 ++++
 1 file changed, 4 insertions(+)
obexd/plugins/bluetooth.c +4 -0
index d232d3fd5..66f432d66 100644
@@ -258,6 +258,9 @@ static int register_profile(struct bluetooth_profile *profile)
 					&opt);
 	g_dbus_dict_append_entry(&opt, "AutoConnect", DBUS_TYPE_BOOLEAN,
 								&auto_connect);
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
 	if (profile->driver->record) {
 		if (profile->driver->port != 0)
 			xml = g_markup_printf_escaped(profile->driver->record,
@@ -268,6 +271,7 @@ static int register_profile(struct bluetooth_profile *profile)
 			xml = g_markup_printf_escaped(profile->driver->record,
 						profile->driver->channel,
 						profile->driver->name);
+#pragma GCC diagnostic pop
 		g_dbus_dict_append_entry(&opt, "ServiceRecord",
 						DBUS_TYPE_STRING, &xml);
 		g_free(xml);
Signature · 1 line
2.29.2
#2 lore raw

PATCH 3/3 tools/mesh-cfglient: Work-around compilation failure

In reply to Bastien Nocera

tools/mesh-cfgclient.c: In function ‘disp_numeric_call’:
tools/mesh-cfgclient.c:543:10: error: format not a string literal, argument types not checked [-Werror=format-nonliteral]

  543 |          n);
      |          ^
---
 tools/mesh-cfgclient.c | 3 +++
 1 file changed, 3 insertions(+)
tools/mesh-cfgclient.c +3 -0
index 1eeed2a1a..ab5026e9b 100644
@@ -530,8 +530,11 @@ static struct l_dbus_message *disp_numeric_call(struct l_dbus *dbus,
 	if (action_index < 0)
 		return l_dbus_message_new_error(msg, dbus_err_support, NULL);
 
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
 	str = l_strdup_printf(display_numeric_table[action_index].description,
 									n);
+#pragma GCC diagnostic pop
 	bt_shell_printf(COLOR_YELLOW "%s\n" COLOR_OFF, str);
 	l_free(str);
 
Signature · 1 line
2.29.2
#3 lore raw
In reply to Bastien Nocera

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=442025

---Test result---

##############################
Test: CheckPatch - PASS

##############################
Test: CheckGitLint - FAIL
Output:
build: Add warnings for non-literal strings
3: B6 Body message is missing

obex: Work-around compilation failure
4: B1 Line exceeds max length (123>80): "obexd/plugins/bluetooth.c:310:7: error: format not a string literal, argument types not checked [-Werror=format-nonliteral]" 7: B1 Line exceeds max length (123>80): "obexd/plugins/bluetooth.c:314:7: error: format not a string literal, argument types not checked [-Werror=format-nonliteral]"

tools/mesh-cfglient: Work-around compilation failure
4: B1 Line exceeds max length (121>80): "tools/mesh-cfgclient.c:543:10: error: format not a string literal, argument types not checked [-Werror=format-nonliteral]"

##############################
Test: CheckBuild - PASS

##############################
Test: MakeCheck - PASS

---
Regards,
Linux Bluetooth

#4 lore raw
In reply to Bastien Nocera

Hi Bastien,

Quoted 10 lines · Bastien Nocera
---
 acinclude.m4 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
acinclude.m4 +0 -0
index 529848357..6ae34b8ae 100644

acinclude.m4 AC_DEFUN([COMPILER_FLAGS], [ · line 24

Quoted 5 lines
acinclude.m4 +1 -1
@@ -21,7 +21,7 @@ AC_DEFUN([COMPILER_FLAGS], [
                with_cflags="$with_cflags -Wredundant-decls"
                with_cflags="$with_cflags -Wcast-align"
                with_cflags="$with_cflags -Wswitch-enum"
-               with_cflags="$with_cflags -Wformat -Wformat-security"
+               with_cflags="$with_cflags -Wformat -Wformat-security -Wformat-nonliteral"

Does it actually have any benefit of having the format as always string literal? I'm not really a big fan of using pragmas.

Quoted 6 lines
acinclude.m4 +0 -1
                with_cflags="$with_cflags -DG_DISABLE_DEPRECATED"
                with_cflags="$with_cflags -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_28"
                with_cflags="$with_cflags -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_32"
--

2.29.2

Signature · 1 line
Luiz Augusto von Dentz
#5 lore raw
Quoted 9 lines · Luiz Augusto von Dentz

Hi Bastien,

Quoted 5 lines · Bastien Nocera

---
 acinclude.m4 | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 14 lines
Quoted 11 lines
acinclude.m4 +0 -0
index 529848357..6ae34b8ae 100644
@@ -21,7 +21,7 @@ AC_DEFUN([COMPILER_FLAGS], [

                with_cflags="$with_cflags -Wredundant-decls" with_cflags="$with_cflags -Wcast-align" with_cflags="$with_cflags -Wswitch-enum"
-               with_cflags="$with_cflags -Wformat -Wformat-security" +               with_cflags="$with_cflags -Wformat -Wformat-security -Wformat-nonliteral"

Does it actually have any benefit of having the format as always string literal? I'm not really a big fan of using pragmas.

It's a security feature[1], so it's pretty important that we avoid using non-literals when some of the arguments are user controlled, especially in a networked daemon. We already enabled "-Wformat-security", so not that much of a difference.

This warning is also enabled by default on Fedora's GCC, so I get to see it whether I want to or not.

I'd be happy actually fixing those warnings if you don't want pragmas at all, it would just be more code movement. If we can get those patches in, I can do a follow-up.

[1]: Quick search gave me this explanation:
https://owasp.org/www-community/attacks/Format_string_attack

Quoted 10 lines
Quoted 8 lines

                with_cflags="$with_cflags -DG_DISABLE_DEPRECATED" with_cflags="$with_cflags - DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_28" with_cflags="$with_cflags - DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_32"
--
2.29.2

#6 lore raw

Hi Bastien,

Quoted 34 lines · Bastien Nocera
Quoted 9 lines · Luiz Augusto von Dentz

Hi Bastien,

Quoted 5 lines · Bastien Nocera
---
 acinclude.m4 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 14 lines

acinclude.m4 AC_DEFUN([COMPILER_FLAGS], [ · line 25

Quoted 11 lines
acinclude.m4 +1 -2
index 529848357..6ae34b8ae 100644
@@ -21,7 +21,7 @@ AC_DEFUN([COMPILER_FLAGS], [
                with_cflags="$with_cflags -Wredundant-decls"
                with_cflags="$with_cflags -Wcast-align"
                with_cflags="$with_cflags -Wswitch-enum"
-               with_cflags="$with_cflags -Wformat -Wformat-security"
+               with_cflags="$with_cflags -Wformat -Wformat-security
-Wformat-nonliteral"

Does it actually have any benefit of having the format as always string literal? I'm not really a big fan of using pragmas.

It's a security feature[1], so it's pretty important that we avoid using non-literals when some of the arguments are user controlled, especially in a networked daemon. We already enabled "-Wformat-security", so not that much of a difference.

This warning is also enabled by default on Fedora's GCC, so I get to see it whether I want to or not.

Quoted 6 lines

I'd be happy actually fixing those warnings if you don't want pragmas at all, it would just be more code movement. If we can get those patches in, I can do a follow-up.

[1]: Quick search gave me this explanation:
https://owasp.org/www-community/attacks/Format_string_attack

You should probably add the above link in the patch description, regarding the use of pragma. I'd say we need to convert to use literals directly then since otherwise we are not actually fixing anything just returning it back to ignore the error where we don't use literals.

Quoted 12 lines
Quoted 10 lines
Quoted 8 lines
acinclude.m4 +0 -0
                with_cflags="$with_cflags -DG_DISABLE_DEPRECATED"
                with_cflags="$with_cflags -

DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_28"
with_cflags="$with_cflags -
DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_32"
--
2.29.2

Signature · 1 line
Luiz Augusto von Dentz
#7 lore raw
Quoted 46 lines · Luiz Augusto von Dentz

Hi Bastien,

Quoted 42 lines · Bastien Nocera
Quoted 9 lines · Luiz Augusto von Dentz

Hi Bastien,

Quoted 5 lines · Bastien Nocera

---
 acinclude.m4 | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines
Quoted 5 lines
acinclude.m4 +0 -0
index 529848357..6ae34b8ae 100644
@@ -21,7 +21,7 @@ AC_DEFUN([COMPILER_FLAGS], [
Quoted 8 lines

                with_cflags="$with_cflags -Wredundant-decls" with_cflags="$with_cflags -Wcast-align" with_cflags="$with_cflags -Wswitch-enum" -               with_cflags="$with_cflags -Wformat -Wformat- security"
+               with_cflags="$with_cflags -Wformat -Wformat- security
-Wformat-nonliteral"

Does it actually have any benefit of having the format as always string literal? I'm not really a big fan of using pragmas.

It's a security feature[1], so it's pretty important that we avoid using non-literals when some of the arguments are user controlled, especially in a networked daemon. We already enabled "-Wformat-security", so not that much of a difference.

This warning is also enabled by default on Fedora's GCC, so I get to
see it whether I want to or not.

I'd be happy actually fixing those warnings if you don't want pragmas
at all, it would just be more code movement. If we can get those patches in, I can do a follow-up.

Quoted 7 lines
Quoted 2 lines

[1]: Quick search gave me this explanation:
https://owasp.org/www-community/attacks/Format_string_attack

You should probably add the above link in the patch description, regarding the use of pragma. I'd say we need to convert to use literals directly then since otherwise we are not actually fixing anything

We're presumably stopping new non-literals from being introduced...

As I mentioned, I can do a follow-up, but I'm not going to do the work until this patch series is merged. I've sent it a number of times already and after 4 years, I'm not sure I want to do the work again only for it to rot in my repo.

Quoted 18 lines

just returning it back to ignore the error where we don't use
literals.

Quoted 13 lines
Quoted 11 lines
Quoted 9 lines

                with_cflags="$with_cflags -
DG_DISABLE_DEPRECATED"
                with_cflags="$with_cflags -
DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_28"
                with_cflags="$with_cflags -
DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_32"
--
2.29.2