Skip to content

Commit db30c63

Browse files
committed
Merge pull request #2 from srajiv/key-bugs2
Please review these 2 commits (v2)
2 parents ed0367f + 8e7ced5 commit db30c63

File tree

6 files changed

+54
-7
lines changed

6 files changed

+54
-7
lines changed

‎.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
*~
2+
*.o
3+
*.lo
4+
Makefile
5+
Makefile.in
6+
*.3
7+
*.8
8+
ABOUT-NLS
9+
aclocal.m4
10+
autom4te.cache
11+
config.guess
12+
config.h.in
13+
config.rpath
14+
config.sub
15+
configure
16+
cscope.out
17+
depcomp
18+
install-sh
19+
ltmain.sh
20+
m4
21+
missing
22+
po
23+

‎lib/tpm_unseal.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ int tpmUnsealFile( char* fname, unsigned char** tss_data, int* tss_size,
185185
BIO_free(b64);
186186
b64 = NULL;
187187
bioRc = BIO_reset(bmem);
188+
if (bioRc != 1) {
189+
tpm_errno = EIO;
190+
rc = TPMSEAL_STD_ERROR;
191+
goto out;
192+
}
188193

189194
/* Check for EVP Key Type Header */
190195
BIO_gets(bdata, data, sizeof(data));
@@ -252,6 +257,11 @@ int tpmUnsealFile( char* fname, unsigned char** tss_data, int* tss_size,
252257
BIO_free(b64);
253258
b64 = NULL;
254259
bioRc = BIO_reset(bmem);
260+
if (bioRc != 1) {
261+
tpm_errno = EIO;
262+
rc = TPMSEAL_STD_ERROR;
263+
goto out;
264+
}
255265

256266
/* Read the base64 encrypted data into the memory BIO */
257267
while ((rcLen = BIO_gets(bdata, data, sizeof(data))) > 0) {
@@ -419,7 +429,8 @@ int tpmUnsealFile( char* fname, unsigned char** tss_data, int* tss_size,
419429
bmem = BIO_pop(b64);
420430
BIO_free(b64);
421431
b64 = NULL;
422-
bioRc = BIO_reset(bmem);
432+
/* a BIO_reset failure shouldn't have an affect at this point */
433+
BIO_reset(bmem);
423434

424435
tss_out:
425436
Tspi_Context_Close(hContext);
@@ -433,7 +444,7 @@ int tpmUnsealFile( char* fname, unsigned char** tss_data, int* tss_size,
433444
if ( b64 )
434445
BIO_free(b64);
435446
if ( bmem ) {
436-
bioRc = BIO_set_close(bmem, BIO_CLOSE);
447+
BIO_set_close(bmem, BIO_CLOSE);
437448
BIO_free(bmem);
438449
}
439450

‎src/cmds/tpm_unsealdata.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ int main(int argc, char **argv)
9292
printf("%c", tss_data[i]);
9393
goto out;
9494
} else if ((fp = fopen(out_filename, "w")) == NULL) {
95-
logError(_("Unable to open output file"));
95+
logError(_("Unable to open output file\n"));
9696
goto out;
9797
}
9898

9999
if (fwrite(tss_data, tss_size, 1, fp) != 1) {
100-
logError(_("Unable to write output file"));
100+
logError(_("Unable to write output file\n"));
101101
goto out;
102102
}
103103
fclose(fp);

‎src/data_mgmt/data_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#define TOKEN_MEMORY_ERROR _("Error, unable to allocate needed memory\n")
4848
#define TOKEN_OPENSSL_ERROR _("Error, OpenSSL error: %s\n")
4949
#define TOKEN_FILE_OPEN_ERROR _("Error, unable to open file %s: %s\n")
50+
#define TOKEN_FILE_WRITE_ERROR _("Error writing to file %s: %s\n")
5051

5152
#define TOKEN_CMD_SUCCESS _("%s succeeded\n")
5253
#define TOKEN_CMD_FAILED _("%s failed\n")

‎src/data_mgmt/data_protect.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,9 +380,15 @@ writeData( CK_BYTE *a_pbData,
380380
}
381381

382382
// Write the previous buffer if there is one
383-
if ( g_pbOutData && ( g_ulOutDataLen > 0 ) )
383+
if ( g_pbOutData && ( g_ulOutDataLen > 0 ) ) {
384384
tWriteCount = fwrite( g_pbOutData, 1, g_ulOutDataLen, g_pOutFile );
385385

386+
if ( tWriteCount != g_ulOutDataLen ) {
387+
logError(TOKEN_FILE_WRITE_ERROR, g_pOutFile, "short write");
388+
return -1;
389+
}
390+
}
391+
386392
if ( a_bMoreData ) {
387393
// Allocate a (new) buffer if necessary
388394
if ( a_ulDataLen > g_ulOutBuffLen ) {
@@ -403,9 +409,15 @@ writeData( CK_BYTE *a_pbData,
403409
}
404410
else {
405411
// No more data so write the last piece of data
406-
if ( a_ulDataLen > 0 )
412+
if ( a_ulDataLen > 0 ) {
407413
tWriteCount = fwrite( a_pbData, 1, a_ulDataLen, g_pOutFile );
408414

415+
if ( tWriteCount != a_ulDataLen ) {
416+
logError(TOKEN_FILE_WRITE_ERROR, g_pOutFile, "short write");
417+
return -1;
418+
}
419+
}
420+
409421
fclose( g_pOutFile );
410422
}
411423

‎src/tpm_mgmt/tpm_present.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ static BOOL confirmLifeLock(TSS_HCONTEXT hContext, TSS_HTPM hTpm)
228228
scanCount = scanf("%5s", rsp);
229229

230230
/* TRANSLATORS: this should be the affirmative letter that was prompted for in the message corresponding to: "Are you sure you want to continue?[y/N]" */
231-
if (strcmp(rsp, _("y")) == 0) {
231+
if (scanCount >= 1 && strcmp(rsp, _("y")) == 0) {
232232
logMsg
233233
(_("Setting the lifetime lock was confirmed.\nContinuing.\n"));
234234
bRc = TRUE;

0 commit comments

Comments
 (0)