[master] f16ebb924 Use VUS_resolver() checks also for VCC

Nils Goroll nils.goroll at uplex.de
Mon Nov 21 17:11:06 UTC 2022


commit f16ebb9240143da89e9aa012a0bffc7bb0f64e9c
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Mon Nov 21 17:59:11 2022 +0100

    Use VUS_resolver() checks also for VCC

diff --git a/bin/varnishtest/tests/v00038.vtc b/bin/varnishtest/tests/v00038.vtc
index eca463012..c7c4d61ed 100644
--- a/bin/varnishtest/tests/v00038.vtc
+++ b/bin/varnishtest/tests/v00038.vtc
@@ -117,12 +117,18 @@ varnish v1 -errvcl "Address redefinition at:" {
 	}
 }
 
-varnish v1 -errvcl "Must be an absolute path:" {
+varnish v1 -errvcl "Must be a valid path or abstract socket:" {
 	backend b1 {
 		.path = "server.sock";
 	}
 }
 
+varnish v1 -errvcl "Path too long for a Unix domain socket" {
+	backend b1 {
+		.path = "/this/super/long/path/this/super/long/path/this/super/long/path/this/super/long/path/this/super/long/path/this/super/long/path/this/super/long/path/this/super/long/path/this/super/long/path/this/super/long/path/this/super/long/path/this/super/long/path/this/super/long/path/this/super/long/path/this/super/long/path/this/super/long/path/this/super/long/path/this/super/long/path/this/super/long/path/this/super/long/path/this/super/long/path/this/super/long/path/this/super/long/path";
+	}
+}
+
 varnish v1 -errvcl "Not a socket:" {
 	backend b1 {
 		.path = "${tmpdir}";
diff --git a/lib/libvcc/vcc_backend.c b/lib/libvcc/vcc_backend.c
index 41b6d3739..e4ccde185 100644
--- a/lib/libvcc/vcc_backend.c
+++ b/lib/libvcc/vcc_backend.c
@@ -37,6 +37,7 @@
 #include <sys/stat.h>
 
 #include "vcc_compile.h"
+#include "vus.h"
 
 const char *
 vcc_default_probe(struct vcc *tl)
@@ -87,10 +88,19 @@ Emit_Sockaddr(struct vcc *tl, struct vsb *vsb1, const struct token *t_host,
 }
 
 /*
- * For UDS, we do not create a VSA. Check if it's an absolute path, can
- * be accessed, and is a socket. If so, just emit the path field and set
- * the IP suckaddrs to NULL.
+ * For UDS, we do not create a VSA. We run the VUS_resolver() checks and, if
+ * it's a path, can be accessed, and is a socket. If so, just emit the path
+ * field and set the IP suckaddrs to NULL.
  */
+
+static int
+uds_resolved(void *priv, const struct sockaddr_un *uds)
+{
+	(void) priv;
+	(void) uds;
+	return (42);
+}
+
 static void
 emit_path(struct vsb *vsb1, char *path)
 {
@@ -104,20 +114,28 @@ Emit_UDS_Path(struct vcc *tl, struct vsb *vsb1,
     const struct token *t_path, const char *errid)
 {
 	struct stat st;
+	const char *vus_err;
 
 	AN(t_path);
 	AN(t_path->dec);
 
-	if (*t_path->dec == '@') {
-		emit_path(vsb1, t_path->dec);
+	if (! VUS_is(t_path->dec)) {
+		VSB_printf(tl->sb,
+			   "%s: Must be a valid path or abstract socket:\n",
+			   errid);
+		vcc_ErrWhere(tl, t_path);
 		return;
 	}
-	if (*t_path->dec != '/') {
-		VSB_printf(tl->sb,
-			   "%s: Must be an absolute path:\n", errid);
+	if (VUS_resolver(t_path->dec, uds_resolved, NULL, &vus_err) != 42) {
+		VSB_printf(tl->sb, "%s: %s\n", errid, vus_err);
 		vcc_ErrWhere(tl, t_path);
 		return;
 	}
+	if (*t_path->dec == '@') {
+		emit_path(vsb1, t_path->dec);
+		return;
+	}
+	assert(*t_path->dec == '/');
 	errno = 0;
 	if (stat(t_path->dec, &st) != 0) {
 		int err = errno;


More information about the varnish-commit mailing list