Skip to contentSkip to conversation

pem: ensure we dont side-effect type_label

PATCH Applied James Prestwood 2 participants 2 messages Oct 4, 2019 – Oct 7, 2019

lore
Share & tools
lore
#0 lore raw

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
index 9da2071..c6481ef 100644
@@ -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
#1 lore raw

Hi James,

Quoted 8 lines · James Prestwood

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(-)

Applied, thanks.

Regards,
-Denis