diff mbox series

[FFmpeg-devel,2/2] lavd/opengl_enc: check strings before parsing them.

Message ID 20200217125000.13528-2-george@nsup.org
State Accepted
Headers show
Series [FFmpeg-devel,1/2] lavd/opengl_enc: use proper context for logging. | expand

Checks

Context Check Description
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Nicolas George Feb. 17, 2020, 12:50 p.m. UTC
Fix a segfault if OpenGL was not initialized before calling
write_header().

Signed-off-by: Nicolas George <george@nsup.org>
---
 libavdevice/opengl_enc.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Mark Thompson Feb. 19, 2020, 10:44 p.m. UTC | #1
On 17/02/2020 12:50, Nicolas George wrote:
> Fix a segfault if OpenGL was not initialized before calling
> write_header().
> 
> Signed-off-by: Nicolas George <george@nsup.org>
> ---
>  libavdevice/opengl_enc.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/libavdevice/opengl_enc.c b/libavdevice/opengl_enc.c
> index fa94345a7c..3d60f7d068 100644
> --- a/libavdevice/opengl_enc.c
> +++ b/libavdevice/opengl_enc.c
> @@ -588,6 +588,10 @@ static av_cold int opengl_read_limits(AVFormatContext *h)
>  
>      version = glGetString(GL_VERSION);
>      extensions = glGetString(GL_EXTENSIONS);
> +    if (!version || !extensions) {
> +        av_log(h, AV_LOG_ERROR, "OpenGL not available\n");

I'd make the error more direct, since this is to be seen by a developer messing up - it's that there is no OpenGL context current on the calling thread.

> +        return AVERROR(ENOSYS);> +    }
>  
>      av_log(h, AV_LOG_DEBUG, "OpenGL version: %s\n", version);
>      sscanf(version, "%d.%d", &major, &minor);
> 

Intent of patch LGTM.

Thanks,

- Mark
Nicolas George Feb. 20, 2020, 1:39 p.m. UTC | #2
Mark Thompson (12020-02-19):
> I'd make the error more direct, since this is to be seen by a
> developer messing up - it's that there is no OpenGL context current on
> the calling thread.

Thanks. I changed the message according to that and pushed both patches.

Regards,
diff mbox series

Patch

diff --git a/libavdevice/opengl_enc.c b/libavdevice/opengl_enc.c
index fa94345a7c..3d60f7d068 100644
--- a/libavdevice/opengl_enc.c
+++ b/libavdevice/opengl_enc.c
@@ -588,6 +588,10 @@  static av_cold int opengl_read_limits(AVFormatContext *h)
 
     version = glGetString(GL_VERSION);
     extensions = glGetString(GL_EXTENSIONS);
+    if (!version || !extensions) {
+        av_log(h, AV_LOG_ERROR, "OpenGL not available\n");
+        return AVERROR(ENOSYS);
+    }
 
     av_log(h, AV_LOG_DEBUG, "OpenGL version: %s\n", version);
     sscanf(version, "%d.%d", &major, &minor);