[6.0] 2d37cff7d Tolerate a null address string in std.ip()

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Wed May 22 17:34:08 UTC 2019


commit 2d37cff7df80c887e42263ecc44bb391655be05a
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Wed May 22 18:07:45 2019 +0200

    Tolerate a null address string in std.ip()
    
    A regression from d7a81fe82ca09c9f3b3a9fd67265de00da7a4315 and the
    followup changes from #2993. The new VSS_Resolve{One,First} functions
    expect a non-null address string.
    
    Conflicts:
            lib/libvmod_std/vmod_std_conversions.c

diff --git a/bin/varnishtest/tests/m00011.vtc b/bin/varnishtest/tests/m00011.vtc
index 6c761fff4..243e5daf6 100644
--- a/bin/varnishtest/tests/m00011.vtc
+++ b/bin/varnishtest/tests/m00011.vtc
@@ -77,6 +77,11 @@ varnish v1 -vcl+backend {
 		set resp.http.port11 = std.port(debug.get_ip());
 		std.timestamp("1.2.3.4 80, p = 443");
 
+		debug.store_ip(std.ip(req.http.non-existent, server.ip));
+		set resp.http.ip12 = debug.get_ip();
+		set resp.http.port12 = std.port(debug.get_ip());
+		std.timestamp("NULL, server.ip");
+
 	}
 } -start
 
@@ -110,4 +115,6 @@ client c1 {
 	expect resp.http.port10 == ${s1_port}
 	expect resp.http.ip11 == 1.2.3.4
 	expect resp.http.port11 == 80
+	expect resp.http.ip12 == ${v1_addr}
+	expect resp.http.port12 == ${v1_port}
 } -run
diff --git a/lib/libvmod_std/vmod_std_conversions.c b/lib/libvmod_std/vmod_std_conversions.c
index c89b79d03..a30086106 100644
--- a/lib/libvmod_std/vmod_std_conversions.c
+++ b/lib/libvmod_std/vmod_std_conversions.c
@@ -81,10 +81,9 @@ VCL_IP
 vmod_ip(VRT_CTX, VCL_STRING s, VCL_IP d, VCL_BOOL n, VCL_STRING default_port)
 {
 	void *p;
-	VCL_IP retval;
+	VCL_IP retval = NULL;
 
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
-	AN(s);
 	AN(d);
 	assert(VSA_Sane(d));
 
@@ -94,8 +93,9 @@ vmod_ip(VRT_CTX, VCL_STRING s, VCL_IP d, VCL_BOOL n, VCL_STRING default_port)
 		return (NULL);
 	}
 
-	retval = VSS_ResolveFirst(p, s, default_port, AF_UNSPEC, SOCK_STREAM,
-	    n ? 0 : AI_NUMERICHOST|AI_NUMERICSERV);
+	if (s != NULL)
+		retval = VSS_ResolveFirst(p, s, default_port, AF_UNSPEC,
+		    SOCK_STREAM, n ? 0 : AI_NUMERICHOST|AI_NUMERICSERV);
 
 	if (retval != NULL)
 		return (retval);


More information about the varnish-commit mailing list