pem: ensure we dont side-effect type_label
PATCH 1/1 pem: ensure we dont side-effect type_label
In pem_load_buffer, l_base64_decode could fail. If it does we were still keeping type_label set. Instead use a temporary variable to hold the label, and only set if l_base64_decode succeeds. Otherwise free the temp label and return NULL.
--- ell/pem.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
ell/pem.c +12 -2
@@ -198,13 +198,23 @@ static uint8_t *pem_load_buffer(const void *buf, size_t buf_len, {size_t base64_len;const char *base64; +char *label; +uint8_t *ret; - base64 =pem_next (buf, buf_len, type_label, &base64_len, + base64 =pem_next (buf, buf_len, &label, &base64_len,NULL , false);if (!base64)return NULL ; -return l_base64_decode (base64, base64_len, len); + ret =l_base64_decode (base64, base64_len, len); +if (ret) { + *type_label = label; +return ret; + } + +l_free (label); + +return NULL ; } LIB_EXPORT uint8_t *l_pem_load_buffer(const void *buf, size_t buf_len,
Signature · 1 line
2.17.1
Denis Kenzior
AppliedHi James,
Quoted 8 lines · James Prestwood
In
pem_load_buffer,l_base64_decodecould fail. If it does we were still keepingtype_labelset. Instead use a temporary variable to hold the label, and only set ifl_base64_decodesucceeds. Otherwise free the temp label and return NULL.--- ell/pem.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
Applied, thanks.
Regards,
-Denis