[master] 1157dfdc6 Respect TOSTRAND() lifetime

Nils Goroll nils.goroll at uplex.de
Wed Feb 23 10:14:08 UTC 2022


commit 1157dfdc61211b95375a3ed10f076f2d7875439c
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Wed Feb 23 11:07:06 2022 +0100

    Respect TOSTRAND() lifetime
    
    In a different context, I questioned my understanding of C object
    lifetimes and learned that I had given the wrong explanation for why
    TOSTRAND() was used wrongly in
    0c96fc6597c3ba6da057bb43acb7f677e6b776f8:
    
    TOSTRAND() creates a compound literal whose lifetime is the enclosing
    block.
    
    Thus, the error was unrelated to temporary lifetime, but rather that
    the compound literal was assigned in the if-block, but used outside
    it.
    
    Ref: https://stackoverflow.com/questions/71225472/more-questions-on-the-c11-temporary-lifetime-rule-and-undefined-behaviour/71226049#71226049

diff --git a/vmod/vmod_vtc.c b/vmod/vmod_vtc.c
index 143e5e7ce..636bdc275 100644
--- a/vmod/vmod_vtc.c
+++ b/vmod/vmod_vtc.c
@@ -474,10 +474,9 @@ vsl_line(VRT_CTX, char *str)
 		return;
 
 	str = strtok_r(NULL, "\r\n", &save);
+	s = TOSTRAND(str);
 	if (str == NULL)
 		s = vrt_null_strands;
-	else
-		s = TOSTRAND(str);
 
 	vmod_vsl(ctx, id, tag, side, s);
 }


More information about the varnish-commit mailing list