[PATCH 7 of 7] Mail: add limits enforcement to IMAP server ID setting as per RFC2971

Filipe da Silva fdasilvayy at gmail.com
Tue Jan 14 11:54:24 UTC 2014


# HG changeset patch
# User Filipe da Silva <fdasilvayy at gmail.com>
# Date 1389700314 -3600
#      Tue Jan 14 12:51:54 2014 +0100
# Node ID bae811e9d65cee82d8deeaaa9cf442bde7d4e458
# Parent  4c742929908a54e06516e80493a42846b9b35420
Mail: add limits enforcement to IMAP server ID setting as per RFC2971.

diff -r 4c742929908a -r bae811e9d65c src/mail/ngx_mail_imap_module.c
--- a/src/mail/ngx_mail_imap_module.c	Tue Jan 14 12:51:19 2014 +0100
+++ b/src/mail/ngx_mail_imap_module.c	Tue Jan 14 12:51:54 2014 +0100
@@ -283,6 +283,13 @@
         return NGX_CONF_ERROR;
     }
 
+    if (conf->server_ids.nelts >= 60) {
+        ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
+           "Trying to declare %ui ( more than 30 ) field-value pairs",
+            conf->server_ids.nelts );
+        return NGX_CONF_ERROR;
+    }
+
     if (conf->server_ids.nelts > 0) {
         size = sizeof("* ID (" CRLF) - 1;
 
@@ -293,6 +300,13 @@
             if (c[i].data[0] != '$')
                 continue;
 
+            if (c[i].len >= 1024) {
+                ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
+                   "Value is too long: %ui characters for value:\"%V\"",
+                    c[i].len, &c[i]);
+                return NGX_CONF_ERROR;
+            }
+
             switch (c[i].len)
             {
             case 12:
@@ -310,6 +324,26 @@
             }
         }
 
+        for (i = 0; i < conf->server_ids.nelts; i += 2) {
+
+            if (c[i].len >= 30) {
+                ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
+                   "Key name is %ui characters long: Too Long\"%V\"",
+                    c[i].len, &c[i]);
+                return NGX_CONF_ERROR;
+            }
+            for (m = i + 2; m < conf->server_ids.nelts; m += 2) {
+                if (c[i].len == c[m].len
+                    && ngx_strncasecmp(c[i].data, c[m].data, c[m].len)
+                    == 0)
+                {
+                    ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
+                       "Duplicate Name found: \"%V\"", &c[i]);
+                    return NGX_CONF_ERROR;
+                }
+            }
+        }
+
         for (i = 0; i < conf->server_ids.nelts; i++) {
             size += 1 + c[i].len + 2;
         }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 006-ImapId_enforcements.diff
Type: text/x-patch
Size: 2238 bytes
Desc: not available
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20140114/c5420c64/attachment.bin>


More information about the nginx-devel mailing list