]> git.kaiwu.me - nginx.git/commitdiff
Fixed overflow detection in ngx_inet_addr().
authorValentin Bartenev <vbart@nginx.com>
Tue, 28 Apr 2015 15:55:03 +0000 (18:55 +0300)
committerValentin Bartenev <vbart@nginx.com>
Tue, 28 Apr 2015 15:55:03 +0000 (18:55 +0300)
Overflow detection of the last octet might not work.

Reported by Sergey Polovko.

src/core/ngx_inet.c

index 2c84daf6e2b64ecd920c4775badae3a1728807ed..96a04fdedbaa7f628897b5e159c0f9d70611b247 100644 (file)
@@ -26,15 +26,15 @@ ngx_inet_addr(u_char *text, size_t len)
     n = 0;
 
     for (p = text; p < text + len; p++) {
-
-        if (octet > 255) {
-            return INADDR_NONE;
-        }
-
         c = *p;
 
         if (c >= '0' && c <= '9') {
             octet = octet * 10 + (c - '0');
+
+            if (octet > 255) {
+                return INADDR_NONE;
+            }
+
             continue;
         }