Skip to contentSkip to conversation

thermal: testing: reject missing command arguments

PATCH Applied Samuel Moelius 2 participants 2 messages Jun 5 – Jun 8 Thermal

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 thermal: testing: reject missing command arguments

The thermal testing debugfs command parser splits commands at ':' and passes the right-hand side to the command implementation. Commands such as deltz, tzaddtrip, tzreg, and tzunreg require a zone id, but writing one of those command names without ':' leaves the argument pointer NULL.

The command implementations parse the id with sscanf(arg, "%d", ...), so the missing-argument form dereferences a NULL pointer from the debugfs write path.

Reject missing arguments in tt_command_exec() before calling handlers that require an id.

Assisted-by Codex:gpt-5.5-cyber-preview
---
 drivers/thermal/testing/command.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/thermal/testing/command.c +12 -0
index 1159ecea57e7..fbf7ab9729b5 100644
@@ -116,18 +116,30 @@ static int tt_command_exec(int index, const char *arg)
 		break;
 
 	case TT_CMD_DELTZ:
+		if (!arg || !*arg)
+			return -EINVAL;
+
 		ret = tt_del_tz(arg);
 		break;
 
 	case TT_CMD_TZADDTRIP:
+		if (!arg || !*arg)
+			return -EINVAL;
+
 		ret = tt_zone_add_trip(arg);
 		break;
 
 	case TT_CMD_TZREG:
+		if (!arg || !*arg)
+			return -EINVAL;
+
 		ret = tt_zone_reg(arg);
 		break;
 
 	case TT_CMD_TZUNREG:
+		if (!arg || !*arg)
+			return -EINVAL;
+
 		ret = tt_zone_unreg(arg);
 		break;
 
Signature · 1 line
2.43.0
maintainer Applied
#1 lore raw
Quoted 45 lines · Samuel Moelius

The thermal testing debugfs command parser splits commands at ':' and passes the right-hand side to the command implementation. Commands such as deltz, tzaddtrip, tzreg, and tzunreg require a zone id, but writing one of those command names without ':' leaves the argument pointer NULL.

The command implementations parse the id with sscanf(arg, "%d", ...), so the missing-argument form dereferences a NULL pointer from the debugfs write path.

Reject missing arguments in tt_command_exec() before calling handlers that require an id.

Assisted-by Codex:gpt-5.5-cyber-preview
---
 drivers/thermal/testing/command.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/thermal/testing/command.c +9 -0
index 1159ecea57e7..fbf7ab9729b5 100644
@@ -116,18 +116,30 @@ static int tt_command_exec(int index, const char *arg)
                break;
 
        case TT_CMD_DELTZ:
+               if (!arg || !*arg)
+                       return -EINVAL;
+
                ret = tt_del_tz(arg);
                break;
 
        case TT_CMD_TZADDTRIP:
+               if (!arg || !*arg)
+                       return -EINVAL;
+
                ret = tt_zone_add_trip(arg);
                break;
 
        case TT_CMD_TZREG:
+               if (!arg || !*arg)
+                       return -EINVAL;
+
                ret = tt_zone_reg(arg);

drivers/thermal/testing/command.c static int tt_command_exec(int index, const char *arg)

Quoted 10 lines
drivers/thermal/testing/command.c +3 -1
                break;
 
        case TT_CMD_TZUNREG:
+               if (!arg || !*arg)
+                       return -EINVAL;
+
                ret = tt_zone_unreg(arg);
                break;
 
--

Applied as 7.2 material, thanks!