Mercurial > hg > nginx
comparison src/core/ngx_conf_file.c @ 5316:12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
If a relative path is set by variables, then the ngx_conf_full_name()
function was called while processing requests, which causes allocations
from the cycle pool.
A new function that takes pool as an argument was introduced.
author | Valentin Bartenev <vbart@nginx.com> |
---|---|
date | Tue, 06 Aug 2013 19:58:40 +0400 |
parents | ea41bba49e8a |
children | f1a91825730a |
comparison
equal
deleted
inserted
replaced
5315:31932b5464f0 | 5316:12dd27b74117 |
---|---|
10 | 10 |
11 #define NGX_CONF_BUFFER 4096 | 11 #define NGX_CONF_BUFFER 4096 |
12 | 12 |
13 static ngx_int_t ngx_conf_handler(ngx_conf_t *cf, ngx_int_t last); | 13 static ngx_int_t ngx_conf_handler(ngx_conf_t *cf, ngx_int_t last); |
14 static ngx_int_t ngx_conf_read_token(ngx_conf_t *cf); | 14 static ngx_int_t ngx_conf_read_token(ngx_conf_t *cf); |
15 static ngx_int_t ngx_conf_test_full_name(ngx_str_t *name); | |
16 static void ngx_conf_flush_files(ngx_cycle_t *cycle); | 15 static void ngx_conf_flush_files(ngx_cycle_t *cycle); |
17 | 16 |
18 | 17 |
19 static ngx_command_t ngx_conf_commands[] = { | 18 static ngx_command_t ngx_conf_commands[] = { |
20 | 19 |
799 | 798 |
800 | 799 |
801 ngx_int_t | 800 ngx_int_t |
802 ngx_conf_full_name(ngx_cycle_t *cycle, ngx_str_t *name, ngx_uint_t conf_prefix) | 801 ngx_conf_full_name(ngx_cycle_t *cycle, ngx_str_t *name, ngx_uint_t conf_prefix) |
803 { | 802 { |
804 size_t len; | 803 return ngx_get_full_name(cycle->pool, |
805 u_char *p, *n, *prefix; | 804 conf_prefix ? &cycle->conf_prefix: |
806 ngx_int_t rc; | 805 &cycle->prefix, |
807 | 806 name); |
808 rc = ngx_conf_test_full_name(name); | |
809 | |
810 if (rc == NGX_OK) { | |
811 return rc; | |
812 } | |
813 | |
814 if (conf_prefix) { | |
815 len = cycle->conf_prefix.len; | |
816 prefix = cycle->conf_prefix.data; | |
817 | |
818 } else { | |
819 len = cycle->prefix.len; | |
820 prefix = cycle->prefix.data; | |
821 } | |
822 | |
823 #if (NGX_WIN32) | |
824 | |
825 if (rc == 2) { | |
826 len = rc; | |
827 } | |
828 | |
829 #endif | |
830 | |
831 n = ngx_pnalloc(cycle->pool, len + name->len + 1); | |
832 if (n == NULL) { | |
833 return NGX_ERROR; | |
834 } | |
835 | |
836 p = ngx_cpymem(n, prefix, len); | |
837 ngx_cpystrn(p, name->data, name->len + 1); | |
838 | |
839 name->len += len; | |
840 name->data = n; | |
841 | |
842 return NGX_OK; | |
843 } | |
844 | |
845 | |
846 static ngx_int_t | |
847 ngx_conf_test_full_name(ngx_str_t *name) | |
848 { | |
849 #if (NGX_WIN32) | |
850 u_char c0, c1; | |
851 | |
852 c0 = name->data[0]; | |
853 | |
854 if (name->len < 2) { | |
855 if (c0 == '/') { | |
856 return 2; | |
857 } | |
858 | |
859 return NGX_DECLINED; | |
860 } | |
861 | |
862 c1 = name->data[1]; | |
863 | |
864 if (c1 == ':') { | |
865 c0 |= 0x20; | |
866 | |
867 if ((c0 >= 'a' && c0 <= 'z')) { | |
868 return NGX_OK; | |
869 } | |
870 | |
871 return NGX_DECLINED; | |
872 } | |
873 | |
874 if (c1 == '/') { | |
875 return NGX_OK; | |
876 } | |
877 | |
878 if (c0 == '/') { | |
879 return 2; | |
880 } | |
881 | |
882 return NGX_DECLINED; | |
883 | |
884 #else | |
885 | |
886 if (name->data[0] == '/') { | |
887 return NGX_OK; | |
888 } | |
889 | |
890 return NGX_DECLINED; | |
891 | |
892 #endif | |
893 } | 807 } |
894 | 808 |
895 | 809 |
896 ngx_open_file_t * | 810 ngx_open_file_t * |
897 ngx_conf_open_file(ngx_cycle_t *cycle, ngx_str_t *name) | 811 ngx_conf_open_file(ngx_cycle_t *cycle, ngx_str_t *name) |