comparison src/mail/ngx_mail_parse.c @ 571:5938746e70c2 PATCH_NGINX_MAIL_0_8

Mail: get rid of ugly protocol check in ngx_mail_auth_parse(). Instead, use index of argument which holds authentication mechanism name. For IMAP and POP3 it's 0, for SMTP - 1 as SMTP preserves command in first argument to allow pipelining support. While here, add check that we actually have argument holding authentication mechanism name. Currently IMAP has no appropriate checks before calling ngx_mail_auth_parse() which results in possible access of uninitialized memory.
author Maxim Dounin <mdounin@mdounin.ru>
date Sun, 27 Sep 2009 00:52:15 +0400
parents c78a94ba4ae1
children
comparison
equal deleted inserted replaced
570:9773720b845e 571:5938746e70c2
857 return NGX_MAIL_PARSE_INVALID_COMMAND; 857 return NGX_MAIL_PARSE_INVALID_COMMAND;
858 } 858 }
859 859
860 860
861 ngx_int_t 861 ngx_int_t
862 ngx_mail_auth_parse(ngx_mail_session_t *s, ngx_connection_t *c) 862 ngx_mail_auth_parse(ngx_mail_session_t *s, ngx_connection_t *c, ngx_uint_t n)
863 { 863 {
864 ngx_str_t *arg; 864 ngx_str_t *arg;
865 ngx_uint_t nelts; 865 ngx_uint_t nelts;
866 866
867 #if (NGX_MAIL_SSL) 867 #if (NGX_MAIL_SSL)
871 #endif 871 #endif
872 872
873 arg = s->args.elts; 873 arg = s->args.elts;
874 nelts = s->args.nelts; 874 nelts = s->args.nelts;
875 875
876 if (s->protocol == NGX_MAIL_SMTP_PROTOCOL) { 876 if (nelts <= n) {
877 arg++; 877 return NGX_MAIL_PARSE_INVALID_COMMAND;
878 nelts--; 878 }
879 } 879
880 arg += n;
881 nelts -= n;
880 882
881 if (arg[0].len == 5) { 883 if (arg[0].len == 5) {
882 884
883 if (ngx_strncasecmp(arg[0].data, (u_char *) "LOGIN", 5) == 0) { 885 if (ngx_strncasecmp(arg[0].data, (u_char *) "LOGIN", 5) == 0) {
884 886
898 if (nelts == 1) { 900 if (nelts == 1) {
899 return NGX_MAIL_AUTH_PLAIN; 901 return NGX_MAIL_AUTH_PLAIN;
900 } 902 }
901 903
902 if (nelts == 2) { 904 if (nelts == 2) {
903 return ngx_mail_auth_plain(s, c, 905 return ngx_mail_auth_plain(s, c, n + 1);
904 (s->protocol == NGX_MAIL_SMTP_PROTOCOL) ? 2 : 1);
905 } 906 }
906 } 907 }
907 908
908 return NGX_MAIL_PARSE_INVALID_COMMAND; 909 return NGX_MAIL_PARSE_INVALID_COMMAND;
909 } 910 }