Merge remote branch 'origin/safe-amf-parser' into video-on-demand

This commit is contained in:
Roman Arutyunyan 2012-07-06 12:38:24 +04:00
commit 28e5b05e01
3 changed files with 17 additions and 9 deletions

View file

@ -61,9 +61,10 @@ ngx_rtmp_amf_debug(const char* op, ngx_log_t *log, u_char *p, size_t n)
static ngx_int_t static ngx_int_t
ngx_rtmp_amf_get(ngx_rtmp_amf_ctx_t *ctx, void *p, size_t n) ngx_rtmp_amf_get(ngx_rtmp_amf_ctx_t *ctx, void *p, size_t n)
{ {
ngx_buf_t *b;
size_t size; size_t size;
ngx_chain_t *l; ngx_chain_t *l;
size_t offset;
u_char *pos, *last;
#ifdef NGX_DEBUG #ifdef NGX_DEBUG
void *op = p; void *op = p;
size_t on = n; size_t on = n;
@ -72,16 +73,16 @@ ngx_rtmp_amf_get(ngx_rtmp_amf_ctx_t *ctx, void *p, size_t n)
if (!n) if (!n)
return NGX_OK; return NGX_OK;
for(l = ctx->link; l; l = l->next) { for(l = ctx->link, offset = ctx->offset; l; l = l->next, offset = 0) {
b = l->buf; pos = l->buf->pos + offset;
last = l->buf->last;
if (b->last >= n + b->pos) { if (last >= pos + n) {
if (p) { if (p) {
p = ngx_cpymem(p, b->pos, n); p = ngx_cpymem(p, pos, n);
} }
b->pos += n; ctx->offset = offset + n;
ctx->link = l; ctx->link = l;
#ifdef NGX_DEBUG #ifdef NGX_DEBUG
@ -91,10 +92,10 @@ ngx_rtmp_amf_get(ngx_rtmp_amf_ctx_t *ctx, void *p, size_t n)
return NGX_OK; return NGX_OK;
} }
size = b->last - b->pos; size = last - pos;
if (p) { if (p) {
p = ngx_cpymem(p, b->pos, size); p = ngx_cpymem(p, pos, size);
} }
n -= size; n -= size;

View file

@ -50,6 +50,7 @@ typedef ngx_chain_t * (*ngx_rtmp_amf_alloc_pt)(void *arg);
typedef struct { typedef struct {
ngx_chain_t *link, *first; ngx_chain_t *link, *first;
size_t offset;
ngx_rtmp_amf_alloc_pt alloc; ngx_rtmp_amf_alloc_pt alloc;
void *arg; void *arg;
ngx_log_t *log; ngx_log_t *log;

View file

@ -206,6 +206,7 @@ ngx_rtmp_amf_message_handler(ngx_rtmp_session_t *s,
cmcf = ngx_rtmp_get_module_main_conf(s, ngx_rtmp_core_module); cmcf = ngx_rtmp_get_module_main_conf(s, ngx_rtmp_core_module);
/* read AMF func name & transaction id */ /* read AMF func name & transaction id */
ngx_memzero(&act, sizeof(act));
act.link = in; act.link = in;
act.log = s->connection->log; act.log = s->connection->log;
memset(func, 0, sizeof(func)); memset(func, 0, sizeof(func));
@ -218,6 +219,10 @@ ngx_rtmp_amf_message_handler(ngx_rtmp_session_t *s,
return NGX_ERROR; return NGX_ERROR;
} }
/* skip name */
in = act.link;
in->buf->pos += act.offset;
len = ngx_strlen(func); len = ngx_strlen(func);
ch = ngx_hash_find(&cmcf->amf_hash, ch = ngx_hash_find(&cmcf->amf_hash,
@ -251,6 +256,7 @@ ngx_rtmp_receive_amf(ngx_rtmp_session_t *s, ngx_chain_t *in,
{ {
ngx_rtmp_amf_ctx_t act; ngx_rtmp_amf_ctx_t act;
ngx_memzero(&act, sizeof(act));
act.link = in; act.link = in;
act.log = s->connection->log; act.log = s->connection->log;