Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] avutil/cuda_check: add error handling to ff_cuda_check
@ 2025-12-11  2:51 Chris Boyd via ffmpeg-devel
  2025-12-11 17:52 ` [FFmpeg-devel] " Timo Rothenpieler via ffmpeg-devel
  0 siblings, 1 reply; 2+ messages in thread
From: Chris Boyd via ffmpeg-devel @ 2025-12-11  2:51 UTC (permalink / raw)
  To: 'ffmpeg-devel@ffmpeg.org'; +Cc: Chris Boyd

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 <cboyd@valvesoftware.com>
---
 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 -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-12-11 17:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-11  2:51 [FFmpeg-devel] [PATCH] avutil/cuda_check: add error handling to ff_cuda_check Chris Boyd via ffmpeg-devel
2025-12-11 17:52 ` [FFmpeg-devel] " Timo Rothenpieler via ffmpeg-devel

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git