comparison src/http/modules/perl/ngx_http_perl_module.c @ 5800:0570e42ffeed

Perl: NULL-terminate argument list. perl_parse() function expects argv/argc-style argument list, which according to the C standard must be NULL-terminated, that is: argv[argc] == NULL. This change fixes a crash (SIGSEGV) that could happen because of the buffer overrun during perl module initialization. Signed-off-by: Piotr Sikora <piotr@cloudflare.com>
author Piotr Sikora <piotr@cloudflare.com>
date Thu, 19 Jun 2014 04:16:36 -0700
parents 79b9101cecf4
children cb4a4e9bba8e
comparison
equal deleted inserted replaced
5799:b1f8285297a7 5800:0570e42ffeed
575 PL_exit_flags |= PERL_EXIT_DESTRUCT_END; 575 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
576 #endif 576 #endif
577 577
578 n = (pmcf->modules != NGX_CONF_UNSET_PTR) ? pmcf->modules->nelts * 2 : 0; 578 n = (pmcf->modules != NGX_CONF_UNSET_PTR) ? pmcf->modules->nelts * 2 : 0;
579 579
580 embedding = ngx_palloc(cf->pool, (4 + n) * sizeof(char *)); 580 embedding = ngx_palloc(cf->pool, (5 + n) * sizeof(char *));
581 if (embedding == NULL) { 581 if (embedding == NULL) {
582 goto fail; 582 goto fail;
583 } 583 }
584 584
585 embedding[0] = ""; 585 embedding[0] = "";
593 } 593 }
594 594
595 embedding[n++] = "-Mnginx"; 595 embedding[n++] = "-Mnginx";
596 embedding[n++] = "-e"; 596 embedding[n++] = "-e";
597 embedding[n++] = "0"; 597 embedding[n++] = "0";
598 embedding[n] = NULL;
598 599
599 n = perl_parse(perl, ngx_http_perl_xs_init, n, embedding, NULL); 600 n = perl_parse(perl, ngx_http_perl_xs_init, n, embedding, NULL);
600 601
601 if (n != 0) { 602 if (n != 0) {
602 ngx_log_error(NGX_LOG_ALERT, cf->log, 0, "perl_parse() failed: %d", n); 603 ngx_log_error(NGX_LOG_ALERT, cf->log, 0, "perl_parse() failed: %d", n);