annotate src/stream/ngx_stream_script.h @ 7690:8253424d1aff

Added size check to ngx_http_alloc_large_header_buffer(). This ensures that copying won't write more than the buffer size even if the buffer comes from hc->free and it is smaller than the large client header buffer size in the virtual host configuration. This might happen if size of large client header buffers is different in name-based virtual hosts, similarly to the problem with number of buffers fixed in 6926:e662cbf1b932.
author Maxim Dounin <mdounin@mdounin.ru>
date Thu, 06 Aug 2020 05:02:22 +0300
parents b82162b8496a
children 3ab8e1e2f0f7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6607
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
1
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
2 /*
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
3 * Copyright (C) Igor Sysoev
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
4 * Copyright (C) Nginx, Inc.
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
5 */
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
6
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
7
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
8 #ifndef _NGX_STREAM_SCRIPT_H_INCLUDED_
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
9 #define _NGX_STREAM_SCRIPT_H_INCLUDED_
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
10
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
11
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
12 #include <ngx_config.h>
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
13 #include <ngx_core.h>
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
14 #include <ngx_stream.h>
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
15
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
16
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
17 typedef struct {
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
18 u_char *ip;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
19 u_char *pos;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
20 ngx_stream_variable_value_t *sp;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
21
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
22 ngx_str_t buf;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
23 ngx_str_t line;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
24
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
25 unsigned flushed:1;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
26 unsigned skip:1;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
27
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
28 ngx_stream_session_t *session;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
29 } ngx_stream_script_engine_t;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
30
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
31
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
32 typedef struct {
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
33 ngx_conf_t *cf;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
34 ngx_str_t *source;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
35
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
36 ngx_array_t **flushes;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
37 ngx_array_t **lengths;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
38 ngx_array_t **values;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
39
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
40 ngx_uint_t variables;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
41 ngx_uint_t ncaptures;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
42 ngx_uint_t size;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
43
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
44 void *main;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
45
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
46 unsigned complete_lengths:1;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
47 unsigned complete_values:1;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
48 unsigned zero:1;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
49 unsigned conf_prefix:1;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
50 unsigned root_prefix:1;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
51 } ngx_stream_script_compile_t;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
52
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
53
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
54 typedef struct {
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
55 ngx_str_t value;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
56 ngx_uint_t *flushes;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
57 void *lengths;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
58 void *values;
7503
b82162b8496a Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents: 6678
diff changeset
59
b82162b8496a Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents: 6678
diff changeset
60 union {
b82162b8496a Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents: 6678
diff changeset
61 size_t size;
b82162b8496a Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents: 6678
diff changeset
62 } u;
6607
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
63 } ngx_stream_complex_value_t;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
64
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
65
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
66 typedef struct {
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
67 ngx_conf_t *cf;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
68 ngx_str_t *value;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
69 ngx_stream_complex_value_t *complex_value;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
70
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
71 unsigned zero:1;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
72 unsigned conf_prefix:1;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
73 unsigned root_prefix:1;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
74 } ngx_stream_compile_complex_value_t;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
75
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
76
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
77 typedef void (*ngx_stream_script_code_pt) (ngx_stream_script_engine_t *e);
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
78 typedef size_t (*ngx_stream_script_len_code_pt) (ngx_stream_script_engine_t *e);
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
79
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
80
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
81 typedef struct {
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
82 ngx_stream_script_code_pt code;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
83 uintptr_t len;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
84 } ngx_stream_script_copy_code_t;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
85
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
86
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
87 typedef struct {
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
88 ngx_stream_script_code_pt code;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
89 uintptr_t index;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
90 } ngx_stream_script_var_code_t;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
91
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
92
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
93 typedef struct {
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
94 ngx_stream_script_code_pt code;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
95 uintptr_t n;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
96 } ngx_stream_script_copy_capture_code_t;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
97
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
98
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
99 typedef struct {
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
100 ngx_stream_script_code_pt code;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
101 uintptr_t conf_prefix;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
102 } ngx_stream_script_full_name_code_t;
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
103
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
104
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
105 void ngx_stream_script_flush_complex_value(ngx_stream_session_t *s,
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
106 ngx_stream_complex_value_t *val);
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
107 ngx_int_t ngx_stream_complex_value(ngx_stream_session_t *s,
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
108 ngx_stream_complex_value_t *val, ngx_str_t *value);
7503
b82162b8496a Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents: 6678
diff changeset
109 size_t ngx_stream_complex_value_size(ngx_stream_session_t *s,
b82162b8496a Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents: 6678
diff changeset
110 ngx_stream_complex_value_t *val, size_t default_value);
6607
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
111 ngx_int_t ngx_stream_compile_complex_value(
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
112 ngx_stream_compile_complex_value_t *ccv);
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
113 char *ngx_stream_set_complex_value_slot(ngx_conf_t *cf, ngx_command_t *cmd,
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
114 void *conf);
7503
b82162b8496a Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents: 6678
diff changeset
115 char *ngx_stream_set_complex_value_size_slot(ngx_conf_t *cf, ngx_command_t *cmd,
b82162b8496a Added ngx_http_set_complex_value_size_slot().
Ruslan Ermilov <ru@nginx.com>
parents: 6678
diff changeset
116 void *conf);
6607
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
117
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
118
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
119 ngx_uint_t ngx_stream_script_variables_count(ngx_str_t *value);
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
120 ngx_int_t ngx_stream_script_compile(ngx_stream_script_compile_t *sc);
6678
0125b151c9a5 Stream: log module.
Vladimir Homutov <vl@nginx.com>
parents: 6607
diff changeset
121 u_char *ngx_stream_script_run(ngx_stream_session_t *s, ngx_str_t *value,
0125b151c9a5 Stream: log module.
Vladimir Homutov <vl@nginx.com>
parents: 6607
diff changeset
122 void *code_lengths, size_t reserved, void *code_values);
0125b151c9a5 Stream: log module.
Vladimir Homutov <vl@nginx.com>
parents: 6607
diff changeset
123 void ngx_stream_script_flush_no_cacheable_variables(ngx_stream_session_t *s,
0125b151c9a5 Stream: log module.
Vladimir Homutov <vl@nginx.com>
parents: 6607
diff changeset
124 ngx_array_t *indices);
6607
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
125
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
126 void *ngx_stream_script_add_code(ngx_array_t *codes, size_t size, void *code);
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
127
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
128 size_t ngx_stream_script_copy_len_code(ngx_stream_script_engine_t *e);
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
129 void ngx_stream_script_copy_code(ngx_stream_script_engine_t *e);
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
130 size_t ngx_stream_script_copy_var_len_code(ngx_stream_script_engine_t *e);
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
131 void ngx_stream_script_copy_var_code(ngx_stream_script_engine_t *e);
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
132 size_t ngx_stream_script_copy_capture_len_code(ngx_stream_script_engine_t *e);
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
133 void ngx_stream_script_copy_capture_code(ngx_stream_script_engine_t *e);
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
134
c70b7f4537e1 Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
diff changeset
135 #endif /* _NGX_STREAM_SCRIPT_H_INCLUDED_ */