[master] ed39f3d52 Fix leak in create_bogo_n_arg

Nils Goroll nils.goroll at uplex.de
Fri Feb 7 22:43:05 UTC 2025


commit ed39f3d523c55385ffec9d2a83250eb013036e6e
Author: Steven Wojcik <wojcikjsteven at gmail.com>
Date:   Fri Feb 23 14:02:44 2024 -0500

    Fix leak in create_bogo_n_arg
    
    When running with ASAN and UBSAN on ubuntu 22 u00000.vtc and m00003.vtc
    fails from a leak from the return value of create_bogo_n_arg() in
    mgt_main.c. Freeing the returned value allows tests to pass.

diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c
index a31ef0506..d67acac69 100644
--- a/bin/varnishd/mgt/mgt_main.c
+++ b/bin/varnishd/mgt/mgt_main.c
@@ -567,7 +567,7 @@ mgt_process_f_arg(struct cli *cli, unsigned C_flag, void **fap)
 	return (retval);
 }
 
-static const char *
+static char *
 create_bogo_n_arg(void)
 {
 	struct vsb *vsb;
@@ -842,8 +842,11 @@ main(int argc, char * const *argv)
 
 	assert(d_flag == 0 || F_flag == 0);
 
-	if (C_flag && n_arg == NULL)
-		n_arg = create_bogo_n_arg();
+	p = NULL;
+	if (C_flag && n_arg == NULL) {
+		p = create_bogo_n_arg();
+		n_arg = p;
+	}
 
 	if (S_arg != NULL && !strcmp(S_arg, "none")) {
 		fprintf(stderr,
@@ -860,6 +863,8 @@ main(int argc, char * const *argv)
 
 	workdir = VIN_n_Arg(n_arg);
 	AN(workdir);
+	if (p != NULL)
+		free(p);
 
 	if (i_arg == NULL || *i_arg == '\0')
 		i_arg = mgt_HostName();


More information about the varnish-commit mailing list