[PATCH i-g-t 4/7] lib/igt_kms: fix helper igt_get_dp_mst_connector_id

Kunal Joshi kunal1.joshi at intel.com
Wed Sep 25 18:29:41 UTC 2024


Use strdup() to create a copy of connector_path
before passing it to strtok(). This ensures the
original string remains unmodified, avoiding potential
bugs where the original path might be reused or
relied upon in other parts of the code.

v2: free the memory allocated by strdup (Imre)

Fixes: 0123456789ab ("lib/igt_kms: add helper for dp-mst connector id")
Signed-off-by: Kunal Joshi <kunal1.joshi at intel.com>
Reviewed-by: Imre Deak <imre.deak at intel.com>
---
 lib/igt_kms.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index 2d8a6f54c..ca5fc92cd 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -6630,11 +6630,12 @@ static int parse_path_connector(char *connector_path)
 {
 	int connector_id;
 	char *encoder;
+	char *connector_path_copy = strdup(connector_path);
 
-	encoder = strtok(connector_path, ":");
+	encoder = strtok(connector_path_copy, ":");
 	igt_assert_f(!strcmp(encoder, "mst"), "PATH connector property expected to have 'mst'\n");
-
 	connector_id = atoi(strtok(NULL, "-"));
+	free(connector_path_copy);
 
 	return connector_id;
 }
@@ -6648,13 +6649,11 @@ static int parse_path_connector(char *connector_path)
 int igt_get_dp_mst_connector_id(igt_output_t *output)
 {
 	int connector_id;
-	char *connector_path;
 
 	if (!igt_check_output_is_dp_mst(output))
 		return -EINVAL;
 
-	connector_path = output->config.connector_path;
-	connector_id = parse_path_connector(connector_path);
+	connector_id = parse_path_connector(output->config.connector_path);
 
 	return connector_id;
 }
-- 
2.43.0



More information about the igt-dev mailing list