[master] b2d19c5 Use memchr rather than strchr/index

Tollef Fog Heen tfheen at varnish-cache.org
Mon Oct 15 13:02:55 CEST 2012


commit b2d19c5f6d3c3d661720a4c4ed2ff0b4695e6f04
Author: Tollef Fog Heen <tfheen at err.no>
Date:   Mon Oct 15 12:56:15 2012 +0200

    Use memchr rather than strchr/index
    
    the strings we get from the libvarnishapi functions are not
    necessarily null-terminated, so avoid using str* functions on them.
    
    Thanks to lampe for the patch.
    
    Fixes #1115

diff --git a/bin/varnishncsa/varnishncsa.c b/bin/varnishncsa/varnishncsa.c
index 9c9267e..88c73eb 100644
--- a/bin/varnishncsa/varnishncsa.c
+++ b/bin/varnishncsa/varnishncsa.c
@@ -312,7 +312,7 @@ collect_backend(struct logline *lp, enum VSL_tag_e tag, unsigned spec,
 			clean_logline(lp);
 			break;
 		}
-		qs = index(ptr, '?');
+		qs = memchr(ptr, '?', len);
 		if (qs) {
 			lp->df_U = trimline(ptr, qs);
 			lp->df_q = trimline(qs, end);
@@ -356,7 +356,7 @@ collect_backend(struct logline *lp, enum VSL_tag_e tag, unsigned spec,
 	case SLT_BereqHeader:
 		if (!lp->active)
 			break;
-		split = strchr(ptr, ':');
+		split = memchr(ptr, ':', len);
 		if (split == NULL)
 			break;
 		if (isprefix(ptr, "authorization:", end, &next) &&
@@ -431,7 +431,7 @@ collect_client(struct logline *lp, enum VSL_tag_e tag, unsigned spec,
 			clean_logline(lp);
 			break;
 		}
-		qs = index(ptr, '?');
+		qs = memchr(ptr, '?', len);
 		if (qs) {
 			lp->df_U = trimline(ptr, qs);
 			lp->df_q = trimline(qs, end);
@@ -464,7 +464,7 @@ collect_client(struct logline *lp, enum VSL_tag_e tag, unsigned spec,
 	case SLT_ReqHeader:
 		if (!lp->active)
 			break;
-		split = strchr(ptr, ':');
+		split = memchr(ptr, ':', len);
 		if (split == NULL)
 			break;
 		if (tag == SLT_ReqHeader &&
@@ -490,7 +490,7 @@ collect_client(struct logline *lp, enum VSL_tag_e tag, unsigned spec,
 		if(!lp->active)
 			break;
 
-		split = strchr(ptr, ':');
+		split = memchr(ptr, ':', len);
 		if (split == NULL)
 			break;
 



More information about the varnish-commit mailing list