[rtmpdump] [PATCH] Get rid of declarations after statements in limelight authentication

Howard Chu hyc at highlandsun.com
Tue Oct 30 19:26:53 CET 2012


This patch is also obsoleted by my last commit.

General rules -
   don't calculate at runtime what is already known at compile time.
   avoid malloc'ing things that are going to be freed immediately.

Martin Storsjo wrote:
> ---
>   librtmp/rtmp.c |   27 +++++++++++++++------------
>   1 file changed, 15 insertions(+), 12 deletions(-)
>
> diff --git a/librtmp/rtmp.c b/librtmp/rtmp.c
> index 3994d42..fbfbc50 100644
> --- a/librtmp/rtmp.c
> +++ b/librtmp/rtmp.c
> @@ -2695,6 +2695,12 @@ PublisherAuth(RTMP *r, AVal *description)
>             char *user = NULL;
>             char *nonce = NULL;
>
> +          const char *authmod, *realm, *method, *qop;
> +          char *tmpbuf, *hash1, *hash2, *hash3, *apptmp, *qpos;
> +          int nc;
> +          char nchex[9];
> +          char cnonce[9];
> +
>             ptr = orig_ptr = strdup(token_in);
>             /* Extract parameters (we need user and nonce) */
>             while (ptr)
> @@ -2725,19 +2731,16 @@ PublisherAuth(RTMP *r, AVal *description)
>              *    http://en.wikipedia.org/wiki/Digest_access_authentication
>              */
>
> -          const char *authmod = "llnw";
> -          const char *realm = "live";
> -          const char *method = "publish";
> -          const char *qop = "auth";
> -          char *tmpbuf;
> +          authmod = "llnw";
> +          realm = "live";
> +          method = "publish";
> +          qop = "auth";
>
>             /* nc = 1..connection count (or rather, number of times cnonce has been reused) */
> -          int nc = 1;
> +          nc = 1;
>             /* nchex = hexenc(nc) (8 hex digits according to RFC 2617) */
> -          char nchex[9];
>             sprintf(nchex, "%08x", nc);
>             /* cnonce = hexenc(4 random bytes) (initialized on first connection) */
> -          char cnonce[9];
>             srand( time(NULL) ); // FIXME: a lib shouldn't call srand()
>             sprintf(cnonce, "%08x", rand());
>
> @@ -2748,11 +2751,11 @@ PublisherAuth(RTMP *r, AVal *description)
>             RTMP_Log(RTMP_LOGDEBUG, "%s, md5(%s) =>", __FUNCTION__, tmpbuf);
>             RTMP_LogHexString(RTMP_LOGDEBUG, md5sum_val, MD5_DIGEST_LENGTH);
>             free(tmpbuf);
> -          char *hash1 = hexenc(md5sum_val, MD5_DIGEST_LENGTH);
> +          hash1 = hexenc(md5sum_val, MD5_DIGEST_LENGTH);
>
>             /* hash2 = hexenc(md5(method + ":/" + app + "/" + appInstance)) */
>             /* Extract appname + appinstance without query parameters */
> -          char *apptmp = malloc(r->Link.app.av_len + 1), *qpos;
> +          apptmp = malloc(r->Link.app.av_len + 1);
>             memcpy(apptmp, r->Link.app.av_val, r->Link.app.av_len);
>             apptmp[r->Link.app.av_len] = '\0';
>             if((qpos = strchr(apptmp, '?')))
> @@ -2764,7 +2767,7 @@ PublisherAuth(RTMP *r, AVal *description)
>             RTMP_Log(RTMP_LOGDEBUG, "%s, md5(%s) =>", __FUNCTION__, tmpbuf);
>             RTMP_LogHexString(RTMP_LOGDEBUG, md5sum_val, MD5_DIGEST_LENGTH);
>             free(tmpbuf);
> -          char *hash2 = hexenc(md5sum_val, MD5_DIGEST_LENGTH);
> +          hash2 = hexenc(md5sum_val, MD5_DIGEST_LENGTH);
>
>             free(apptmp);
>
> @@ -2775,7 +2778,7 @@ PublisherAuth(RTMP *r, AVal *description)
>             RTMP_Log(RTMP_LOGDEBUG, "%s, md5(%s) =>", __FUNCTION__, tmpbuf);
>             RTMP_LogHexString(RTMP_LOGDEBUG, md5sum_val, MD5_DIGEST_LENGTH);
>             free(tmpbuf);
> -          char *hash3 = hexenc(md5sum_val, MD5_DIGEST_LENGTH);
> +          hash3 = hexenc(md5sum_val, MD5_DIGEST_LENGTH);
>
>             /* pubToken = &authmod=<authmod>&user=<username>&nonce=<nonce>&cnonce=<cnonce>&nc=<nchex>&response=<hash3> */
>             /* Append nonces and response to query string which already contains
>



More information about the rtmpdump mailing list