Skip to contentSkip to conversation

lib/vsprintf.c: remove leftover 'f' and 'F' cases from bstr_printf()

PATCH In review Rasmus Villemoes 4 participants 4 messages Apr 23, 2021 – Apr 26, 2021

Subsystems (3)
lore
Share & tools
lore

Rasmus Villemoes

author reviewer
#0 lore raw

PATCH 1/1 lib/vsprintf.c: remove leftover 'f' and 'F' cases from bstr_printf()

Commit 9af7706492f9 ("lib/vsprintf: Remove support for %pF and %pf in favour of %pS and %ps") removed support for %pF and %pf, and correctly removed the handling of those cases in vbin_printf(). However, the corresponding cases in bstr_printf() were left behind.

In the same series, %pf was re-purposed for dealing with fwnodes (3bd32d6a2ee6, "lib/vsprintf: Add %pfw conversion specifier for printing fwnode names").

So should anyone use %pf with the binary printf routines, vbin_printf() would (correctly, as it involves dereferencing the pointer) do the string formatting to the u32 array, but bstr_printf() would not copy the string from the u32 array, but instead interpret the first sizeof(void*) bytes of the formatted string as a pointer - which generally won't end well (also, all subsequent get_args would be out of sync).

Fixes 9af7706492f9 ("lib/vsprintf: Remove support for %pF and %pf in favour of %pS and %ps")
---
 lib/vsprintf.c | 2 --
 1 file changed, 2 deletions(-)
lib/vsprintf.c +0 -2
index 41ddc353ebb8..39ef2e314da5 100644
@@ -3135,8 +3135,6 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
 			switch (*fmt) {
 			case 'S':
 			case 's':
-			case 'F':
-			case 'f':
 			case 'x':
 			case 'K':
 			case 'e':
Signature · 1 line
2.29.2
Reviewed-by on v1 1/1
#1 lore raw

Hi Rasmus,

Quoted 17 lines · Rasmus Villemoes

Commit 9af7706492f9 ("lib/vsprintf: Remove support for %pF and %pf in favour of %pS and %ps") removed support for %pF and %pf, and correctly removed the handling of those cases in vbin_printf(). However, the corresponding cases in bstr_printf() were left behind.

In the same series, %pf was re-purposed for dealing with fwnodes (3bd32d6a2ee6, "lib/vsprintf: Add %pfw conversion specifier for printing fwnode names").

So should anyone use %pf with the binary printf routines, vbin_printf() would (correctly, as it involves dereferencing the pointer) do the string formatting to the u32 array, but bstr_printf() would not copy the string from the u32 array, but instead interpret the first sizeof(void*) bytes of the formatted string as a pointer - which generally won't end well (also, all subsequent get_args would be out of sync).

Quoted 3 lines
Fixes 9af7706492f9 ("lib/vsprintf: Remove support for %pF and %pf in favour of %pS and %ps")

Thanks!

Quoted 20 lines
---
 lib/vsprintf.c | 2 --
 1 file changed, 2 deletions(-)
lib/vsprintf.c +0 -2
index 41ddc353ebb8..39ef2e314da5 100644
@@ -3135,8 +3135,6 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
 			switch (*fmt) {
 			case 'S':
 			case 's':
-			case 'F':
-			case 'f':
 			case 'x':
 			case 'K':
 			case 'e':
Signature · 1 line
2.29.2
Signature · 1 line
Sakari Ailus
maintainer
#2 lore raw
In reply to Rasmus Villemoes
Quoted 17 lines · Rasmus Villemoes

Commit 9af7706492f9 ("lib/vsprintf: Remove support for %pF and %pf in favour of %pS and %ps") removed support for %pF and %pf, and correctly removed the handling of those cases in vbin_printf(). However, the corresponding cases in bstr_printf() were left behind.

In the same series, %pf was re-purposed for dealing with fwnodes (3bd32d6a2ee6, "lib/vsprintf: Add %pfw conversion specifier for printing fwnode names").

So should anyone use %pf with the binary printf routines, vbin_printf() would (correctly, as it involves dereferencing the pointer) do the string formatting to the u32 array, but bstr_printf() would not copy the string from the u32 array, but instead interpret the first sizeof(void*) bytes of the formatted string as a pointer - which generally won't end well (also, all subsequent get_args would be out of sync).

Quoted 3 lines
Fixes 9af7706492f9 ("lib/vsprintf: Remove support for %pF and %pf in favour of %pS and %ps")

Great catch!

The patch is pushed in printk/linux.git, branch for-5.13 now.

I did it quickly because the merge window will likely be opened next week and this should get in.

Best Regards,
Petr

maintainer Reviewed-by on v1 1/1
#3 lore raw
In reply to Rasmus Villemoes
Quoted 17 lines · On Fri, 23 Apr 2021 11:45:29 +0200 Rasmus Villemoes <[email protected]>…

Commit 9af7706492f9 ("lib/vsprintf: Remove support for %pF and %pf in favour of %pS and %ps") removed support for %pF and %pf, and correctly removed the handling of those cases in vbin_printf(). However, the corresponding cases in bstr_printf() were left behind.

In the same series, %pf was re-purposed for dealing with fwnodes (3bd32d6a2ee6, "lib/vsprintf: Add %pfw conversion specifier for printing fwnode names").

So should anyone use %pf with the binary printf routines, vbin_printf() would (correctly, as it involves dereferencing the pointer) do the string formatting to the u32 array, but bstr_printf() would not copy the string from the u32 array, but instead interpret the first sizeof(void*) bytes of the formatted string as a pointer - which generally won't end well (also, all subsequent get_args would be out of sync).

Quoted 4 lines
Fixes 9af7706492f9 ("lib/vsprintf: Remove support for %pF and %pf in favour of %pS and %ps")

---

Thanks!

-- Steve

Quoted 16 lines
 lib/vsprintf.c | 2 --
 1 file changed, 2 deletions(-)
lib/vsprintf.c +0 -2
index 41ddc353ebb8..39ef2e314da5 100644
@@ -3135,8 +3135,6 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
 			switch (*fmt) {
 			case 'S':
 			case 's':
-			case 'F':
-			case 'f':
 			case 'x':
 			case 'K':
 			case 'e':