[master] 488e39e VarnishNCSA base64 implementation now takes a start and end ptr

Martin Blix Grydeland martin at varnish-cache.org
Tue Nov 19 17:37:57 CET 2013


commit 488e39efbb8c83e547f34041da09af1ea44d9b14
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Tue Nov 19 16:26:28 2013 +0100

    VarnishNCSA base64 implementation now takes a start and end ptr

diff --git a/bin/varnishncsa/base64.c b/bin/varnishncsa/base64.c
index 1c0979a..d7b2b89 100644
--- a/bin/varnishncsa/base64.c
+++ b/bin/varnishncsa/base64.c
@@ -6,6 +6,9 @@
 
 #include "config.h"
 
+#include <stdlib.h>
+#include <string.h>
+
 #include "base64.h"
 
 static const char b64[] =
@@ -27,17 +30,17 @@ VB64_init(void)
 }
 
 int
-VB64_decode(char *d, unsigned dlen, const char *s)
+VB64_decode(char *d, unsigned dlen, const char *s, const char *e)
 {
 	unsigned u, v, l;
 	int i;
 
+	if (e == NULL)
+		e = s + strlen(s);
 	u = 0;
 	l = 0;
-	while (*s) {
-		for (v = 0; v < 4; v++) {
-			if (!*s)
-				break;
+	while (s < e) {
+		for (v = 0; s < e && v < 4; v++) {
 			i = i64[(int)*s++];
 			if (i < 0)
 				return (-1);
@@ -80,7 +83,7 @@ main(int argc, char **argv)
 
 	VB64_init();
 	l = sizeof buf;
-	VB64_decode(buf, &l, test1);
+	VB64_decode(buf, l, test1, NULL);
 	printf("%s\n", buf);
 	return (0);
 }
diff --git a/bin/varnishncsa/base64.h b/bin/varnishncsa/base64.h
index 31b166c..526ae19 100644
--- a/bin/varnishncsa/base64.h
+++ b/bin/varnishncsa/base64.h
@@ -29,4 +29,4 @@
  */
 
 void VB64_init(void);
-int VB64_decode(char *d, unsigned dlen, const char *s);
+int VB64_decode(char *d, unsigned dlen, const char *s, const char *e);



More information about the varnish-commit mailing list