Skip to content

Commit f88f495

Browse files
committed
Initialize pwdata in pesign and efikeygen
Fixes: github issue rhboot#105 Fixes: 12f1671 (Rework the wildly undocumented NSS password file goo.) Complements: 1a4481e (Add more ways to use a password with the token) Signed-off-by: Egor Ignatov <[email protected]>
1 parent 1fb3c85 commit f88f495

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/cms_common.c

+8-4
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,10 @@ cms_context_fini(cms_context *cms)
172172
xfree(cms->pwdata.data);
173173
break;
174174
case PW_PLAINTEXT:
175-
memset(cms->pwdata.data, 0, strlen(cms->pwdata.data));
176-
xfree(cms->pwdata.data);
175+
if (cms->pwdata.data) {
176+
memset(cms->pwdata.data, 0, strlen(cms->pwdata.data));
177+
xfree(cms->pwdata.data);
178+
}
177179
break;
178180
}
179181
cms->pwdata.source = PW_SOURCE_INVALID;
@@ -319,8 +321,10 @@ void cms_set_pw_data(cms_context *cms, secuPWData *pwdata)
319321
case PW_FROMENV:
320322
case PW_FROMFILE:
321323
case PW_PLAINTEXT:
322-
memset(cms->pwdata.data, 0, strlen(cms->pwdata.data));
323-
xfree(cms->pwdata.data);
324+
if (cms->pwdata.data) {
325+
memset(cms->pwdata.data, 0, strlen(cms->pwdata.data));
326+
xfree(cms->pwdata.data);
327+
}
324328
break;
325329

326330
case PW_DATABASE:

src/efikeygen.c

+5
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,11 @@ int main(int argc, char *argv[])
985985
if (!strcmp(dbdir, "-") && list_empty(&cms->pk12_ins) && !is_self_signed)
986986
errx(1, "'--dbdir -' requires either --pk12-in or --self-sign.");
987987

988+
secuPWData pwdata;
989+
memset(&pwdata, 0, sizeof(pwdata));
990+
pwdata.source = pwdata.orig_source = PW_PROMPT;
991+
cms_set_pw_data(cms, &pwdata);
992+
988993
PK11_SetPasswordFunc(cms->func ? cms->func : readpw);
989994
if (strcmp(dbdir, "-")) {
990995
if (cms->pk12_out.fd >= 0)

src/pesign.c

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ main(int argc, char *argv[])
9595
secuPWData pwdata;
9696

9797
memset(&pwdata, 0, sizeof(pwdata));
98+
pwdata.source = pwdata.orig_source = PW_PROMPT;
9899
pwdata.intdata = -1;
99100

100101
setenv("NSS_DEFAULT_DB_TYPE", "sql", 0);

0 commit comments

Comments
 (0)