Mesa (main): intel: parse intel_measure environment without side effects

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Jun 16 03:30:00 UTC 2022


Module: Mesa
Branch: main
Commit: 3c53c6b247b32927bb18f5be526bdf11db13d745
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=3c53c6b247b32927bb18f5be526bdf11db13d745

Author: Mark Janes <markjanes at swizzler.org>
Date:   Tue May 24 12:16:27 2022 -0700

intel: parse intel_measure environment without side effects

If an application links agaist both iris and anv, they will clash when
parsing the INTEL_MEASURE environment variable.

Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16571>

---

 src/intel/common/intel_measure.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/src/intel/common/intel_measure.c b/src/intel/common/intel_measure.c
index d4abda129fc..aa933ad5a3d 100644
--- a/src/intel/common/intel_measure.c
+++ b/src/intel/common/intel_measure.c
@@ -64,8 +64,12 @@ intel_measure_init(struct intel_measure_device *device)
       if (!env)
          return;
 
+      char env_copy[1024];
+      strncpy(env_copy, env, 1024);
+      env_copy[1023] = '\0';
+
       config.file = stderr;
-      config.flags = parse_debug_string(env, debug_control);
+      config.flags = parse_debug_string(env_copy, debug_control);
       if (!config.flags)
          config.flags = INTEL_MEASURE_DRAW;
       config.enabled = true;
@@ -87,15 +91,15 @@ intel_measure_init(struct intel_measure_device *device)
       const int DEFAULT_BUFFER_SIZE = 64 * 1024;
       config.buffer_size = DEFAULT_BUFFER_SIZE;
 
-      const char *filename = strstr(env, "file=");
-      const char *start_frame_s = strstr(env, "start=");
-      const char *count_frame_s = strstr(env, "count=");
-      const char *control_path = strstr(env, "control=");
-      const char *interval_s = strstr(env, "interval=");
-      const char *batch_size_s = strstr(env, "batch_size=");
-      const char *buffer_size_s = strstr(env, "buffer_size=");
+      const char *filename = strstr(env_copy, "file=");
+      const char *start_frame_s = strstr(env_copy, "start=");
+      const char *count_frame_s = strstr(env_copy, "count=");
+      const char *control_path = strstr(env_copy, "control=");
+      const char *interval_s = strstr(env_copy, "interval=");
+      const char *batch_size_s = strstr(env_copy, "batch_size=");
+      const char *buffer_size_s = strstr(env_copy, "buffer_size=");
       while (true) {
-         char *sep = strrchr(env, ',');
+         char *sep = strrchr(env_copy, ',');
          if (sep == NULL)
             break;
          *sep = '\0';



More information about the mesa-commit mailing list