Skip to contentSkip to conversation

pinctrl: fix buffer size for pinctrl_generic_set_state_prefix()

PATCH In review John Keeping 4 participants 4 messages Sep 7, 2022 – Oct 11, 2022 Pin control

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pinctrl: fix buffer size for pinctrl_generic_set_state_prefix()

This buffer has the concatenated prefix and name written into it, so it must be large enough to cover both strings plus the terminating NUL.

Fixes 92c4a95ec7 ("pinctrl: Add new function pinctrl_generic_set_state_prefix()")
---
 drivers/pinctrl/pinctrl-generic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/pinctrl-generic.c +1 -1
index ec21d4ff83..8909b57810 100644
@@ -237,7 +237,7 @@ enum pinmux_subnode_type {
 static const char *alloc_name_with_prefix(const char *name, const char *prefix)
 {
 	if (prefix) {
-		char *name_with_prefix = malloc(strlen(prefix) + sizeof("pins"));
+		char *name_with_prefix = malloc(strlen(prefix) + strlen(name) + 1);
 		if (name_with_prefix)
 			sprintf(name_with_prefix, "%s%s", prefix, name);
 		return name_with_prefix;
Signature · 1 line
2.37.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 2 lines · On Wednesday 07 September 2022 12:11:42 John Keeping wrote:

This buffer has the concatenated prefix and name written into it, so it must be large enough to cover both strings plus the terminating NUL.

You are right. Not sure why I put there sizeof("pins") (maybe old version when name was only pins).

Quoted 22 lines
Fixes 92c4a95ec7 ("pinctrl: Add new function pinctrl_generic_set_state_prefix()")
---
 drivers/pinctrl/pinctrl-generic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/pinctrl-generic.c +1 -1
index ec21d4ff83..8909b57810 100644
@@ -237,7 +237,7 @@ enum pinmux_subnode_type {
 static const char *alloc_name_with_prefix(const char *name, const char *prefix)
 {
 	if (prefix) {
-		char *name_with_prefix = malloc(strlen(prefix) + sizeof("pins"));
+		char *name_with_prefix = malloc(strlen(prefix) + strlen(name) + 1);
 		if (name_with_prefix)
 			sprintf(name_with_prefix, "%s%s", prefix, name);
 		return name_with_prefix;
Signature · 1 line
2.37.3
Reviewed-by
#2 lore raw
Quoted 16 lines · Pali Rohár
Quoted 2 lines · On Wednesday 07 September 2022 12:11:42 John Keeping wrote:

This buffer has the concatenated prefix and name written into it, so it must be large enough to cover both strings plus the terminating NUL.

You are right. Not sure why I put there sizeof("pins") (maybe old version when name was only pins).

Quoted 6 lines
Fixes 92c4a95ec7 ("pinctrl: Add new function pinctrl_generic_set_state_prefix()")
---
 drivers/pinctrl/pinctrl-generic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
#3 lore raw
In reply to John Keeping
Quoted 7 lines · John Keeping

This buffer has the concatenated prefix and name written into it, so it must be large enough to cover both strings plus the terminating NUL.

Fixes 92c4a95ec7 ("pinctrl: Add new function pinctrl_generic_set_state_prefix()")

Applied to u-boot/master, thanks!

Signature · 1 line
Tom