Skip to content

Commit ad1d04d

Browse files
authored
Merge pull request #2046 from esnet/pr-2040-follow-up
Explicitly check the return values from Base64Decode()
2 parents 2b9cfa6 + 0b10818 commit ad1d04d

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

src/iperf_auth.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* iperf, Copyright (c) 2014-2023, The Regents of the University of
2+
* iperf, Copyright (c) 2014-2026, The Regents of the University of
33
* California, through Lawrence Berkeley National Laboratory (subject
44
* to receipt of any required approvals from the U.S. Dept. of
55
* Energy). All rights reserved.
@@ -188,7 +188,12 @@ EVP_PKEY *load_pubkey_from_file(const char *file) {
188188
EVP_PKEY *load_pubkey_from_base64(const char *buffer) {
189189
unsigned char *key = NULL;
190190
size_t key_len;
191-
Base64Decode(buffer, &key, &key_len);
191+
int bd;
192+
193+
bd = Base64Decode(buffer, &key, &key_len);
194+
if (bd < 0) {
195+
return NULL;
196+
}
192197

193198
BIO* bio = BIO_new(BIO_s_mem());
194199
BIO_write(bio, key, key_len);
@@ -215,7 +220,12 @@ EVP_PKEY *load_privkey_from_file(const char *file) {
215220
EVP_PKEY *load_privkey_from_base64(const char *buffer) {
216221
unsigned char *key = NULL;
217222
size_t key_len;
218-
Base64Decode(buffer, &key, &key_len);
223+
int bd;
224+
225+
bd = Base64Decode(buffer, &key, &key_len);
226+
if (bd < 0) {
227+
return NULL;
228+
}
219229

220230
BIO* bio = BIO_new(BIO_s_mem());
221231
BIO_write(bio, key, key_len);
@@ -408,7 +418,12 @@ int decode_auth_setting(int enable_debug, const char *authtoken, EVP_PKEY *priva
408418
unsigned char *encrypted_b64 = NULL;
409419
size_t encrypted_len_b64;
410420
int64_t utc_seconds =0;
411-
Base64Decode(authtoken, &encrypted_b64, &encrypted_len_b64);
421+
int bd;
422+
423+
bd = Base64Decode(authtoken, &encrypted_b64, &encrypted_len_b64);
424+
if (bd < 0) {
425+
return -1;
426+
}
412427

413428
unsigned char *plaintext = NULL;
414429
int plaintext_len;

0 commit comments

Comments
 (0)