[libav-devel] [PATCH 2/2] rtmp: check malloc calls

Diego Biurrun diego at biurrun.de
Tue May 22 18:28:54 CEST 2012


On Tue, May 22, 2012 at 05:28:17PM +0200, Samuel Pitoiset wrote:
> ---
>  libavformat/rtmpproto.c |   73 ++++++++++++++++++++++++++++++++++++++---------
>  1 file changed, 59 insertions(+), 14 deletions(-)
> 
> diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c
> index 4c46a1d..250a3f3 100644
> --- a/libavformat/rtmpproto.c
> +++ b/libavformat/rtmpproto.c
> @@ -497,7 +497,7 @@ static int gen_bytes_read(URLContext *s, RTMPContext *rt, uint32_t ts)
> -static void rtmp_calc_digest(const uint8_t *src, int len, int gap,
> +static int rtmp_calc_digest(const uint8_t *src, int len, int gap,
>                               const uint8_t *key, int keylen, uint8_t *dst)

Please fix the indentation of related lines.

> @@ -545,14 +549,18 @@ static void rtmp_calc_digest(const uint8_t *src, int len, int gap,
>  
> -    rtmp_calc_digest(buf, RTMP_HANDSHAKE_PACKET_SIZE, digest_pos,
> +    ret = rtmp_calc_digest(buf, RTMP_HANDSHAKE_PACKET_SIZE, digest_pos,
>                       rtmp_player_key, PLAYER_KEY_OPEN_PART_LEN,
>                       buf + digest_pos);

same, more below

> @@ -610,17 +623,21 @@ static int rtmp_handshake(URLContext *s, RTMPContext *rt)
>  
>      ffurl_write(rt->stream, tosend, RTMP_HANDSHAKE_PACKET_SIZE + 1);
>      i = ffurl_read_complete(rt->stream, serverdata, RTMP_HANDSHAKE_PACKET_SIZE + 1);
>      if (i != RTMP_HANDSHAKE_PACKET_SIZE + 1) {
>          av_log(s, AV_LOG_ERROR, "Cannot read RTMP handshake response\n");
> -        return -1;
> +        return AVERROR(EIO);
>      }
>      i = ffurl_read_complete(rt->stream, clientdata, RTMP_HANDSHAKE_PACKET_SIZE);
>      if (i != RTMP_HANDSHAKE_PACKET_SIZE) {
>          av_log(s, AV_LOG_ERROR, "Cannot read RTMP handshake response\n");
> -        return -1;
> +        return AVERROR(EIO);
>      }

This does not match the log message.  If you don't split out such changes,
at least mention them in the log message.

> @@ -628,33 +645,54 @@ static int rtmp_handshake(URLContext *s, RTMPContext *rt)
>          if (!server_pos) {
>              server_pos = rtmp_validate_digest(serverdata + 1, 8);
> +            if (server_pos < 0) {
> +                /* out of memory */
> +                return server_pos;
> +            }
> +
>              if (!server_pos) {
>                  av_log(s, AV_LOG_ERROR, "Server response validating failed\n");
> -                return -1;
> +                return AVERROR(EIO);
>              }
>          }

The error handling feels somewhat redundant now.

Diego


More information about the libav-devel mailing list