[3.0] 5103801 Use memchr rather than strchr/index

Tollef Fog Heen tfheen at varnish-cache.org
Mon Apr 22 13:27:01 CEST 2013


commit 5103801ff1ba7c8f6bb1522d6f6f2ac3bcc22288
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 dc7b4f9..f9fbfa7 100644
--- a/bin/varnishncsa/varnishncsa.c
+++ b/bin/varnishncsa/varnishncsa.c
@@ -316,7 +316,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) {
 			trimline(&lp->df_U, ptr, qs);
 			trimline(&lp->df_q, qs, end);
@@ -360,7 +360,7 @@ collect_backend(struct logline *lp, enum VSL_tag_e tag, unsigned spec,
 	case SLT_TxHeader:
 		if (!lp->active)
 			break;
-		split = strchr(ptr, ':');
+		split = memchr(ptr, ':', len);
 		if (split == NULL)
 			break;
 		if (isprefix(ptr, "authorization:", end, &next) &&
@@ -435,7 +435,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) {
 			trimline(&lp->df_U, ptr, qs);
 			trimline(&lp->df_q, qs, end);
@@ -468,7 +468,7 @@ collect_client(struct logline *lp, enum VSL_tag_e tag, unsigned spec,
 	case SLT_RxHeader:
 		if (!lp->active)
 			break;
-		split = strchr(ptr, ':');
+		split = memchr(ptr, ':', len);
 		if (split == NULL)
 			break;
 		if (tag == SLT_RxHeader &&
@@ -493,7 +493,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