Skip to content

Commit a251fc4

Browse files
committed
Slightly improve error handling in encrypt/decrypt routines.
1 parent f511150 commit a251fc4

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/iperf_auth.c

+16-4
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,9 @@ int encrypt_rsa_message(const char *plaintext, EVP_PKEY *public_key, unsigned ch
245245
ctx = EVP_PKEY_CTX_new_from_pkey(NULL, public_key, "");
246246
/* See evp_pkey_rsa(7) and provider-keymgmt(7) */
247247
rc = EVP_PKEY_get_int_param(public_key, OSSL_PKEY_PARAM_MAX_SIZE, &keysize); /* XXX not really keysize */
248+
if (!rc) {
249+
goto errreturn;
250+
}
248251
#else
249252
rsa = EVP_PKEY_get1_RSA(public_key);
250253
keysize = RSA_size(rsa);
@@ -267,11 +270,14 @@ int encrypt_rsa_message(const char *plaintext, EVP_PKEY *public_key, unsigned ch
267270
BIO_free(bioBuff);
268271

269272
if (encryptedtext_len <= 0) {
270-
/* We probably shouldn't be printing stuff like this */
271-
fprintf(stderr, "%s\n", ERR_error_string(ERR_get_error(), NULL));
273+
goto errreturn;
272274
}
273275

274276
return encryptedtext_len;
277+
278+
errreturn:
279+
fprintf(stderr, "%s\n", ERR_error_string(ERR_get_error(), NULL));
280+
return 0;
275281
}
276282

277283
int decrypt_rsa_message(const unsigned char *encryptedtext, const int encryptedtext_len, EVP_PKEY *private_key, unsigned char **plaintext) {
@@ -289,6 +295,9 @@ int decrypt_rsa_message(const unsigned char *encryptedtext, const int encryptedt
289295
ctx = EVP_PKEY_CTX_new_from_pkey(NULL, private_key, "");
290296
/* See evp_pkey_rsa(7) and provider-keymgmt(7) */
291297
rc = EVP_PKEY_get_int_param(private_key, OSSL_PKEY_PARAM_MAX_SIZE, &keysize); /* XXX not really keysize */
298+
if (!rc) {
299+
goto errreturn;
300+
}
292301
#else
293302
rsa = EVP_PKEY_get1_RSA(private_key);
294303
keysize = RSA_size(rsa);
@@ -312,11 +321,14 @@ int decrypt_rsa_message(const unsigned char *encryptedtext, const int encryptedt
312321
BIO_free(bioBuff);
313322

314323
if (plaintext_len <= 0) {
315-
/* We probably shouldn't be printing stuff like this */
316-
fprintf(stderr, "%s\n", ERR_error_string(ERR_get_error(), NULL));
324+
goto errreturn;
317325
}
318326

319327
return plaintext_len;
328+
329+
errreturn:
330+
fprintf(stderr, "%s\n", ERR_error_string(ERR_get_error(), NULL));
331+
return 0;
320332
}
321333

322334
int encode_auth_setting(const char *username, const char *password, EVP_PKEY *public_key, char **authtoken){

0 commit comments

Comments
 (0)