[PATCH] Implemention ngx_strstrn() is no longer exposed

crespin nginx-forum at nginx.us
Fri Aug 8 09:50:04 UTC 2014


Hello,

Implementing ngx_strstrn () is exposed. This can be misleading.

regards,

yves


# HG changeset patch
# User Yves Crespin<yves.crespin at e-quartz.fr>
# Date 1407491120 -7200
# Node ID 505ec91d60fefa776bc2c7fcbd6d980cc85b6b5e
# Parent  74265a0edba677c967f532de789a4589436aa5fb
Implemention ngx_strstrn() is no longer exposed.

The third parameter must be the length of the second string.
As usual, the size is provived via sizeof().

diff -r 74265a0edba6 -r 505ec91d60fe src/core/ngx_string.c
--- a/src/core/ngx_string.c Fri Aug 08 08:55:33 2014 +0200
+++ b/src/core/ngx_string.c Fri Aug 08 11:45:20 2014 +0200
@@ -655,7 +655,7 @@
 /*
  * ngx_strstrn() and ngx_strcasestrn() are intended to search for static
  * substring with known length in null-terminated string. The argument n
- * must be length of the second substring - 1.
+ * must be length of the second substring.
  */

 u_char *
@@ -675,7 +675,7 @@

         } while (c1 != c2);

-    } while (ngx_strncmp(s1, (u_char *) s2, n) != 0);
+    } while (ngx_strncmp(s1, (u_char *) s2, n - 1) != 0);

     return --s1;
 }
diff -r 74265a0edba6 -r 505ec91d60fe src/http/ngx_http_request.c
--- a/src/http/ngx_http_request.c   Fri Aug 08 08:55:33 2014 +0200
+++ b/src/http/ngx_http_request.c   Fri Aug 08 11:45:20 2014 +0200
@@ -1667,7 +1667,7 @@

     user_agent = h->value.data;

-    msie = ngx_strstrn(user_agent, "MSIE ", 5 - 1);
+    msie = ngx_strstrn(user_agent, "MSIE ", sizeof("MSIE") - 1);

     if (msie && msie + 7 < user_agent + h->value.len) {

@@ -1681,7 +1681,7 @@
                 r->headers_in.msie6 = 1;
                 break;
             case '6':
-                if (ngx_strstrn(msie + 8, "SV1", 3 - 1) == NULL) {
+                if (ngx_strstrn(msie + 8, "SV1", sizeof("SV1") - 1) ==
NULL) {
                     r->headers_in.msie6 = 1;
                 }
                 break;
@@ -1696,7 +1696,7 @@
 #endif
     }

-    if (ngx_strstrn(user_agent, "Opera", 5 - 1)) {
+    if (ngx_strstrn(user_agent, "Opera", sizeof("Opera") - 1)) {
         r->headers_in.opera = 1;
         r->headers_in.msie = 0;
         r->headers_in.msie6 = 0;
@@ -1704,18 +1704,18 @@

     if (!r->headers_in.msie && !r->headers_in.opera) {

-        if (ngx_strstrn(user_agent, "Gecko/", 6 - 1)) {
+        if (ngx_strstrn(user_agent, "Gecko/", sizeof("Gecko/") - 1)) {
             r->headers_in.gecko = 1;

-        } else if (ngx_strstrn(user_agent, "Chrome/", 7 - 1)) {
+        } else if (ngx_strstrn(user_agent, "Chrome/", sizeof("Chrome/") -
1)) {
             r->headers_in.chrome = 1;

-        } else if (ngx_strstrn(user_agent, "Safari/", 7 - 1)
-                   && ngx_strstrn(user_agent, "Mac OS X", 8 - 1))
+        } else if (ngx_strstrn(user_agent, "Safari/", sizeof("Safari/") -
1)
+                   && ngx_strstrn(user_agent, "Mac OS X", sizeof("Mac OS
X") - 1))
         {
             r->headers_in.safari = 1;

-        } else if (ngx_strstrn(user_agent, "Konqueror", 9 - 1)) {
+        } else if (ngx_strstrn(user_agent, "Konqueror", sizeof("Konqueror")
- 1)) {
             r->headers_in.konqueror = 1;
         }
     }

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,252408,252408#msg-252408



More information about the nginx mailing list