Mercurial > hg > nginx-quic
comparison src/mail/ngx_mail_imap_handler.c @ 8462:ccdf83bee8c1
Mail: fixed backslash handling in IMAP literals.
Previously, s->backslash was set if any of the arguments was a quoted
string with a backslash character. After successful command parsing
this resulted in all arguments being filtered to remove backslashes.
This is, however, incorrect, as backslashes should not be removed from
IMAP literals. For example:
S: * OK IMAP4 ready
C: a01 login {9}
S: + OK
C: user\name "pass\"word"
S: * BAD internal server error
resulted in "Auth-User: username" instead of "Auth-User: user\name"
as it should.
Fix is to apply backslash filtering on per-argument basis during parsing.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Wed, 19 May 2021 03:13:23 +0300 |
parents | da0a85e91587 |
children | b38728495e1a |
comparison
equal
deleted
inserted
replaced
8461:379d461eccf4 | 8462:ccdf83bee8c1 |
---|---|
99 | 99 |
100 | 100 |
101 void | 101 void |
102 ngx_mail_imap_auth_state(ngx_event_t *rev) | 102 ngx_mail_imap_auth_state(ngx_event_t *rev) |
103 { | 103 { |
104 u_char *p, *dst, *src, *end; | 104 u_char *p; |
105 ngx_str_t *arg; | |
106 ngx_int_t rc; | 105 ngx_int_t rc; |
107 ngx_uint_t tag, i; | 106 ngx_uint_t tag; |
108 ngx_connection_t *c; | 107 ngx_connection_t *c; |
109 ngx_mail_session_t *s; | 108 ngx_mail_session_t *s; |
110 | 109 |
111 c = rev->data; | 110 c = rev->data; |
112 s = c->data; | 111 s = c->data; |
155 | 154 |
156 if (rc == NGX_OK) { | 155 if (rc == NGX_OK) { |
157 | 156 |
158 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0, "imap auth command: %i", | 157 ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0, "imap auth command: %i", |
159 s->command); | 158 s->command); |
160 | |
161 if (s->backslash) { | |
162 | |
163 arg = s->args.elts; | |
164 | |
165 for (i = 0; i < s->args.nelts; i++) { | |
166 dst = arg[i].data; | |
167 end = dst + arg[i].len; | |
168 | |
169 for (src = dst; src < end; dst++) { | |
170 *dst = *src; | |
171 if (*src++ == '\\') { | |
172 *dst = *src++; | |
173 } | |
174 } | |
175 | |
176 arg[i].len = dst - arg[i].data; | |
177 } | |
178 | |
179 s->backslash = 0; | |
180 } | |
181 | 159 |
182 switch (s->mail_state) { | 160 switch (s->mail_state) { |
183 | 161 |
184 case ngx_imap_start: | 162 case ngx_imap_start: |
185 | 163 |