1
1

Fix base64 implementation in pmix framework.

In the commit 80f07b65f16e9538aca7fc5e124d2074e7e0b69e setting of '-' marker used
as the string termination sign was moved from base64 code:
from: 80f07b65f1 (diff-1b10896c267d2591dc2c08fd0542ab67L491)
to: 80f07b65f1 (diff-1b10896c267d2591dc2c08fd0542ab67R189)

However the decoding function wasn't fixed and still expects on extra
byte at the end of the encoded string which leads to data truncation
during extraction (was noticed on standalone code that was using base64
from OMPI).
Этот коммит содержится в:
Artem Polyakov 2016-05-23 12:25:24 +03:00
родитель bca44592af
Коммит 725eea2819

Просмотреть файл

@ -5,6 +5,8 @@
* Copyright (c) 2014-2015 Intel, Inc. All rights reserved.
* Copyright (c) 2014-2015 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2016 Mellanox Technologies, Inc.
* All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
@ -556,7 +558,7 @@ int opal_pmix_base_cache_keys_locally(const opal_process_name_t* id, const char*
}
/* search for each key in the decoded data */
for (offset = 0 ; offset < len && '\0' != tmp_val[offset] ; ) {
for (offset = 0 ; offset < len ; ) {
/* type */
tmp = tmp_val + offset + strlen (tmp_val + offset) + 1;
/* size */
@ -693,7 +695,6 @@ static inline unsigned char pmi_base64_decsym (unsigned char value) {
} else if (value <= 'z') {
return (value - 'a') + 26;
}
return 64;
}
@ -750,7 +751,7 @@ static char *pmi_encode(const void *val, size_t vallen)
static uint8_t *pmi_decode (const char *data, size_t *retlen)
{
size_t input_len = (strlen (data) - 1) / 4;
size_t input_len = strlen (data) / 4;
unsigned char *ret;
int out_len;
size_t i;
@ -758,16 +759,13 @@ static uint8_t *pmi_decode (const char *data, size_t *retlen)
/* default */
*retlen = 0;
ret = calloc (1, 3 * input_len + 1);
ret = calloc (1, 3 * input_len);
if (NULL == ret) {
return ret;
}
for (i = 0, out_len = 0 ; i < input_len ; i++, data += 4) {
out_len += pmi_base64_decode_block(data, ret + 3 * i);
}
ret[out_len] = '\0';
*retlen = out_len;
return ret;
}