Add variable initialization and return value checks when calling
cuGetErrorName() and cuGetErrorString(). Although the documentation for
these methods seems to imply that the provided char* will be set to NULL
on failure, we have seen crashes when logging these strings with
uninitialized memory on machines that have Nvidia drivers installed but
no longer have an Nvidia GPU.

Signed-off-by: Christopher Boyd <[email protected]>
---
 libavutil/cuda_check.h | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/libavutil/cuda_check.h b/libavutil/cuda_check.h
index f5a9234eaf..763009ce92 100644
--- a/libavutil/cuda_check.h
+++ b/libavutil/cuda_check.h
@@ -33,16 +33,22 @@ static inline int ff_cuda_check(void *avctx,
                                 void *cuGetErrorName_fn, void 
*cuGetErrorString_fn,
                                 CUresult err, const char *func)
 {
-    const char *err_name;
-    const char *err_string;
+    const char *err_name = NULL;
+    const char *err_string = NULL;
+    CUresult get_err;
 
     av_log(avctx, AV_LOG_TRACE, "Calling %s\n", func);
 
     if (err == CUDA_SUCCESS)
         return 0;
 
-    ((cuda_check_GetErrorName *)cuGetErrorName_fn)(err, &err_name);
-    ((cuda_check_GetErrorString *)cuGetErrorString_fn)(err, &err_string);
+    get_err = ((cuda_check_GetErrorName *)cuGetErrorName_fn)(err, &err_name);
+    if (get_err != CUDA_SUCCESS)
+        err_name = NULL;
+
+    get_err = ((cuda_check_GetErrorString *)cuGetErrorString_fn)(err, 
&err_string);
+    if (get_err != CUDA_SUCCESS)
+        err_string = NULL;
 
     av_log(avctx, AV_LOG_ERROR, "%s failed", func);
     if (err_name && err_string)
-- 
2.43.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to