Skip to content

Commit 97b2873

Browse files
committed
Fixed uninitialzed memory access bug in base64 encoding.
Signed-off-by: Charles Shereda <cpshereda@lanl.gov>
1 parent ab3fc05 commit 97b2873

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

opal/mca/pmix/base/pmix_base_fns.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* Copyright (c) 2016 Mellanox Technologies, Inc.
99
* All rights reserved.
1010
* Copyright (c) 2016 Cisco Systems, Inc. All rights reserved.
11+
* Copyright (c) 2020 Triad National Security, LLC. All rights
12+
* reserved.
1113
* $COPYRIGHT$
1214
*
1315
* Additional copyrights may follow
@@ -663,9 +665,11 @@ static inline unsigned char pmi_base64_decsym (unsigned char value) {
663665

664666
static inline void pmi_base64_encode_block (const unsigned char in[3], char out[4], int len) {
665667
out[0] = pmi_base64_encsym (in[0] >> 2);
666-
out[1] = pmi_base64_encsym (((in[0] & 0x03) << 4) | ((in[1] & 0xf0) >> 4));
668+
/* len == length of in[] - conditionals insure we don't reference uninitialized in[] values */
669+
out[1] = 1 < len ? pmi_base64_encsym(((in[0] & 0x03) << 4) | ((in[1] & 0xf0) >> 4)) : pmi_base64_encsym((in[0] & 0x03) << 4);
667670
/* Cray PMI doesn't allow = in PMI attributes so pad with spaces */
668-
out[2] = 1 < len ? pmi_base64_encsym(((in[1] & 0x0f) << 2) | ((in[2] & 0xc0) >> 6)) : ' ';
671+
out[2] = 1 < len ? pmi_base64_encsym((in[1] & 0x0f) << 2) : ' ';
672+
out[2] = 2 < len ? pmi_base64_encsym(((in[1] & 0x0f) << 2) | ((in[2] & 0xc0) >> 6)) : out[2];
669673
out[3] = 2 < len ? pmi_base64_encsym(in[2] & 0x3f) : ' ';
670674
}
671675

0 commit comments

Comments
 (0)