comparison keyimport.c @ 1912:8b4274d34fe8

Use buf_burn_free() instead of two calls
author Matt Johnston <matt@ucc.asn.au>
date Tue, 29 Mar 2022 23:47:30 +0800
parents ced53051e200
children 38c6fd7d7a82
comparison
equal deleted inserted replaced
1911:ced53051e200 1912:8b4274d34fe8
502 errmsg = "Encrypted key blob is not a multiple of cipher block size"; 502 errmsg = "Encrypted key blob is not a multiple of cipher block size";
503 goto error; 503 goto error;
504 } 504 }
505 505
506 if (buf) { 506 if (buf) {
507 buf_burn(buf); 507 buf_burn_free(buf);
508 buf_free(buf);
509 } 508 }
510 m_burn(buffer, sizeof(buffer)); 509 m_burn(buffer, sizeof(buffer));
511 return ret; 510 return ret;
512 511
513 error: 512 error:
514 if (buf) { 513 if (buf) {
515 buf_burn(buf); 514 buf_burn_free(buf);
516 buf_free(buf);
517 } 515 }
518 m_burn(buffer, sizeof(buffer)); 516 m_burn(buffer, sizeof(buffer));
519 if (ret) { 517 if (ret) {
520 if (ret->keyblob) { 518 if (ret->keyblob) {
521 m_burn(ret->keyblob, ret->keyblob_size); 519 m_burn(ret->keyblob, ret->keyblob_size);
896 errmsg = NULL; /* no error */ 894 errmsg = NULL; /* no error */
897 retval = retkey; 895 retval = retkey;
898 896
899 error: 897 error:
900 if (blobbuf) { 898 if (blobbuf) {
901 buf_burn(blobbuf); 899 buf_burn_free(blobbuf);
902 buf_free(blobbuf);
903 } 900 }
904 m_burn(key->keyblob, key->keyblob_size); 901 m_burn(key->keyblob, key->keyblob_size);
905 m_free(key->keyblob); 902 m_free(key->keyblob);
906 m_burn(key, sizeof(*key)); 903 m_burn(key, sizeof(*key));
907 m_free(key); 904 m_free(key);
1068 1065
1069 outlen = len = pos = buf->len; 1066 outlen = len = pos = buf->len;
1070 outblob = (unsigned char*)m_malloc(outlen); 1067 outblob = (unsigned char*)m_malloc(outlen);
1071 memcpy(outblob, buf->data, buf->len); 1068 memcpy(outblob, buf->data, buf->len);
1072 1069
1073 buf_burn(buf); 1070 buf_burn_free(buf);
1074 buf_free(buf);
1075 buf = NULL; 1071 buf = NULL;
1076 1072
1077 header = "-----BEGIN OPENSSH PRIVATE KEY-----\n"; 1073 header = "-----BEGIN OPENSSH PRIVATE KEY-----\n";
1078 footer = "-----END OPENSSH PRIVATE KEY-----\n"; 1074 footer = "-----END OPENSSH PRIVATE KEY-----\n";
1079 } 1075 }
1131 if (outblob) { 1127 if (outblob) {
1132 memset(outblob, 0, outlen); 1128 memset(outblob, 0, outlen);
1133 m_free(outblob); 1129 m_free(outblob);
1134 } 1130 }
1135 if (keyblob) { 1131 if (keyblob) {
1136 buf_burn(keyblob); 1132 buf_burn_free(keyblob);
1137 buf_free(keyblob);
1138 } 1133 }
1139 if (extrablob) { 1134 if (extrablob) {
1140 buf_burn(extrablob); 1135 buf_burn_free(extrablob);
1141 buf_free(extrablob);
1142 } 1136 }
1143 return ret; 1137 return ret;
1144 } 1138 }
1145 1139
1146 #if 0 1140 #if 0