mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-12-24 19:37:48 +03:00
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
- e1a8b359c1
Addresses:
- https://gitlab.com/libssh/libssh-mirror/-/merge_requests/320#note_1173911211
Signed-off-by: Jon Simons <jon@jonsimons.org>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user