Skip to content

Commit b89c1ac

Browse files
committed
[fix] fixed potential length overflow of rtmp_socket_dir.
The size of member `sun_path` in structure `sockaddr_un` is typically 108, so the length of `rtmp_socket_dir` must be limited to fit it.
1 parent 196c89c commit b89c1ac

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

ngx_rtmp_auto_push_module.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ static ngx_rtmp_delete_stream_pt next_delete_stream;
1717

1818
static ngx_int_t ngx_rtmp_auto_push_init_process(ngx_cycle_t *cycle);
1919
static void ngx_rtmp_auto_push_exit_process(ngx_cycle_t *cycle);
20-
static void * ngx_rtmp_auto_push_create_conf(ngx_cycle_t *cf);
21-
static char * ngx_rtmp_auto_push_init_conf(ngx_cycle_t *cycle, void *conf);
20+
static void *ngx_rtmp_auto_push_create_conf(ngx_cycle_t *cf);
21+
static char *ngx_rtmp_auto_push_init_conf(ngx_cycle_t *cycle, void *conf);
2222
#if (NGX_HAVE_UNIX_DOMAIN)
2323
static ngx_int_t ngx_rtmp_auto_push_publish(ngx_rtmp_session_t *s,
2424
ngx_rtmp_publish_t *v);
@@ -434,6 +434,11 @@ ngx_rtmp_auto_push_create_conf(ngx_cycle_t *cycle)
434434
static char *
435435
ngx_rtmp_auto_push_init_conf(ngx_cycle_t *cycle, void *conf)
436436
{
437+
#if (NGX_HAVE_UNIX_DOMAIN)
438+
struct sockaddr_un saun;
439+
size_t len;
440+
u_char *p;
441+
#endif
437442
ngx_rtmp_auto_push_conf_t *apcf = conf;
438443

439444
ngx_conf_init_value(apcf->auto_push, 0);
@@ -442,6 +447,24 @@ ngx_rtmp_auto_push_init_conf(ngx_cycle_t *cycle, void *conf)
442447
if (apcf->socket_dir.len == 0) {
443448
ngx_str_set(&apcf->socket_dir, "/tmp");
444449
}
450+
#if (NGX_HAVE_UNIX_DOMAIN)
451+
else {
452+
p = apcf->socket_dir.data + apcf->socket_dir.len - 1;
453+
454+
while ((p > apcf->socket_dir.data) && (*p == '/' || *p == '\\')) {
455+
*p-- = '\0';
456+
}
457+
458+
apcf->socket_dir.len = p + 1 - apcf->socket_dir.data;
459+
len = apcf->socket_dir.len + sizeof(NGX_RTMP_AUTO_PUSH_SOCKNAME);
460+
461+
if (len + 1 + NGX_INT_T_LEN >= sizeof(saun.sun_path)) {
462+
ngx_log_error(NGX_LOG_EMERG, cycle->log, 0,
463+
"auto_push: too long \"rtmp_socket_dir\" directive");
464+
return NGX_CONF_ERROR;
465+
}
466+
}
467+
#endif
445468

446469
return NGX_CONF_OK;
447470
}

0 commit comments

Comments
 (0)