1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
|
Description: this patch makes boinc correctly close the open files.
This patch allows also MFILE to correctly deallocate its pointers by calling close().
Index: boinc/lib/crypt_prog.cpp
===================================================================
--- boinc.orig/lib/crypt_prog.cpp
+++ boinc/lib/crypt_prog.cpp
@@ -117,6 +117,7 @@ unsigned int random_int() {
}
if (1 != fread(&n, sizeof(n), 1, f)) {
print_error("couldn't read from /dev/random\n");
+ fclose(f);
return 2;
}
fclose(f);
@@ -156,6 +157,7 @@ int genkey(int n, const std::string& private_keyfile,
FILE* fpub = fopen(public_keyfile.c_str(), "w");
if (!fpub) {
print_error("fopen");
+ fclose(fpriv);
return 2;
}
print_key_hex(fpriv, (KEY*)&private_key, sizeof(private_key));
@@ -176,6 +178,7 @@ int sign(const std::string& file, const std::string& private_keyfile) {
int retval = scan_key_hex(fpriv, (KEY*)&private_key, sizeof(private_key));
if (retval) {
print_error("scan_key_hex");
+ fclose(fpriv);
return 2;
}
const int data_len = 256;
@@ -186,9 +189,11 @@ int sign(const std::string& file, const std::string& private_keyfile) {
retval = sign_file(file.c_str(), private_key, signature);
if (retval) {
print_error("sign_file");
+ fclose(fpriv);
return 2;
}
print_hex_data(stdout, signature);
+ fclose(fpriv);
return 0;
}
@@ -202,6 +207,7 @@ int sign_string(const std::string& str, const std::string& private_keyfile) {
int retval = scan_key_hex(fpriv, (KEY*)&private_key, sizeof(private_key));
if (retval) {
print_error("scan_key_hex");
+ fclose(fpriv);
return 2;
}
char cbuf[512];
@@ -211,9 +217,11 @@ int sign_string(const std::string& str, const std::string& private_keyfile) {
private_key);
if (retval) {
print_error("generate_signature");
+ fclose(fpriv);
return 2;
}
std::cout << cbuf;
+ fclose(fpriv);
return 0;
}
@@ -228,11 +236,13 @@ int verify(const std::string& file, const std::string& signature_file,
int retval = scan_key_hex(fpub, (KEY*)&public_key, sizeof(public_key));
if (retval) {
print_error("read_public_key");
+ fclose(fpub);
return 2;
}
FILE* f = fopen(signature_file.c_str(), "r");
if (!f) {
print_error("fopen");
+ fclose(fpub);
return 2;
}
const int signature_len = 256;
@@ -243,6 +253,8 @@ int verify(const std::string& file, const std::string& signature_file,
retval = scan_hex_data(f, signature);
if (retval) {
print_error("scan_hex_data");
+ fclose(fpub);
+ fclose(f);
return 2;
}
@@ -251,6 +263,8 @@ int verify(const std::string& file, const std::string& signature_file,
retval = md5_file(file.c_str(), md5_buf, size);
if (retval) {
print_error("md5_file");
+ fclose(fpub);
+ fclose(f);
return 2;
}
bool is_valid = false;
@@ -259,13 +273,19 @@ int verify(const std::string& file, const std::string& signature_file,
);
if (retval) {
print_error("check_file_signature");
+ fclose(fpub);
+ fclose(f);
return 2;
}
if (!is_valid) {
std::cout << "signature is invalid" << std::endl;
+ fclose(fpub);
+ fclose(f);
return 1;
}
+ fclose(fpub);
+ fclose(f);
std::cout << "signature is valid" << std::endl;
return 0;
}
@@ -281,11 +301,13 @@ int verify_string(const std::string& str, const std::string& signature_file,
int retval = scan_key_hex(fpub, (KEY*)&public_key, sizeof(public_key));
if (retval) {
print_error("read_public_key");
+ fclose(fpub);
return 2;
}
FILE* f = fopen(signature_file.c_str(), "r");
if (!f) {
print_error("fopen");
+ fclose(fpub);
return 2;
}
const int signature_len = 512;
@@ -298,13 +320,19 @@ int verify_string(const std::string& str, const std::string& signature_file,
retval = check_string_signature(str.c_str(), cbuf, public_key, is_valid);
if (retval) {
print_error("check_string_signature");
+ fclose(fpub);
+ fclose(f);
return 2;
}
if (!is_valid) {
std::cout << "signature is invalid" << std::endl;
+ fclose(fpub);
+ fclose(f);
return 1;
}
std::cout << "signature is valid" << std::endl;
+ fclose(fpub);
+ fclose(f);
return 0;
}
@@ -319,11 +347,13 @@ int test_crypt(const std::string& private_keyfile,
int retval = scan_key_hex(fpriv, (KEY*)&private_key, sizeof(private_key));
if (retval) {
print_error("scan_key_hex\n");
+ fclose(fpriv);
return 2;
}
FILE* fpub = fopen(public_keyfile.c_str(), "r");
if (!fpub) {
print_error("fopen");
+ fclose(fpriv);
return 2;
}
@@ -331,6 +361,8 @@ int test_crypt(const std::string& private_keyfile,
retval = scan_key_hex(fpub, (KEY*)&public_key, sizeof(public_key));
if (retval) {
print_error("read_public_key");
+ fclose(fpriv);
+ fclose(fpub);
return 2;
}
const std::string test_string("encryption test successful");
@@ -343,6 +375,8 @@ int test_crypt(const std::string& private_keyfile,
retval = encrypt_private(private_key, in, out);
if (retval) {
print_error("encrypt_private");
+ fclose(fpriv);
+ fclose(fpub);
return 2;
}
in = out;
@@ -350,9 +384,13 @@ int test_crypt(const std::string& private_keyfile,
retval = decrypt_public(public_key, in, out);
if (retval) {
print_error("decrypt_public");
+ fclose(fpriv);
+ fclose(fpub);
return 2;
}
std::cout << "out: " << out.data << std::endl;
+ fclose(fpriv);
+ fclose(fpub);
return 0;
}
@@ -498,7 +536,9 @@ int convkey_private_o2b(const std::string& input, const std::string& output) {
print_error("fopen");
return 2;
}
- return print_key_hex(fpriv, (KEY*)&private_key, sizeof(private_key));
+ int ret = print_key_hex(fpriv, (KEY*)&private_key, sizeof(private_key));
+ fclose(fpriv);
+ return ret;
}
int convkey_public_b2o(const std::string& input, const std::string& output) {
@@ -580,7 +620,9 @@ int convkey_public_o2b(const std::string& input, const std::string& output) {
print_error("fopen");
return 2;
}
- return print_key_hex(fpub, (KEY*)&public_key, sizeof(public_key));
+ int ret = print_key_hex(fpub, (KEY*)&public_key, sizeof(public_key));
+ fclose(fpub);
+ return ret;
}
int convkey(const std::string& conversion, const std::string& key_type,
@@ -624,18 +666,21 @@ int cert_verify(const std::string& file, const std::string& signature_file,
int retval = scan_hex_data(f, signature);
if (retval) {
print_error("cannot scan_hex_data");
+ fclose(f);
return 2;
}
char* certpath = check_validity(certificate_dir.c_str(), file.c_str(),
signature.data, const_cast<char*>(ca_dir.c_str()));
if (certpath == NULL) {
print_error("signature cannot be verified.");
+ fclose(f);
return 2;
}
else {
std::cout << "signature verified using certificate" << certpath
<< std::endl;
}
+ fclose(f);
return 0;
}
Index: boinc/lib/mfile.cpp
===================================================================
--- boinc.orig/lib/mfile.cpp
+++ boinc/lib/mfile.cpp
@@ -40,7 +40,7 @@
}
MFILE::~MFILE() {
- if (buf) free(buf);
+ close();
}
int MFILE::open(const char* path, const char* mode) {
Index: boinc/lib/parse_test.cpp
===================================================================
--- boinc.orig/lib/parse_test.cpp
+++ boinc/lib/parse_test.cpp
@@ -57,6 +57,7 @@
exit(1);
}
parse(f);
+ fclose(f);
}
/* try it with something like:
|