diff mbox

[FFmpeg-devel] lavf/tls_gnutls: check for interrupt inside handshake loop

Message ID 20190816083845.2269-1-spaz16@wp.pl
State Accepted
Headers show

Commit Message

Błażej Szczygieł Aug. 16, 2019, 8:38 a.m. UTC
fixes #8080

Signed-off-by: Błażej Szczygieł <spaz16@wp.pl>
---
 libavformat/tls_gnutls.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Błażej Szczygieł Sept. 4, 2019, 6:36 p.m. UTC | #1
> fixes #8080
> 
> Signed-off-by: Błażej Szczygieł <spaz16@wp.pl>
> ---
>   libavformat/tls_gnutls.c | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git a/libavformat/tls_gnutls.c b/libavformat/tls_gnutls.c
> index f32bc2821b..f507b7d044 100644
> --- a/libavformat/tls_gnutls.c
> +++ b/libavformat/tls_gnutls.c
> @@ -184,6 +184,10 @@ static int tls_open(URLContext *h, const char *uri, int flags, AVDictionary **op
>       gnutls_priority_set_direct(p->session, "NORMAL", NULL);
>       do {
>           ret = gnutls_handshake(p->session);
> +        if (ff_check_interrupt(&h->interrupt_callback)) {
> +            ret = AVERROR_EXIT;
> +            goto fail;
> +        }
>           if (gnutls_error_is_fatal(ret)) {
>               ret = print_tls_error(h, ret);
>               goto fail;
> 

Ping?
This causes QMPlay2 unstable in some cases: 
https://github.com/zaps166/QMPlay2/issues/239
Michael Niedermayer Sept. 5, 2019, 3:01 p.m. UTC | #2
On Fri, Aug 16, 2019 at 10:38:46AM +0200, Błażej Szczygieł wrote:
> fixes #8080
> 
> Signed-off-by: Błażej Szczygieł <spaz16@wp.pl>
> ---
>  libavformat/tls_gnutls.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/libavformat/tls_gnutls.c b/libavformat/tls_gnutls.c
> index f32bc2821b..f507b7d044 100644
> --- a/libavformat/tls_gnutls.c
> +++ b/libavformat/tls_gnutls.c
> @@ -184,6 +184,10 @@ static int tls_open(URLContext *h, const char *uri, int flags, AVDictionary **op
>      gnutls_priority_set_direct(p->session, "NORMAL", NULL);
>      do {
>          ret = gnutls_handshake(p->session);
> +        if (ff_check_interrupt(&h->interrupt_callback)) {
> +            ret = AVERROR_EXIT;
> +            goto fail;
> +        }
>          if (gnutls_error_is_fatal(ret)) {
>              ret = print_tls_error(h, ret);
>              goto fail;

probably ok

Thanks

[...]
Jan Ekström April 20, 2020, 5:07 p.m. UTC | #3
On Thu, Sep 5, 2019 at 6:13 PM Michael Niedermayer
<michael@niedermayer.cc> wrote:
>
> On Fri, Aug 16, 2019 at 10:38:46AM +0200, Błażej Szczygieł wrote:
> > fixes #8080
> >
> > Signed-off-by: Błażej Szczygieł <spaz16@wp.pl>
> > ---
> >  libavformat/tls_gnutls.c | 4 ++++
> >  1 file changed, 4 insertions(+)
> >
> > diff --git a/libavformat/tls_gnutls.c b/libavformat/tls_gnutls.c
> > index f32bc2821b..f507b7d044 100644
> > --- a/libavformat/tls_gnutls.c
> > +++ b/libavformat/tls_gnutls.c
> > @@ -184,6 +184,10 @@ static int tls_open(URLContext *h, const char *uri, int flags, AVDictionary **op
> >      gnutls_priority_set_direct(p->session, "NORMAL", NULL);
> >      do {
> >          ret = gnutls_handshake(p->session);
> > +        if (ff_check_interrupt(&h->interrupt_callback)) {
> > +            ret = AVERROR_EXIT;
> > +            goto fail;
> > +        }
> >          if (gnutls_error_is_fatal(ret)) {
> >              ret = print_tls_error(h, ret);
> >              goto fail;
>
> probably ok
>
> Thanks
>

I've been meaning to look at this (and apply if it looks good), and
while the other TLS wrappers don't seem to have this (I guess their
handshake doesn't base on a loop?), it seems to almost match examples
found in f.ex. libavformat/network.c, libavformat/libzmq.c or
libavformat/libsrt.c.

The only point I notice is that usually the interrupt check is the
first thing done a loop, and unless people see any issues with it, I
will apply this patch with that change during today or so?

Best regards,
Jan
Jan Ekström April 21, 2020, 6:18 p.m. UTC | #4
On Mon, Apr 20, 2020 at 8:07 PM Jan Ekström <jeebjp@gmail.com> wrote:
>
> On Thu, Sep 5, 2019 at 6:13 PM Michael Niedermayer
> <michael@niedermayer.cc> wrote:
> >
> > On Fri, Aug 16, 2019 at 10:38:46AM +0200, Błażej Szczygieł wrote:
> > > fixes #8080
> > >
> > > Signed-off-by: Błażej Szczygieł <spaz16@wp.pl>
> > > ---
> > >  libavformat/tls_gnutls.c | 4 ++++
> > >  1 file changed, 4 insertions(+)
> > >
> > > diff --git a/libavformat/tls_gnutls.c b/libavformat/tls_gnutls.c
> > > index f32bc2821b..f507b7d044 100644
> > > --- a/libavformat/tls_gnutls.c
> > > +++ b/libavformat/tls_gnutls.c
> > > @@ -184,6 +184,10 @@ static int tls_open(URLContext *h, const char *uri, int flags, AVDictionary **op
> > >      gnutls_priority_set_direct(p->session, "NORMAL", NULL);
> > >      do {
> > >          ret = gnutls_handshake(p->session);
> > > +        if (ff_check_interrupt(&h->interrupt_callback)) {
> > > +            ret = AVERROR_EXIT;
> > > +            goto fail;
> > > +        }
> > >          if (gnutls_error_is_fatal(ret)) {
> > >              ret = print_tls_error(h, ret);
> > >              goto fail;
> >
> > probably ok
> >
> > Thanks
> >
>
> I've been meaning to look at this (and apply if it looks good), and
> while the other TLS wrappers don't seem to have this (I guess their
> handshake doesn't base on a loop?), it seems to almost match examples
> found in f.ex. libavformat/network.c, libavformat/libzmq.c or
> libavformat/libsrt.c.
>
> The only point I notice is that usually the interrupt check is the
> first thing done a loop, and unless people see any issues with it, I
> will apply this patch with that change during today or so?
>

Re-checked with Michael and pushed with the minor modification of
moving the interrupt handling to the beginning of the loop (as that is
how various similar I/O loops elsewhere in the code base seem to
handle these interrupts).

Jan
diff mbox

Patch

diff --git a/libavformat/tls_gnutls.c b/libavformat/tls_gnutls.c
index f32bc2821b..f507b7d044 100644
--- a/libavformat/tls_gnutls.c
+++ b/libavformat/tls_gnutls.c
@@ -184,6 +184,10 @@  static int tls_open(URLContext *h, const char *uri, int flags, AVDictionary **op
     gnutls_priority_set_direct(p->session, "NORMAL", NULL);
     do {
         ret = gnutls_handshake(p->session);
+        if (ff_check_interrupt(&h->interrupt_callback)) {
+            ret = AVERROR_EXIT;
+            goto fail;
+        }
         if (gnutls_error_is_fatal(ret)) {
             ret = print_tls_error(h, ret);
             goto fail;