comparison src/mail/ngx_mail_parse.c @ 7836:6a81d96d3733

Mail: fixed handling of invalid SMTP commands split between reads. Previously, if an invalid SMTP command was split between reads, nginx failed to wait for LF before returning an error, and interpreted the rest of the command received later as a separate command. The sw_invalid state in ngx_mail_smtp_parse_command(), introduced in 04e43d03e153, did not work, since ngx_mail_smtp_auth_state() clears s->state when returning an error due to NGX_MAIL_PARSE_INVALID_COMMAND. And not clearing s->state will introduce another problem: the rest of the command would trigger duplicate error when rest of the command is received. Fix is to return NGX_AGAIN from ngx_mail_smtp_parse_command() until full command is received.
author Maxim Dounin <mdounin@mdounin.ru>
date Wed, 19 May 2021 03:13:15 +0300
parents bcb107bb89cd
children ba8a8299b904
comparison
equal deleted inserted replaced
7835:c72d8839f427 7836:6a81d96d3733
844 /* skip invalid command till LF */ 844 /* skip invalid command till LF */
845 845
846 for (p = s->buffer->pos; p < s->buffer->last; p++) { 846 for (p = s->buffer->pos; p < s->buffer->last; p++) {
847 if (*p == LF) { 847 if (*p == LF) {
848 s->state = sw_start; 848 s->state = sw_start;
849 p++; 849 s->buffer->pos = p + 1;
850 break; 850 return NGX_MAIL_PARSE_INVALID_COMMAND;
851 } 851 }
852 } 852 }
853 853
854 s->buffer->pos = p; 854 s->buffer->pos = p;
855 855
856 return NGX_MAIL_PARSE_INVALID_COMMAND; 856 return NGX_AGAIN;
857 } 857 }
858 858
859 859
860 ngx_int_t 860 ngx_int_t
861 ngx_mail_auth_parse(ngx_mail_session_t *s, ngx_connection_t *c) 861 ngx_mail_auth_parse(ngx_mail_session_t *s, ngx_connection_t *c)