From 0fa215e2acdf08482708199eeb258efbc8e6aeae Mon Sep 17 00:00:00 2001 From: Jon Simons Date: Wed, 16 Nov 2022 19:07:22 -0500 Subject: [PATCH] tests/pkd: adjust usage of argv strings Adjust some subtle usage of argv string handling in the pkd test options: rather than conditionally overwrite the two mkdtemp strings with a newly-allocated buffer to be later freed, keep the original const argv pointer around in its own dedicated field. See also these changes in the same area that were due to the previous arrangement, which was a bit too subtle: - 61ce3310b864802a101cb01ff103f0bc2da936e6 - e1a8b359c181508d973da681b1c698db7a6dbd20 Addresses: - https://gitlab.com/libssh/libssh-mirror/-/merge_requests/320#note_1173911211 Signed-off-by: Jon Simons Reviewed-by: Jakub Jelen --- tests/pkd/pkd_daemon.h | 2 ++ tests/pkd/pkd_hello.c | 12 ++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/pkd/pkd_daemon.h b/tests/pkd/pkd_daemon.h index 81273912..7470f67c 100644 --- a/tests/pkd/pkd_daemon.h +++ b/tests/pkd/pkd_daemon.h @@ -44,10 +44,12 @@ struct pkd_daemon_args { unsigned int iterations; struct { + const char *argv_mkdtemp_str; char *mkdtemp_str; } socket_wrapper; struct { + const char *argv_mkdtemp_str; char *mkdtemp_str; } temp_dir; } opts; diff --git a/tests/pkd/pkd_hello.c b/tests/pkd/pkd_hello.c index 63958ee6..fad4a397 100644 --- a/tests/pkd/pkd_hello.c +++ b/tests/pkd/pkd_hello.c @@ -94,7 +94,7 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { pkd_dargs.opts.list = 1; break; case 'L': - pkd_dargs.opts.temp_dir.mkdtemp_str = arg; + pkd_dargs.opts.temp_dir.argv_mkdtemp_str = arg; break; case 'i': pkd_dargs.opts.iterations = atoi(arg); @@ -115,7 +115,7 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { pkd_dargs.opts.libssh_log_level += 1; break; case 'w': - pkd_dargs.opts.socket_wrapper.mkdtemp_str = arg; + pkd_dargs.opts.socket_wrapper.argv_mkdtemp_str = arg; break; default: return ARGP_ERR_UNKNOWN; @@ -961,7 +961,7 @@ static int pkd_init_temp_dir(void) { char *mkdtemp_str = NULL; pkd_dargs.original_dir_fd = -1; - if (pkd_dargs.opts.temp_dir.mkdtemp_str == NULL) { + if (pkd_dargs.opts.temp_dir.argv_mkdtemp_str == NULL) { return 0; } @@ -971,7 +971,7 @@ static int pkd_init_temp_dir(void) { return -1; } - mkdtemp_str = strdup(pkd_dargs.opts.temp_dir.mkdtemp_str); + mkdtemp_str = strdup(pkd_dargs.opts.temp_dir.argv_mkdtemp_str); if (mkdtemp_str == NULL) { fprintf(stderr, "pkd_init_temp_dir strdup failed\n"); goto errstrdup; @@ -1006,11 +1006,11 @@ static int pkd_init_socket_wrapper(void) { int rc = 0; char *mkdtemp_str = NULL; - if (pkd_dargs.opts.socket_wrapper.mkdtemp_str == NULL) { + if (pkd_dargs.opts.socket_wrapper.argv_mkdtemp_str == NULL) { goto out; } - mkdtemp_str = strdup(pkd_dargs.opts.socket_wrapper.mkdtemp_str); + mkdtemp_str = strdup(pkd_dargs.opts.socket_wrapper.argv_mkdtemp_str); if (mkdtemp_str == NULL) { fprintf(stderr, "pkd_init_socket_wrapper strdup failed\n"); goto errstrdup;