Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize pwdata in efikeygen and pesign #118

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/cms_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,10 @@ cms_context_fini(cms_context *cms)
xfree(cms->pwdata.data);
break;
case PW_PLAINTEXT:
memset(cms->pwdata.data, 0, strlen(cms->pwdata.data));
xfree(cms->pwdata.data);
if (cms->pwdata.data) {
memset(cms->pwdata.data, 0, strlen(cms->pwdata.data));
xfree(cms->pwdata.data);
}
break;
}
cms->pwdata.source = PW_SOURCE_INVALID;
Expand Down Expand Up @@ -319,8 +321,10 @@ void cms_set_pw_data(cms_context *cms, secuPWData *pwdata)
case PW_FROMENV:
case PW_FROMFILE:
case PW_PLAINTEXT:
memset(cms->pwdata.data, 0, strlen(cms->pwdata.data));
xfree(cms->pwdata.data);
if (cms->pwdata.data) {
memset(cms->pwdata.data, 0, strlen(cms->pwdata.data));
xfree(cms->pwdata.data);
}
break;

case PW_DATABASE:
Expand Down
5 changes: 5 additions & 0 deletions src/efikeygen.c
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,11 @@ int main(int argc, char *argv[])
if (!strcmp(dbdir, "-") && list_empty(&cms->pk12_ins) && !is_self_signed)
errx(1, "'--dbdir -' requires either --pk12-in or --self-sign.");

secuPWData pwdata;
memset(&pwdata, 0, sizeof(pwdata));
pwdata.source = pwdata.orig_source = PW_PROMPT;
cms_set_pw_data(cms, &pwdata);

PK11_SetPasswordFunc(cms->func ? cms->func : readpw);
if (strcmp(dbdir, "-")) {
if (cms->pk12_out.fd >= 0)
Expand Down
2 changes: 2 additions & 0 deletions src/pesign.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,8 @@ main(int argc, char *argv[])
pwdata.data = strdup(secure_getenv("PESIGN_TOKEN_PIN"));
if (!pwdata.data)
err(1, "could not allocate memory");
} else if (pwdata.source == PW_SOURCE_INVALID) {
pwdata.source = PW_PROMPT;
}
pwdata.orig_source = pwdata.source;

Expand Down
Loading