[PATCH i-g-t v14 02/11] tests/intel/*_intel_bb: handle base64 encode fail

Jeevaka Prabu Badrappan jeevaka.badrappan at intel.com
Tue Jun 3 19:23:45 UTC 2025


g_base64_encode function returns a newly allocated string containing
the Base64 encoded data. Failure case is not handled.

When g_base64_encode function fails, set the outsize to 0 to address
null pointer dereference crash.

Signed-off-by: Jeevaka Prabu Badrappan <jeevaka.badrappan at intel.com>
Reviewed-by: Kamil Konieczny <kamil.konieczny at linux.intel.com>
---
 tests/intel/api_intel_bb.c | 3 ++-
 tests/intel/xe_intel_bb.c  | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/tests/intel/api_intel_bb.c b/tests/intel/api_intel_bb.c
index 4a1c9be91..1910690cd 100644
--- a/tests/intel/api_intel_bb.c
+++ b/tests/intel/api_intel_bb.c
@@ -944,7 +944,8 @@ static int dump_base64(const char *name, struct intel_buf *buf)
 
 		igt_info("--- %s ---\n", name);
 		pos = str = g_base64_encode(destbuf, outsize);
-		outsize = strlen(str);
+		outsize = str ? strlen(str) : 0;
+
 		while (pos) {
 			char line[LINELEN + 1];
 			int to_copy = min(LINELEN, outsize);
diff --git a/tests/intel/xe_intel_bb.c b/tests/intel/xe_intel_bb.c
index d8bd7b519..f0cc17b1a 100644
--- a/tests/intel/xe_intel_bb.c
+++ b/tests/intel/xe_intel_bb.c
@@ -595,7 +595,8 @@ static int dump_base64(const char *name, struct intel_buf *buf)
 
 		igt_info("--- %s ---\n", name);
 		pos = str = g_base64_encode(destbuf, outsize);
-		outsize = strlen(str);
+		outsize = str ? strlen(str) : 0;
+
 		while (pos) {
 			char line[LINELEN + 1];
 			int to_copy = min(LINELEN, outsize);
-- 
2.49.0



More information about the igt-dev mailing list