Skip to content

Commit 907e46a

Browse files
committed
server_config_util_ssh: changes due to PR review
1 parent 55d2bc3 commit 907e46a

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

src/server_config_util_ssh.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -498,13 +498,17 @@ _nc_server_config_add_ssh_user_password(const struct ly_ctx *ctx, const char *tr
498498
int ret = 0;
499499
char *hashed_pw = NULL;
500500
const char *salt = "$6$idsizuippipk$";
501-
static struct crypt_data cdata;
501+
struct crypt_data *cdata = NULL;
502502

503503
NC_CHECK_ARG_RET(NULL, ctx, tree_path, password, config, 1);
504504

505-
memset(&cdata, 0, sizeof(struct crypt_data));
505+
cdata = (struct crypt_data *) calloc(sizeof(struct crypt_data), 1);
506+
if (cdata == NULL) {
507+
ret = 1;
508+
goto cleanup;
509+
}
506510

507-
hashed_pw = crypt_r(password, salt, &cdata);
511+
hashed_pw = crypt_r(password, salt, cdata);
508512
if (!hashed_pw) {
509513
ERR(NULL, "Hashing password failed (%s).", strerror(errno));
510514
ret = 1;
@@ -517,6 +521,7 @@ _nc_server_config_add_ssh_user_password(const struct ly_ctx *ctx, const char *tr
517521
}
518522

519523
cleanup:
524+
free(cdata);
520525
return ret;
521526
}
522527

0 commit comments

Comments
 (0)